gnark/examples arithmetization and proof #995
-
How's proving done in the cubic example since the circuit isn't compiled. Per the docs, gnark follows a typical workflow and it is recommended to execute a circuit without running a zk-SNARK prover. Is that the case in the gnark/examples? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, the online playground at https://play.gnark.io/ doesn't run the full prover to output a proof, but only runs until solving stage and then stops. There are some performance problems with compiling the full Groth16/PLONK prover. For testing locally, I would recommend setting up a Go environment, doing: go mod init example
go get github.com/consensys/gnark@master And then start implementing the circuits in circuit := ExampleFieldCircuit[emulated.BN254Fp]{}
witness := ExampleFieldCircuit[emulated.BN254Fp]{
In1: emulated.ValueOf[emulated.BN254Fp](3),
In2: emulated.ValueOf[emulated.BN254Fp](5),
Res: emulated.ValueOf[emulated.BN254Fp](15),
}
ccs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
panic(err)
} else {
fmt.Println("compiled")
}
witnessData, err := frontend.NewWitness(&witness, ecc.BN254.ScalarField())
if err != nil {
panic(err)
} else {
fmt.Println("secret witness parsed")
}
publicWitnessData, err := witnessData.Public()
if err != nil {
panic(err)
} else {
fmt.Println("public witness parsed")
}
pk, vk, err := groth16.Setup(ccs)
if err != nil {
panic(err)
} else {
fmt.Println("setup done")
}
proof, err := groth16.Prove(ccs, pk, witnessData, backend.WithSolverOptions(solver.WithHints(emulated.GetHints()...)))
if err != nil {
panic(err)
} else {
fmt.Println("proved")
}
err = groth16.Verify(proof, vk, publicWitnessData)
if err != nil {
panic(err)
} else {
fmt.Println("verified")
} |
Beta Was this translation helpful? Give feedback.
Hi, the online playground at https://play.gnark.io/ doesn't run the full prover to output a proof, but only runs until solving stage and then stops. There are some performance problems with compiling the full Groth16/PLONK prover.
For testing locally, I would recommend setting up a Go environment, doing:
And then start implementing the circuits in
main.go
for example. As an example on how to run the full Groth16 prover, see https://pkg.go.dev/github.com/consensys/[email protected]/std/math/emulated#example-Field: