You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Eduard S 4349ce584f
Merge pull request #24 from iden3/feature/update
2 years ago
.github/workflows Add cli to convert Pk to go-circom binary file 2 years ago
cli Fix binary parser bug, make go.bin format deterministic 2 years ago
parsers Fix binary parser bug, make go.bin format deterministic 2 years ago
prover Remove unnecessary structs & polsC 2 years ago
testdata Add cli to convert Pk to go-circom binary file 2 years ago
types Remove unnecessary structs & polsC 2 years ago
verifier Fix prover benchmark file paths, update readme, and other small updates 2 years ago
.gitignore Add witness parser from binary file 2 years ago
LICENSE Add arithmetic mod operations 2 years ago
README.md Fix prover benchmark file paths, update readme, and other small updates 2 years ago
go.mod Update deps 2 years ago
go.sum Update deps 2 years ago

README.md

go-circom-prover-verifier GoDoc Go Report Card Test

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