Git Product home page Git Product logo

go-snark's Introduction

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

go-snark's People

Contributors

arnaucube avatar druiz0992 avatar ed255 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.