Skip to content

Commit 7d45dee

Browse files
committed
prototyped recursive verifier with CI running
1 parent 48b6262 commit 7d45dee

File tree

6 files changed

+88
-20
lines changed

6 files changed

+88
-20
lines changed

recursion/mersenne31.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"ExpanderVerifierCircuit/modules/fields"
66

77
"github.com/PolyhedraZK/ExpanderCompilerCollection/ecgo"
8+
ecgoTest "github.com/PolyhedraZK/ExpanderCompilerCollection/ecgo/test"
89
"github.com/spf13/cobra"
910
)
1011

@@ -48,10 +49,32 @@ func Mersenne31RecursionImpl() {
4849
OriginalCircuit: *originalCircuit,
4950
Proof: *proof.PlaceHolder(),
5051
}
51-
_, err = ecgo.Compile(fields.ECCM31.FieldModulus(), &m31RecursionCircuit)
52+
m31Compilation, err := ecgo.Compile(fields.ECCM31.FieldModulus(), &m31RecursionCircuit)
5253
if err != nil {
5354
panic(err.Error())
5455
}
5556

56-
// TODO circuit input witness
57+
// witness definition
58+
originalCircuit, _, err = circuit.ReadCircuit(circuitRel)
59+
if err != nil {
60+
panic(err.Error())
61+
}
62+
63+
assignment := VerifierCircuit{
64+
MpiSize: mpiSize,
65+
FieldEnum: fields.ECCM31,
66+
OriginalCircuit: *originalCircuit,
67+
Proof: *proof,
68+
}
69+
70+
println("Solving witness...")
71+
inputSolver := m31Compilation.GetInputSolver()
72+
witness, err := inputSolver.SolveInput(&assignment, 0)
73+
if err != nil {
74+
panic(err.Error())
75+
}
76+
77+
println("Checking satisfiability...")
78+
layeredCircuit := m31Compilation.GetLayeredCircuit()
79+
println(ecgoTest.CheckCircuit(layeredCircuit, witness))
5780
}

recursion/modules/polycommit/generics.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ type PolynomialCommitment interface {
2323
// Verify checks against commitment the opening point and eval
2424
// TODO(HS) for now this matches with raw commitment,
2525
// later we should add polynomial commitment opening to the interface
26-
Verify(arithmeticEngine fields.ArithmeticEngine, r [][]frontend.Variable, y []frontend.Variable)
26+
Verify(
27+
api fields.ArithmeticEngine,
28+
rs, rSIMD, rMPI [][]frontend.Variable,
29+
y []frontend.Variable,
30+
)
2731
}
2832

2933
// NewCommitment is the general interface for verifier circuit to extract a

recursion/modules/polycommit/raw.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,22 @@ func EvalMultilinear(
4141
}
4242

4343
func (c *RawCommitment) Verify(
44-
api fields.ArithmeticEngine, r [][]frontend.Variable, y []frontend.Variable) {
45-
api.AssertEq(EvalMultilinear(api, c.Vals, r), y)
44+
api fields.ArithmeticEngine,
45+
rs, rSIMD, rMPI [][]frontend.Variable,
46+
y []frontend.Variable,
47+
) {
48+
totalNumVars := len(rs) + len(rSIMD) + len(rMPI)
49+
50+
if 1<<len(rSIMD) != api.SIMDPackSize() {
51+
panic("Inconsistent SIMD length with randomness")
52+
}
53+
54+
challengePoint := make([][]frontend.Variable, totalNumVars)
55+
copy(challengePoint, rSIMD)
56+
copy(challengePoint[len(rSIMD):], rs)
57+
copy(challengePoint[len(rSIMD)+len(rs):], rMPI)
58+
59+
api.AssertEq(EvalMultilinear(api, c.Vals, challengePoint), y)
4660
}
4761

4862
func NewRawPolyCommitment(

recursion/modules/transcript/generics.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,27 @@ func (t *FieldHasherTranscript) ChallengeF() []frontend.Variable {
141141
return sampledChallenge
142142
}
143143

144-
// TODO(HS) hash to state / set state? need after poseidon m31
144+
func (t *FieldHasherTranscript) HashAndReturnState() []frontend.Variable {
145+
if len(t.dataPool) != 0 {
146+
var newCount uint = 0
147+
t.hashState, newCount = t.hasher.HashToState(t.dataPool...)
148+
149+
t.count += newCount
150+
t.dataPool = nil
151+
} else {
152+
var newCount uint = 0
153+
t.hashState, newCount = t.hasher.HashToState(t.hashState...)
154+
155+
t.count += newCount
156+
}
157+
158+
return t.hashState
159+
}
160+
161+
func (t *FieldHasherTranscript) SetState(newHashState []frontend.Variable) {
162+
t.nextUnconsumed = t.hasher.StateCapacity()
163+
t.hashState = newHashState
164+
}
145165

146166
func (t *FieldHasherTranscript) GetCount() uint {
147167
return t.count

recursion/modules/verifier/verifier.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,15 @@ func Verify(
264264
fsTranscript,
265265
)
266266

267-
// TODO(HS) MPI Fiat-Shamir sync randomness rewrite
268-
// Trigger an additional hash
267+
// NOTE: MPI Fiat-Shamir sync randomness
269268
if mpiSize > 1 {
270-
_ = fsTranscript.ChallengeF()
269+
newState := fsTranscript.HashAndReturnState()
270+
fsTranscript.SetState(newState)
271271
}
272272

273-
// TODO(HS) fix inconsistency between MPI and single process settings
274-
log.Println("#Hashes for input: ", fsTranscript.GetCount())
273+
if mpiSize > 1 {
274+
log.Println("#Hashes for input: ", fsTranscript.GetCount())
275+
}
275276
fsTranscript.ResetCount()
276277

277278
originalCircuit.FillRndCoef(fsTranscript)
@@ -292,12 +293,9 @@ func Verify(
292293
log.Println("#Hashes for gkr challenge: ", fsTranscript.GetCount())
293294
fsTranscript.ResetCount()
294295

295-
rx = append(rx, r_simd...)
296-
rx = append(rx, r_mpi...)
296+
polyCom.Verify(api, rx, r_simd, r_mpi, claimed_v0)
297297

298-
ry = append(ry, r_simd...)
299-
ry = append(ry, r_mpi...)
300-
301-
polyCom.Verify(api, rx, claimed_v0)
302-
polyCom.Verify(api, ry, claimed_v1)
298+
if ry != nil {
299+
polyCom.Verify(api, ry, r_simd, r_mpi, claimed_v1)
300+
}
303301
}

scripts/test_recursion.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,17 @@ def test_m31_gkr_to_gkr_recursion(
185185

186186
@in_recursion_dir
187187
def test_m31_gkr_to_gkr_recursion_payload():
188-
# TODO m31 dev TBD
189-
pass
188+
m31_gkr_cmd = ' '.join(f'''
189+
go run . mersenne31
190+
--circuit-file ../{proof_config.circuit}
191+
--witness-files ../{proof_config.witness}
192+
--gkr-proofs ../{proof_path}
193+
--mpi-size {mpi_config.cpus()}
194+
'''.strip().split())
195+
196+
print(m31_gkr_cmd)
197+
if subprocess.run(m31_gkr_cmd, shell=True).returncode != 0:
198+
raise Exception("recursion proof is not proving correctly")
190199

191200
test_m31_gkr_to_gkr_recursion_payload()
192201

0 commit comments

Comments
 (0)