Skip to content

Commit

Permalink
fix: assign baseChallenge correctly while verifying gkr solution (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetyalp authored Jan 24, 2024
1 parent aa1dc4e commit 9627e98
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/fxamacker/cbor/v2 v2.5.0
github.com/google/go-cmp v0.5.9
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b
github.com/icza/bitio v1.1.0
github.com/ingonyama-zk/iciclegnark v0.1.0
github.com/leanovate/gopter v0.2.9
github.com/rs/zerolog v1.30.0
Expand All @@ -22,7 +23,6 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/icza/bitio v1.1.0 // indirect
github.com/ingonyama-zk/icicle v0.0.0-20230928131117-97f0079e5c71 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ 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/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/compress v0.2.0 h1:aBg3YJe8ZFUxm/RF+ppx/URFsZq3aJ6o8isLDQysYDA=
github.com/consensys/compress v0.2.0/go.mod h1:Ne8+cGKjqgjF1dlHapZx38pHzWpaBYhsKxQa+JPl0zM=
github.com/consensys/compress v0.2.1-0.20240103160955-e4fcce3dc96a h1:0Y7y1JXtP8O/nL7LHpBt62pGZ87so63uWrYqUoq920s=
github.com/consensys/compress v0.2.1-0.20240103160955-e4fcce3dc96a/go.mod h1:Ne8+cGKjqgjF1dlHapZx38pHzWpaBYhsKxQa+JPl0zM=
github.com/consensys/gnark-crypto v0.12.2-0.20231221171913-5d5eded6bb15 h1:mcxhrDtXKIepsKXofxSuXRst+41yzAcoNWKIotsjMTQ=
Expand Down
21 changes: 15 additions & 6 deletions std/gkr/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ type mimcNoDepCircuit struct {
X []frontend.Variable
Y []frontend.Variable
mimcDepth int
hashName string
}

func (c *mimcNoDepCircuit) Define(api frontend.API) error {
Expand Down Expand Up @@ -592,10 +593,10 @@ func (c *mimcNoDepCircuit) Define(api frontend.API) error {
return err
}
Z := solution.Export(z)
return solution.Verify("-20", Z...)
return solution.Verify(c.hashName, Z...)
}

func mimcNoDepCircuits(mimcDepth, nbInstances int) (circuit, assignment frontend.Circuit) {
func mimcNoDepCircuits(mimcDepth, nbInstances int, hashName string) (circuit, assignment frontend.Circuit) {
X := make([]frontend.Variable, nbInstances)
Y := make([]frontend.Variable, nbInstances)
for i := range X {
Expand All @@ -610,23 +611,24 @@ func mimcNoDepCircuits(mimcDepth, nbInstances int) (circuit, assignment frontend
X: make([]frontend.Variable, nbInstances),
Y: make([]frontend.Variable, nbInstances),
mimcDepth: mimcDepth,
hashName: hashName,
}
return
}

func BenchmarkMiMCNoDepSolve(b *testing.B) {
//defer profile.Start().Stop()
circuit, assignment := mimcNoDepCircuits(1, 1<<9)
circuit, assignment := mimcNoDepCircuits(1, 1<<9, "-20")
benchProof(b, circuit, assignment)
}

func BenchmarkMiMCFullDepthNoDepSolve(b *testing.B) {
circuit, assignment := mimcNoDepCircuits(91, 1<<19)
circuit, assignment := mimcNoDepCircuits(91, 1<<19, "-20")
benchProof(b, circuit, assignment)
}

func BenchmarkMiMCFullDepthNoDepCompile(b *testing.B) {
circuit, _ := mimcNoDepCircuits(91, 1<<17)
circuit, _ := mimcNoDepCircuits(91, 1<<17, "-20")
benchCompile(b, circuit)
}

Expand All @@ -638,12 +640,19 @@ func BenchmarkMiMCNoGkrFullDepthSolve(b *testing.B) {
func TestMiMCFullDepthNoDepSolve(t *testing.T) {
registerMiMC()
for i := 0; i < 100; i++ {
circuit, assignment := mimcNoDepCircuits(5, 1<<2)
circuit, assignment := mimcNoDepCircuits(5, 1<<2, "-20")
testGroth16(t, circuit, assignment)
testPlonk(t, circuit, assignment)
}
}

func TestMiMCFullDepthNoDepSolveWithMiMCHash(t *testing.T) {
registerMiMC()
circuit, assignment := mimcNoDepCircuits(5, 1<<2, "mimc")
testGroth16(t, circuit, assignment)
testPlonk(t, circuit, assignment)
}

func mimcNoGkrCircuits(mimcDepth, nbInstances int) (circuit, assignment frontend.Circuit) {
X := make([]frontend.Variable, nbInstances)
Y := make([]frontend.Variable, nbInstances)
Expand Down
5 changes: 3 additions & 2 deletions std/gkr/gkr.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,11 @@ func Verify(api frontend.API, c Circuit, assignment WireAssignment, proof Proof,
}
} else if err = sumcheck.Verify(
api, claim, proof[i], fiatshamir.WithTranscript(o.transcript, wirePrefix+strconv.Itoa(i)+".", baseChallenge...),
); err != nil {
); err == nil {
baseChallenge = finalEvalProof
} else {
return err
}
baseChallenge = finalEvalProof
claims.deleteClaim(wire)
}
return nil
Expand Down

0 comments on commit 9627e98

Please sign in to comment.