Skip to content

Commit

Permalink
fix aggregate proof recursive circuit, see Consensys/gnark#1306
Browse files Browse the repository at this point in the history
  • Loading branch information
p4u committed Nov 11, 2024
1 parent 8c36c62 commit 6fe9b82
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions example_native_aggregation/circomproofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/consensys/gnark/backend/witness"
"github.com/consensys/gnark/constraint"
"github.com/consensys/gnark/frontend"
stdgroth16 "github.com/consensys/gnark/std/recursion/groth16"
"github.com/consensys/gnark/test"
"github.com/vocdoni/circom2gnark/parser"
)
Expand Down Expand Up @@ -122,7 +123,7 @@ func circom2gnarkRecursiveBls12377(proofData, vkData, publicSignalsData []byte,
// Create the proof
fmt.Println("Generating a recursive proof BLS12-377 of an independent Circom proof...")
startTime := time.Now()
proof, err := groth16.Prove(ccs, pk, witnessFull)
proof, err := groth16.Prove(ccs, pk, witnessFull, stdgroth16.GetNativeProverOptions(ecc.BW6_761.ScalarField(), ecc.BLS12_377.ScalarField()))
if err != nil {
log.Fatalf("Failed to create proof: %v", err)
}
Expand All @@ -131,7 +132,7 @@ func circom2gnarkRecursiveBls12377(proofData, vkData, publicSignalsData []byte,
// Verify the proof
fmt.Println("Verifying...")
startTime = time.Now()
err = groth16.Verify(proof, vk, publicWitness)
err = groth16.Verify(proof, vk, publicWitness, stdgroth16.GetNativeVerifierOptions(ecc.BW6_761.ScalarField(), ecc.BLS12_377.ScalarField()))
if err != nil {
log.Fatalf("Failed to verify proof: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion example_native_aggregation/circuits.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *AggregateProofCircuit) Define(api frontend.API) error {
}
for i := 0; i < numProofs; i++ {
fmt.Printf("Verifying proof %d\n", i)
if err := verifier.AssertProof(c.VerifyingKey, c.Proofs[i].Proof, c.Proofs[i].PublicInputs, stdgroth16.WithCompleteArithmetic()); err != nil {
if err := verifier.AssertProof(c.VerifyingKey, c.Proofs[i].Proof, c.Proofs[i].PublicInputs); err != nil {
return fmt.Errorf("assert proof: %w", err)
}
fmt.Printf("Proof %d verified\n", i)
Expand Down
5 changes: 3 additions & 2 deletions example_native_aggregation/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CompileCircuit(placeholdercircuit any, scalarField *big.Int, t circuitType)
return nil, nil, nil, fmt.Errorf("error creating vk.bin: %w", err)
}
defer vkFile.Close()
_, err = vk.WriteTo(vkFile)
_, err = vk.WriteRawTo(vkFile)
if err != nil {
return nil, nil, nil, fmt.Errorf("error writing verifying key to vk.bin: %w", err)
}
Expand Down Expand Up @@ -143,7 +143,8 @@ func LoadCircuit(curve ecc.ID, t circuitType) (constraint.ConstraintSystem, grot
}
defer pkFile.Close()
pk = groth16.NewProvingKey(curve)
_, err = pk.ReadFrom(pkFile)

_, err = pk.UnsafeReadFrom(pkFile)
if err != nil {
return nil, nil, nil, fmt.Errorf("error reading proving key from pk.bin: %w", err)
}
Expand Down

0 comments on commit 6fe9b82

Please sign in to comment.