-
Notifications
You must be signed in to change notification settings - Fork 139
feat(verifier-ray): vanishing query check using codegen #3271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
84b21ee
feat: add code generation of verifier-side System
ivokub 0ac4af8
feat: add exponentiation with comptime exponent
ivokub 0c8454d
feat: add vanishing polynomial check
ivokub d22722f
test: add vanishing fixture generation
ivokub bdc1176
chore: generate vanishing testdata
ivokub 758ad3b
ci: check that vanishing testdata is up-to-date
ivokub 151d591
test: add vanishing tests
ivokub bb962d9
docs: add some documentation notes
ivokub bb8f81b
docs: add later integration notes
ivokub 5967d8f
fix: ensure cancellation points are in allowed ranges
ivokub 242959e
fix: check that no coins in round 0
ivokub a877719
fix: explicit error on too large module
ivokub 2ecc01a
Revert "fix: ensure cancellation points are in allowed ranges"
ivokub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,23 @@ | ||
| module github.com/consensys/linea-monorepo/verifier-ray/codegen | ||
|
|
||
| go 1.25.7 | ||
|
|
||
| require github.com/consensys/linea-monorepo/prover-ray v0.0.0-20260604100845-588fd53a8c0f | ||
|
|
||
| require ( | ||
| github.com/bits-and-blooms/bitset v1.24.4 // indirect | ||
| github.com/blang/semver/v4 v4.0.0 // indirect | ||
| github.com/consensys/gnark v0.14.1-0.20260219004710-bbfb2f70a565 // indirect | ||
| github.com/consensys/gnark-crypto v0.20.2-0.20260514182922-df0578435b08 // indirect | ||
| github.com/fxamacker/cbor/v2 v2.9.1 // indirect | ||
| github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect | ||
| github.com/mattn/go-colorable v0.1.14 // indirect | ||
| github.com/mattn/go-isatty v0.0.21 // indirect | ||
| github.com/ronanh/intcomp v1.1.1 // indirect | ||
| github.com/rs/zerolog v1.35.1 // indirect | ||
| github.com/sirupsen/logrus v1.9.4 // indirect | ||
| github.com/x448/float16 v0.8.4 // indirect | ||
| golang.org/x/crypto v0.50.0 // indirect | ||
| golang.org/x/sync v0.20.0 // indirect | ||
| golang.org/x/sys v0.43.0 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| github.com/bits-and-blooms/bitset v1.24.4 h1:95H15Og1clikBrKr/DuzMXkQzECs1M6hhoGXLwLQOZE= | ||
| github.com/bits-and-blooms/bitset v1.24.4/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= | ||
| github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= | ||
| github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= | ||
| github.com/consensys/gnark v0.14.1-0.20260219004710-bbfb2f70a565 h1:NlOAmbLYsVb/hcuOBxza6CAA+233tB0eFiunGVEMyv4= | ||
| github.com/consensys/gnark v0.14.1-0.20260219004710-bbfb2f70a565/go.mod h1:EoWWbEboQRydCqJDSA7zrFxucIeoy/5R+MDx04oFpF4= | ||
| github.com/consensys/gnark-crypto v0.20.2-0.20260514182922-df0578435b08 h1:EdljQKaHxACX5JMSTXlVM9R8qASU/W1husqDsB2b5tU= | ||
| github.com/consensys/gnark-crypto v0.20.2-0.20260514182922-df0578435b08/go.mod h1:NzeBHSZ49bIM7RtrNTYYR2kymTqwvI/A4eTgQlyQc+Q= | ||
| github.com/consensys/linea-monorepo/prover-ray v0.0.0-20260604100845-588fd53a8c0f h1:1z/yV6WAzsvTXhKrFfSJNvI7kQQYL8N/uPgi651jZzo= | ||
| github.com/consensys/linea-monorepo/prover-ray v0.0.0-20260604100845-588fd53a8c0f/go.mod h1:2cEA44vEDPh8MB1huZtKZv//iXB0ZOghXq7idgt4UPc= | ||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= | ||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/fxamacker/cbor/v2 v2.9.1 h1:2rWm8B193Ll4VdjsJY28jxs70IdDsHRWgQYAI80+rMQ= | ||
| github.com/fxamacker/cbor/v2 v2.9.1/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= | ||
| github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= | ||
| github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= | ||
| github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 h1:EwtI+Al+DeppwYX2oXJCETMO23COyaKGP6fHVpkpWpg= | ||
| github.com/google/pprof v0.0.0-20260402051712-545e8a4df936/go.mod h1:MxpfABSjhmINe3F1It9d+8exIHFvUqtLIRCdOGNXqiI= | ||
| github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzWu4= | ||
| github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c= | ||
| github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= | ||
| github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= | ||
| github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs= | ||
| github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= | ||
| github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= | ||
| github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/ronanh/intcomp v1.1.1 h1:+1bGV/wEBiHI0FvzS7RHgzqOpfbBJzLIxkqMJ9e6yxY= | ||
| github.com/ronanh/intcomp v1.1.1/go.mod h1:7FOLy3P3Zj3er/kVrU/pl+Ql7JFZj7bwliMGketo0IU= | ||
| github.com/rs/zerolog v1.35.1 h1:m7xQeoiLIiV0BCEY4Hs+j2NG4Gp2o2KPKmhnnLiazKI= | ||
| github.com/rs/zerolog v1.35.1/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw= | ||
| github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= | ||
| github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= | ||
| github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= | ||
| github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= | ||
| github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= | ||
| github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= | ||
| golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= | ||
| golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q= | ||
| golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= | ||
| golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= | ||
| golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= | ||
| golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= | ||
| gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,261 @@ | ||
| package codegen | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/consensys/linea-monorepo/prover-ray/maths/koalabear/field" | ||
| "github.com/consensys/linea-monorepo/prover-ray/wiop" | ||
| "github.com/consensys/linea-monorepo/prover-ray/wiop/compilers/global" | ||
| ) | ||
|
|
||
| // UnsupportedExpressionError reports an expression leaf or operation that the | ||
| // first verifier-ray vanishing checker intentionally does not evaluate yet. | ||
| type UnsupportedExpressionError struct { | ||
| Type string | ||
| } | ||
|
|
||
| func (e *UnsupportedExpressionError) Error() string { | ||
| return fmt.Sprintf("unsupported vanishing expression %s", e.Type) | ||
| } | ||
|
|
||
| func IsUnsupportedExpression(err error) bool { | ||
| var unsupported *UnsupportedExpressionError | ||
| return errors.As(err, &unsupported) | ||
| } | ||
|
|
||
| type NamedVanishingSystem struct { | ||
| Name string | ||
| System VanishingSystem | ||
| } | ||
|
|
||
| type VanishingSystem struct { | ||
| SourceName string | ||
| Modules []VanishingModule | ||
| RoundCoinCounts []int | ||
| RoundCoinOffsets []int | ||
| MaxRoundCoins int | ||
| TotalRoundCoins int | ||
| DynamicModuleCount int | ||
| TotalWitnessClaims int | ||
| TotalQuotientClaims int | ||
| } | ||
|
|
||
| type ModuleSize struct { | ||
| Dynamic bool | ||
| StaticSize int | ||
| DynamicIndex int | ||
| } | ||
|
|
||
| type VanishingModule struct { | ||
| SourceName string | ||
| Size ModuleSize | ||
| Expressions []ExprNode | ||
| Buckets []VanishingBucket | ||
| WitnessClaimOffset int | ||
| } | ||
|
|
||
| type VanishingBucket struct { | ||
| Ratio int | ||
| Vanishings []Vanishing | ||
| QuotientClaimOffset int | ||
| } | ||
|
|
||
| type Vanishing struct { | ||
| SourceName string | ||
| Expression int | ||
| CancelledPositions []int | ||
| } | ||
|
|
||
| type ExprNode struct { | ||
| Kind ExprKind | ||
| ColumnClaim int | ||
| ColumnSourceName string | ||
| Cell ScalarRef | ||
| Coin ScalarRef | ||
| Constant field.Element | ||
| Operator Operator | ||
| Operands []int | ||
| } | ||
|
|
||
| type ExprKind int | ||
|
|
||
| const ( | ||
| ExprColumnClaim ExprKind = iota | ||
| ExprCellValue | ||
| ExprCoinValue | ||
| ExprConstant | ||
| ExprOp | ||
| ) | ||
|
|
||
| type ScalarRef struct { | ||
| Round int | ||
| Index int | ||
| FlatIndex int | ||
| SourceName string | ||
| } | ||
|
|
||
| type Operator string | ||
|
|
||
| const ( | ||
| OperatorAdd Operator = "add" | ||
| OperatorMul Operator = "mul" | ||
| OperatorSub Operator = "sub" | ||
| OperatorDiv Operator = "div" | ||
| OperatorDouble Operator = "double" | ||
| OperatorSquare Operator = "square" | ||
| OperatorNegate Operator = "negate" | ||
| OperatorInverse Operator = "inverse" | ||
| ) | ||
|
|
||
| type viewKey struct { | ||
| id wiop.ObjectID | ||
| shift int | ||
| } | ||
|
|
||
| // BuildVanishingSystem extracts only compiled global.Verifier actions from sys | ||
| // and converts them to the compact data representation consumed by Zig. | ||
| func BuildVanishingSystem(sys *wiop.System) (VanishingSystem, error) { | ||
| out := VanishingSystem{SourceName: sys.Context.Path()} | ||
| out.RoundCoinCounts = make([]int, len(sys.Rounds)) | ||
| out.RoundCoinOffsets = make([]int, len(sys.Rounds)) | ||
| for i, round := range sys.Rounds { | ||
| out.RoundCoinOffsets[i] = out.TotalRoundCoins | ||
| out.RoundCoinCounts[i] = len(round.Coins) | ||
| out.TotalRoundCoins += len(round.Coins) | ||
| if len(round.Coins) > out.MaxRoundCoins { | ||
| out.MaxRoundCoins = len(round.Coins) | ||
| } | ||
| } | ||
| dynamicIndices := map[*wiop.Module]int{} | ||
|
|
||
| for _, round := range sys.Rounds { | ||
| for _, action := range round.VerifierActions { | ||
| verifier, ok := action.(*global.Verifier) | ||
| if !ok { | ||
| continue | ||
| } | ||
| moduleRef := verifier.Module | ||
| module := VanishingModule{SourceName: moduleRef.Context.Label, WitnessClaimOffset: out.TotalWitnessClaims} | ||
| if moduleRef.IsDynamic() { | ||
| idx, ok := dynamicIndices[moduleRef] | ||
| if !ok { | ||
| idx = len(dynamicIndices) | ||
| dynamicIndices[moduleRef] = idx | ||
| } | ||
| module.Size = ModuleSize{Dynamic: true, DynamicIndex: idx} | ||
| } else { | ||
| module.Size = ModuleSize{StaticSize: moduleRef.Size()} | ||
| } | ||
|
|
||
| views := make(map[viewKey]int, len(verifier.WitnessViews)) | ||
| for i, view := range verifier.WitnessViews { | ||
| views[viewKey{id: view.Column.Context.ID, shift: view.ShiftingOffset}] = i | ||
| } | ||
|
|
||
| out.TotalWitnessClaims += len(verifier.WitnessClaims) | ||
| for _, bucket := range verifier.Buckets { | ||
| b := VanishingBucket{ | ||
| Ratio: bucket.Ratio, | ||
| QuotientClaimOffset: out.TotalQuotientClaims, | ||
| } | ||
| out.TotalQuotientClaims += len(bucket.QuotientClaims) | ||
|
|
||
| for _, v := range bucket.Vanishings { | ||
| exprIdx, err := appendExpr(&module, views, out.RoundCoinOffsets, v.Expression) | ||
| if err != nil { | ||
| return VanishingSystem{}, err | ||
| } | ||
| b.Vanishings = append(b.Vanishings, Vanishing{ | ||
| SourceName: v.Context().Label, | ||
| Expression: exprIdx, | ||
| CancelledPositions: append([]int(nil), v.CancelledPositions...), | ||
| }) | ||
| } | ||
| module.Buckets = append(module.Buckets, b) | ||
| } | ||
|
|
||
| out.Modules = append(out.Modules, module) | ||
| } | ||
| } | ||
|
|
||
| out.DynamicModuleCount = len(dynamicIndices) | ||
| return out, nil | ||
| } | ||
|
|
||
| func appendExpr(module *VanishingModule, views map[viewKey]int, roundCoinOffsets []int, expr wiop.Expression) (int, error) { | ||
| switch e := expr.(type) { | ||
| case *wiop.ColumnView: | ||
| idx, ok := views[viewKey{id: e.Column.Context.ID, shift: e.ShiftingOffset}] | ||
| if !ok { | ||
| return 0, fmt.Errorf("column view %s shift %d was not exported as a witness claim", e.Column.Context.Path(), e.ShiftingOffset) | ||
| } | ||
| module.Expressions = append(module.Expressions, ExprNode{Kind: ExprColumnClaim, ColumnClaim: idx, ColumnSourceName: e.Column.Context.Label}) | ||
| return len(module.Expressions) - 1, nil | ||
| case *wiop.Constant: | ||
| module.Expressions = append(module.Expressions, ExprNode{Kind: ExprConstant, Constant: e.Value}) | ||
| return len(module.Expressions) - 1, nil | ||
| case *wiop.ArithmeticOperation: | ||
| operands := make([]int, len(e.Operands)) | ||
| for i, operand := range e.Operands { | ||
| idx, err := appendExpr(module, views, roundCoinOffsets, operand) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| operands[i] = idx | ||
| } | ||
| op, err := mapOperator(e.Operator) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| module.Expressions = append(module.Expressions, ExprNode{Kind: ExprOp, Operator: op, Operands: operands}) | ||
| return len(module.Expressions) - 1, nil | ||
| case *wiop.Cell: | ||
| module.Expressions = append(module.Expressions, ExprNode{ | ||
| Kind: ExprCellValue, | ||
| Cell: ScalarRef{ | ||
| Round: e.Context.ID.Slot(), | ||
| Index: e.Context.ID.Position(), | ||
| SourceName: e.Context.Label, | ||
| }, | ||
| }) | ||
| return len(module.Expressions) - 1, nil | ||
| case *wiop.CoinField: | ||
| round := e.Context.ID.Slot() | ||
| module.Expressions = append(module.Expressions, ExprNode{ | ||
| Kind: ExprCoinValue, | ||
| Coin: ScalarRef{ | ||
| Round: round, | ||
| Index: e.Context.ID.Position(), | ||
| FlatIndex: roundCoinOffsets[round] + e.Context.ID.Position(), | ||
| SourceName: e.Context.Label, | ||
| }, | ||
| }) | ||
| return len(module.Expressions) - 1, nil | ||
| default: | ||
| return 0, &UnsupportedExpressionError{Type: fmt.Sprintf("%T", expr)} | ||
| } | ||
| } | ||
|
|
||
| func mapOperator(op wiop.ArithmeticOperator) (Operator, error) { | ||
| switch op { | ||
| case wiop.ArithmeticOperatorAdd: | ||
| return OperatorAdd, nil | ||
| case wiop.ArithmeticOperatorMul: | ||
| return OperatorMul, nil | ||
| case wiop.ArithmeticOperatorSub: | ||
| return OperatorSub, nil | ||
| case wiop.ArithmeticOperatorDiv: | ||
| return OperatorDiv, nil | ||
| case wiop.ArithmeticOperatorDouble: | ||
| return OperatorDouble, nil | ||
| case wiop.ArithmeticOperatorSquare: | ||
| return OperatorSquare, nil | ||
| case wiop.ArithmeticOperatorNegate: | ||
| return OperatorNegate, nil | ||
| case wiop.ArithmeticOperatorInverse: | ||
| return OperatorInverse, nil | ||
| default: | ||
| return "", &UnsupportedExpressionError{Type: fmt.Sprintf("ArithmeticOperator(%d)", int(op))} | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.