mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-06 19:06:43 +01:00
fix/pk-parse-benchmarks
Parsers were working correctly, but the benchmarks had errors.
The benchmarks in the commit d1b3979eb6
are incorrect, correct ones are:
```
BenchmarkParsePk/ParsePkJson_circuit1k-4 2 529437960 ns/op
BenchmarkParsePk/ParsePkBin_circuit1k-4 2 607792597 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit1k-4 2 540594611 ns/op
BenchmarkParsePk/ParsePkJson_circuit5k-4 1 2769819086 ns/op
BenchmarkParsePk/ParsePkBin_circuit5k-4 1 3094913319 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit5k-4 1 2404651389 ns/op
BenchmarkParsePk/ParsePkJson_circuit10k-4 1 5374917709 ns/op
BenchmarkParsePk/ParsePkBin_circuit10k-4 1 5756633515 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit10k-4 1 4782081310 ns/op
BenchmarkParsePk/ParsePkJson_circuit20k-4 1 10374987398 ns/op
BenchmarkParsePk/ParsePkBin_circuit20k-4 1 11528361584 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit20k-4 1 9541829245 ns/op
BenchmarkParsePk/ParsePkJson_circuit50k-4 1 25979727146 ns/op
BenchmarkParsePk/ParsePkBin_circuit50k-4 1 28434810627 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit50k-4 1 23860248412 ns/op
```
The size of ProvingKey file for a circuit of 20k and 50k constraints:
```
circuit 20k constraints:
10097876 bytes of proving_key.go.bin
10097876 bytes of proving_key.bin
29760049 bytes of proving_key.json
circuit 50k constraints:
24195028 bytes of proving_key.go.bin
24194964 bytes of proving_key.bin
71484081 bytes of proving_key.json
```
go-circom-prover-verifier

Go implementation of the Groth16 protocol zkSNARK prover & verifier compatible with circom.
Using bn256 (used by go-ethereum) for the Pairing curve operations.
Example
- Generate Proof
import (
"github.com/iden3/go-circom-prover-verifier/parsers"
"github.com/iden3/go-circom-prover-verifier/prover"
"github.com/iden3/go-circom-prover-verifier/verifier"
)
[...]
// read ProvingKey & Witness files
provingKeyJson, _ := ioutil.ReadFile("../testdata/small/proving_key.json")
witnessJson, _ := ioutil.ReadFile("../testdata/small/witness.json")
// parse Proving Key
pk, _ := parsers.ParsePk(provingKeyJson)
// parse Witness
w, _ := parsers.ParseWitness(witnessJson)
// generate the proof
proof, pubSignals, _ := prover.GenerateProof(pk, w)
// print proof & publicSignals
proofStr, _ := parsers.ProofToJson(proof)
publicStr, _ := json.Marshal(parsers.ArrayBigIntToString(pubSignals))
fmt.Println(proofStr)
fmt.Println(publicStr)
- Verify Proof
// read proof & verificationKey & publicSignals
proofJson, _ := ioutil.ReadFile("../testdata/big/proof.json")
vkJson, _ := ioutil.ReadFile("../testdata/big/verification_key.json")
publicJson, _ := ioutil.ReadFile("../testdata/big/public.json")
// parse proof & verificationKey & publicSignals
public, _ := parsers.ParsePublicSignals(publicJson)
proof, _ := parsers.ParseProof(proofJson)
vk, _ := parsers.ParseVk(vkJson)
// verify the proof with the given verificationKey & publicSignals
v := verifier.Verify(vk, proof, public)
fmt.Println(v)
CLI
From the cli directory:
- Show options
> go run cli.go -help
go-circom-prover-verifier
v0.0.1
Usage of /tmp/go-build620318239/b001/exe/cli:
-proof string
proof path (default "proof.json")
-prove
prover mode
-provingkey string
provingKey path (default "proving_key.json")
-public string
public signals path (default "public.json")
-verificationkey string
verificationKey path (default "verification_key.json")
-verify
verifier mode
-witness string
witness path (default "witness.json")
- Prove
> go run cli.go -prove -provingkey=../testdata/circuit5k/proving_key.json -witness=../testdata/circuit5k/witness.json
- Verify
> go run cli.go -verify -verificationkey=../testdata/circuit5k/verification_key.json
Languages
Go
100%