@@ -8,18 +8,13 @@ import (
88
99 "github.com/consensys/gnark-crypto/ecc"
1010 "github.com/consensys/gnark/backend/groth16"
11-
12- // "github.com/consensys/gnark/frontend/cs/scs"
13- "github.com/consensys/gnark/frontend/cs/r1cs"
14-
1511 "github.com/consensys/gnark/frontend"
12+ "github.com/consensys/gnark/frontend/cs/r1cs"
1613)
1714
18- // CubicCircuit defines a simple circuit
15+ // InequalityCircuit defines a simple circuit
1916// x != 0
2017type InequalityCircuit struct {
21- // struct tags on a variable is optional
22- // default uses variable name and secret visibility.
2318 X frontend.Variable `gnark:"x"`
2419}
2520
@@ -34,23 +29,12 @@ func GenerateIneqProof(x int) {
3429 outputDir := "task_sender/test_examples/gnark_groth16_bn254_infinite_script/infinite_proofs/"
3530
3631 var circuit InequalityCircuit
37- // use r1cs.NewBuilder instead of scs.NewBuilder
3832 ccs , err := frontend .Compile (ecc .BN254 .ScalarField (), r1cs .NewBuilder , & circuit )
3933 if err != nil {
4034 panic ("circuit compilation error" )
4135 }
4236
43- // rics is not used in the setup
44- // r1cs := ccs.(*cs.SparseR1CS)
45- // as srs is not used in the setup, we can remove it
46- // srs, err := test.NewKZGSRS(r1cs)
47- if err != nil {
48- panic ("KZG setup error" )
49- }
50-
51- // no need to use srs in the setup
5237 pk , vk , _ := groth16 .Setup (ccs )
53- // pk, vk, err := groth16.Setup(ccs, srs)
5438
5539 assignment := InequalityCircuit {X : x }
5640
@@ -59,25 +43,21 @@ func GenerateIneqProof(x int) {
5943 log .Fatal (err )
6044 }
6145
62- // TODO , this should be empty, right? private input is x and no pub input
6346 publicWitness , err := frontend .NewWitness (& assignment , ecc .BN254 .ScalarField (), frontend .PublicOnly ())
6447 if err != nil {
6548 log .Fatal (err )
6649 }
6750
68- // This proof should be serialized for testing in the operator
6951 proof , err := groth16 .Prove (ccs , pk , fullWitness )
7052 if err != nil {
7153 panic ("GROTH16 proof generation error" )
7254 }
7355
74- // The proof is verified before writing it into a file to make sure it is valid.
7556 err = groth16 .Verify (proof , vk , publicWitness )
7657 if err != nil {
7758 panic ("GROTH16 proof not verified" )
7859 }
7960
80- // Open files for writing the proof, the verification key and the public witness
8161 proofFile , err := os .Create (outputDir + "ineq_" + strconv .Itoa (x ) + "_groth16.proof" )
8262 if err != nil {
8363 panic (err )
@@ -107,7 +87,7 @@ func GenerateIneqProof(x int) {
10787 panic ("could not serialize proof into file" )
10888 }
10989
110- fmt .Println ("Proof written into ineq_{x}_groth16 .proof" )
111- fmt .Println ("Verification key written into groth16_verification_key" )
112- fmt .Println ("Public witness written into witness .pub" )
90+ fmt .Printf ("Proof written into ineq_%d_groth16 .proof\n " , x )
91+ fmt .Printf ("Verification key written into ineq_%d_groth16.vk \n " , x )
92+ fmt .Printf ("Public witness written into ineq_%d_groth16 .pub\n " , x )
11393}
0 commit comments