Eduard S 6ec118d4e2 | 4 years ago | |
---|---|---|
.github/workflows | 4 years ago | |
cli | 4 years ago | |
parsers | 4 years ago | |
prover | 4 years ago | |
testdata | 4 years ago | |
types | 4 years ago | |
verifier | 4 years ago | |
.gitignore | 4 years ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
go.mod | 4 years ago | |
go.sum | 4 years ago |
Go implementation of the Groth16 protocol zkSNARK prover & verifier compatible with circom.
Using bn256 (used by go-ethereum) for the Pairing curve operations.
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)
// 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)
From the cli
directory:
> 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")
> go run cli.go -prove -provingkey=../testdata/circuit5k/proving_key.json -witness=../testdata/circuit5k/witness.json
> go run cli.go -verify -verificationkey=../testdata/circuit5k/verification_key.json