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.

90 lines
3.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. # go-circom-prover-verifier [![GoDoc](https://godoc.org/github.com/iden3/go-circom-prover-verifier?status.svg)](https://godoc.org/github.com/iden3/go-circom-prover-verifier) [![Go Report Card](https://goreportcard.com/badge/github.com/iden3/go-circom-prover-verifier)](https://goreportcard.com/report/github.com/iden3/go-circom-prover-verifier) [![Test](https://github.com/iden3/go-circom-prover-verifier/workflows/Test/badge.svg)](https://github.com/iden3/go-circom-prover-verifier/actions?query=workflow%3ATest)
  2. Experimental Go implementation of the [Groth16 protocol](https://eprint.iacr.org/2016/260.pdf) zkSNARK prover & verifier compatible with [circom](https://github.com/iden3/circom).
  3. Using [bn256](https://github.com/ethereum/go-ethereum/tree/master/crypto/bn256/cloudflare) (used by [go-ethereum](https://github.com/ethereum/go-ethereum)) for the Pairing curve operations.
  4. ### Example
  5. - Generate Proof
  6. ```go
  7. import (
  8. "github.com/iden3/go-circom-prover-verifier/parsers"
  9. "github.com/iden3/go-circom-prover-verifier/prover"
  10. "github.com/iden3/go-circom-prover-verifier/verifier"
  11. )
  12. [...]
  13. // read ProvingKey & Witness files
  14. provingKeyJson, _ := ioutil.ReadFile("../testdata/small/proving_key.json")
  15. witnessJson, _ := ioutil.ReadFile("../testdata/small/witness.json")
  16. // parse Proving Key
  17. pk, _ := parsers.ParsePk(provingKeyJson)
  18. // parse Witness
  19. w, _ := parsers.ParseWitness(witnessJson)
  20. // generate the proof
  21. proof, pubSignals, _ := prover.GenerateProof(pk, w)
  22. // print proof & publicSignals
  23. proofStr, _ := parsers.ProofToJson(proof)
  24. publicStr, _ := json.Marshal(parsers.ArrayBigIntToString(pubSignals))
  25. fmt.Println(proofStr)
  26. fmt.Println(publicStr)
  27. ```
  28. - Verify Proof
  29. ```go
  30. // read proof & verificationKey & publicSignals
  31. proofJson, _ := ioutil.ReadFile("../testdata/big/proof.json")
  32. vkJson, _ := ioutil.ReadFile("../testdata/big/verification_key.json")
  33. publicJson, _ := ioutil.ReadFile("../testdata/big/public.json")
  34. // parse proof & verificationKey & publicSignals
  35. public, _ := parsers.ParsePublicSignals(publicJson)
  36. proof, _ := parsers.ParseProof(proofJson)
  37. vk, _ := parsers.ParseVk(vkJson)
  38. // verify the proof with the given verificationKey & publicSignals
  39. v := verifier.Verify(vk, proof, public)
  40. fmt.Println(v)
  41. ```
  42. ## CLI
  43. From the `cli` directory:
  44. - Show options
  45. ```
  46. > go run cli.go -help
  47. go-circom-prover-verifier
  48. v0.0.1
  49. Usage of /tmp/go-build620318239/b001/exe/cli:
  50. -proof string
  51. proof path (default "proof.json")
  52. -prove
  53. prover mode
  54. -provingkey string
  55. provingKey path (default "proving_key.json")
  56. -public string
  57. public signals path (default "public.json")
  58. -verificationkey string
  59. verificationKey path (default "verification_key.json")
  60. -verify
  61. verifier mode
  62. -witness string
  63. witness path (default "witness.json")
  64. ```
  65. - Prove
  66. ```
  67. > go run cli.go -prove -provingkey=../testdata/small/proving_key.json -witness=../testdata/small/witness.json
  68. ```
  69. - Verify
  70. ```
  71. > go run cli.go -verify -verificationkey=../testdata/small/verification_key.json
  72. ```