-
Notifications
You must be signed in to change notification settings - Fork 143
added the compiler for logderivativesum #496
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
Soleimani193
merged 8 commits into
prover/limitless-top-level
from
prover/logderivativesum-compilation
Jan 7, 2025
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ac34dd
added the compiler for logderivativesum
Soleimani193 fb194e4
replace zero check against the expected sum
Soleimani193 8a6246a
fixed the verifier check against the claimed sum
Soleimani193 1753619
testing the logderivativesum compilation
Soleimani193 0f0fb0c
removed the changes unrelavant to the PR
Soleimani193 d61c3f5
minor; clarifing the panic error
Soleimani193 c62258c
minor; changing the file name
Soleimani193 239bffc
minor typo
Soleimani193 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package logderiv | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/consensys/gnark/frontend" | ||
| "github.com/consensys/linea-monorepo/prover/maths/field" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/compiler/lookup" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/ifaces" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/query" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/wizard" | ||
| ) | ||
|
|
||
| // compile [query.LogDerivativeSum] query | ||
| func CompileLogDerivSum(comp *wizard.CompiledIOP) { | ||
|
|
||
| // Collect all the logDerivativeSum queries | ||
| for _, qName := range comp.QueriesParams.AllUnignoredKeys() { | ||
|
|
||
| // Filter out non other types of queries | ||
| logDeriv, ok := comp.QueriesParams.Data(qName).(query.LogDerivativeSum) | ||
| if !ok { | ||
| continue | ||
| } | ||
|
|
||
| // This ensures that the LogDerivativeSum query is not used again in the | ||
| // compilation process. We know that the query was already ignored at | ||
| // the beginning because we are iterating over the unignored keys. | ||
| comp.QueriesParams.MarkAsIgnored(qName) | ||
| // get the Numerator and Denominator from the input and prepare their compilation. | ||
| zEntries := logDeriv.Inputs | ||
| va := FinalEvaluationCheck{} | ||
| for _, entry := range zEntries { | ||
| zC := &lookup.ZCtx{ | ||
| Round: entry.Round, | ||
| Size: entry.Size, | ||
| SigmaNumerator: entry.Numerator, | ||
| SigmaDenominator: entry.Denominator, | ||
| } | ||
|
|
||
| // z-packing compile; it imposes the correct accumulation over Numerator and Denominator. | ||
| zC.Compile(comp) | ||
| // prover step; Z assignments | ||
| zAssignmentTask := lookup.ZAssignmentTask(*zC) | ||
| comp.SubProvers.AppendToInner(zC.Round, func(run *wizard.ProverRuntime) { | ||
| zAssignmentTask.Run(run) | ||
| }) | ||
| // collect all the zOpening for all the z columns | ||
| va.ZOpenings = append(va.ZOpenings, zC.ZOpenings...) | ||
| } | ||
|
|
||
| // verifer step | ||
| va.LogDerivSumID = qName | ||
| lastRound := comp.NumRounds() - 1 | ||
| comp.RegisterVerifierAction(lastRound, &va) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| type FinalEvaluationCheck struct { | ||
| // ZOpenings lists all the openings of all the zCtx | ||
| ZOpenings []query.LocalOpening | ||
| // query ID | ||
| LogDerivSumID ifaces.QueryID | ||
| } | ||
|
|
||
| // Run implements the [wizard.VerifierAction] | ||
| func (f *FinalEvaluationCheck) Run(run *wizard.VerifierRuntime) error { | ||
|
|
||
| // zSum stores the sum of the ending values of the zs as queried | ||
| // in the protocol via the local opening queries. | ||
| zSum := field.Zero() | ||
| for k := range f.ZOpenings { | ||
| temp := run.GetLocalPointEvalParams(f.ZOpenings[k].ID).Y | ||
| zSum.Add(&zSum, &temp) | ||
| } | ||
|
|
||
| claimedSum := run.GetLogDerivSumParams(f.LogDerivSumID).Sum | ||
| if zSum != claimedSum { | ||
| return fmt.Errorf("log-derivate-sum, the final evaluation check failed for %v,", f.LogDerivSumID) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // RunGnark implements the [wizard.VerifierAction] | ||
| func (f *FinalEvaluationCheck) RunGnark(api frontend.API, run *wizard.WizardVerifierCircuit) { | ||
|
|
||
| claimedSum := run.GetLogDerivSumParams(f.LogDerivSumID).Sum | ||
| // SigmaSKSum stores the sum of the ending values of the SigmaSs as queried | ||
| // in the protocol via the | ||
| zSum := frontend.Variable(field.Zero()) | ||
| for k := range f.ZOpenings { | ||
| temp := run.GetLocalPointEvalParams(f.ZOpenings[k].ID).Y | ||
| zSum = api.Add(zSum, temp) | ||
| } | ||
|
|
||
| api.AssertIsEqual(zSum, claimedSum) | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
prover/protocol/compiler/logderivative_sum.go/logderivsum_test.go
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,75 @@ | ||
| package logderiv_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/consensys/linea-monorepo/prover/maths/common/smartvectors" | ||
| "github.com/consensys/linea-monorepo/prover/maths/field" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/compiler/dummy" | ||
| logderiv "github.com/consensys/linea-monorepo/prover/protocol/compiler/logderivative_sum.go" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/ifaces" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/query" | ||
| "github.com/consensys/linea-monorepo/prover/protocol/wizard" | ||
| "github.com/consensys/linea-monorepo/prover/symbolic" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // It tests that the given expression for the LogDerivativeSum adds up to the given parameter. | ||
| func TestLogDerivSum(t *testing.T) { | ||
|
|
||
| define := func(b *wizard.Builder) { | ||
| var ( | ||
| comp = b.CompiledIOP | ||
| ) | ||
|
|
||
| p0 := b.RegisterCommit("Num_0", 4) | ||
| p1 := b.RegisterCommit("Num_1", 4) | ||
| p2 := b.RegisterCommit("Num_2", 4) | ||
|
|
||
| q0 := b.RegisterCommit("Den_0", 4) | ||
| q1 := b.RegisterCommit("Den_1", 4) | ||
| q2 := b.RegisterCommit("Den_2", 4) | ||
|
|
||
| numerators := []*symbolic.Expression{ | ||
| symbolic.Mul(p0, -1), | ||
| ifaces.ColumnAsVariable(p1), | ||
| symbolic.Mul(p2, p0, 2), | ||
| } | ||
|
|
||
| denominators := []*symbolic.Expression{ | ||
| ifaces.ColumnAsVariable(q0), | ||
| ifaces.ColumnAsVariable(q1), | ||
| ifaces.ColumnAsVariable(q2), | ||
| } | ||
|
|
||
| key := [2]int{0, 4} | ||
| zCat1 := map[[2]int]*query.LogDerivativeSumInput{} | ||
| zCat1[key] = &query.LogDerivativeSumInput{ | ||
| Round: 0, | ||
| Size: 4, | ||
| Numerator: numerators, | ||
| Denominator: denominators, | ||
| } | ||
| comp.InsertLogDerivativeSum(0, "LogDerivSum_Test", zCat1) | ||
|
|
||
| } | ||
|
|
||
| prover := func(run *wizard.ProverRuntime) { | ||
|
|
||
| run.AssignColumn("Num_0", smartvectors.ForTest(1, 1, 1, 1)) | ||
| run.AssignColumn("Num_1", smartvectors.ForTest(2, 3, 7, 9)) | ||
| run.AssignColumn("Num_2", smartvectors.ForTest(5, 6, 1, 1)) | ||
|
|
||
| run.AssignColumn("Den_0", smartvectors.ForTest(1, 1, 1, 1)) | ||
| run.AssignColumn("Den_1", smartvectors.ForTest(2, 3, 7, 9)) | ||
| run.AssignColumn("Den_2", smartvectors.ForTest(5, 6, 1, 1)) | ||
|
|
||
| run.AssignLogDerivSum("LogDerivSum_Test", field.NewElement(8)) | ||
|
|
||
| } | ||
|
|
||
| compiled := wizard.Compile(define, logderiv.CompileLogDerivSum, dummy.Compile) | ||
| proof := wizard.Prove(compiled, prover) | ||
| valid := wizard.Verify(compiled, proof) | ||
| require.NoError(t, valid) | ||
| } |
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
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
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
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.