go-snark

module
Version: v0.0.0-...-1c2a880 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2021 License: GPL-3.0

README

go-snark GoDoc Go Report Card Test

Go implementation of the Groth16 protocol zkSNARK prover & verifier compatible with:

Using bn256 (used by go-ethereum) for the Pairing curve operations.

Usage
  • Generate Proof
import (
  "github.com/vocdoni/go-snark/parsers"
  "github.com/vocdoni/go-snark/prover"
  "github.com/vocdoni/go-snark/verifier"
)

[...]

// read ProvingKey & Witness files
provingKeyJSON, _ := ioutil.ReadFile("../testdata/circuit1k/proving_key.json")
witnessJSON, _ := ioutil.ReadFile("../testdata/circuit1k/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/circuit1k/proof.json")
vkJSON, _ := ioutil.ReadFile("../testdata/circuit1k/verification_key.json")
publicJSON, _ := ioutil.ReadFile("../testdata/circuit1k/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-snark
                 v0.0.1
Usage of go-snark:
  -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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL