arnaucube
arnaucube/go-snarkPublic Self-hosted repository
update cli, update readme
arnaucube arnaucube@gmail.com
Sun, 12 May 2019 17:35:22 +0200
commit

66629d2158c299e24a9f7a0aa69e8016ef3b67db

parent

8ad8ae35f7a1aca26973eee744e2a231b20cc475

5 files changed, 78 insertions(+), 67 deletions(-)

jump to
M .gitignore → .gitignore

@@ -1,6 +1,7 @@

*.Backup cli/compiledcircuit.json -cli/inputs.json +cli/privateInputs.json +cli/publicInputs.json cli/proofs.json cli/test.circuit cli/trustedsetup.json
M README.md → README.md

@@ -36,6 +36,63 @@ - [![GoDoc](https://godoc.org/github.com/arnaucube/go-snark/fields?status.svg)](https://godoc.org/github.com/arnaucube/go-snark/fields) Finite Fields operations

- [![GoDoc](https://godoc.org/github.com/arnaucube/go-snark/r1csqap?status.svg)](https://godoc.org/github.com/arnaucube/go-snark/r1csqap) R1CS to QAP (more details: https://github.com/arnaucube/go-snark/tree/master/r1csqap) - [![GoDoc](https://godoc.org/github.com/arnaucube/go-snark/circuitcompiler?status.svg)](https://godoc.org/github.com/arnaucube/go-snark/circuitcompiler) Circuit Compiler +### CLI usage + +#### Compile circuit +Having a circuit file `test.circuit`: +``` +func test(private s0, public s1): + s2 = s0 * s0 + s3 = s2 * s0 + s4 = s3 + s0 + s5 = s4 + 5 + equals(s1, s5) + out = 1 * 1 +``` +And a private inputs file `privateInputs.json` +``` +[ + 3 +] +``` +And a public inputs file `publicInputs.json` +``` +[ + 35 +] +``` + +In the command line, execute: +``` +> ./go-snark-cli compile test.circuit +``` + +This will output the `compiledcircuit.json` file. + +#### Trusted Setup +Having the `compiledcircuit.json`, now we can generate the `TrustedSetup`: +``` +> ./go-snark-cli trustedsetup +``` +This will create the file `trustedsetup.json` with the TrustedSetup data, and also a `toxic.json` file, with the parameters to delete from the `Trusted Setup`. + + +#### Generate Proofs +Assumming that we have the `compiledcircuit.json`, `trustedsetup.json`, `privateInputs.json` and the `publicInputs.json` we can now generate the `Proofs` with the following command: +``` +> ./go-snark-cli genproofs +``` + +This will store the file `proofs.json`, that contains all the SNARK proofs. + +#### Verify Proofs +Having the `proofs.json`, `compiledcircuit.json`, `trustedsetup.json` `publicInputs.json` files, we can now verify the `Pairings` of the proofs, in order to verify the proofs. +``` +> ./go-snark-cli verify +``` +This will return a `true` if the proofs are verified, or a `false` if the proofs are not verified. + + ### Library usage Warning: not finished.

@@ -100,62 +157,6 @@ b35Verif := big.NewInt(int64(35))

publicSignalsVerif := []*big.Int{b35Verif} assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true)) ``` - -### CLI usage - -#### Compile circuit -Having a circuit file `test.circuit`: -``` -func test(private s0, public s1): - s2 = s0 * s0 - s3 = s2 * s0 - s4 = s3 + s0 - s5 = s4 + 5 - equals(s1, s5) - out = 1 * 1 -``` -And a private inputs file `privateInputs.json` -``` -[ - 3 -] -``` -And a public inputs file `publicInputs.json` -``` -[ - 35 -] -``` - -In the command line, execute: -``` -> go-snark-cli compile test.circuit -``` - -This will output the `compiledcircuit.json` file. - -#### Trusted Setup -Having the `compiledcircuit.json`, now we can generate the `TrustedSetup`: -``` -> go-snark-cli trustedsetup -``` -This will create the file `trustedsetup.json` with the TrustedSetup data, and also a `toxic.json` file, with the parameters to delete from the `Trusted Setup`. - - -#### Generate Proofs -Assumming that we have the `compiledcircuit.json`, `trustedsetup.json`, `privateInputs.json` and the `publicInputs.json` we can now generate the `Proofs` with the following command: -``` -> go-snark-cli genproofs -``` - -This will store the file `proofs.json`, that contains all the SNARK proofs. - -#### Verify Proofs -Having the `proofs.json`, `compiledcircuit.json`, `trustedsetup.json` `publicInputs.json` files, we can now verify the `Pairings` of the proofs, in order to verify the proofs. -``` -> go-snark-cli verify -``` -This will return a `true` if the proofs are verified, or a `false` if the proofs are not verified.
A build-cli.sh

@@ -0,0 +1,4 @@

+#!/bin/sh + +cd cli && go build +mv ./cli ../go-snark-cli
M cli/main.go → cli/main.go

@@ -53,7 +53,7 @@

func main() { app := cli.NewApp() app.Name = "go-snarks-cli" - app.Version = "0.1.0-alpha" + app.Version = "0.0.1-alpha" app.Flags = []cli.Flag{ cli.StringFlag{Name: "config"}, }

@@ -170,14 +170,20 @@ var circuit circuitcompiler.Circuit

json.Unmarshal([]byte(string(compiledcircuitFile)), &circuit) panicErr(err) - // read inputs file - inputsFile, err := ioutil.ReadFile("inputs.json") + // read privateInputs file + privateInputsFile, err := ioutil.ReadFile("privateInputs.json") + panicErr(err) + // read publicInputs file + publicInputsFile, err := ioutil.ReadFile("publicInputs.json") panicErr(err) + // parse inputs from inputsFile - // var inputs []*big.Int var inputs circuitcompiler.Inputs - json.Unmarshal([]byte(string(inputsFile)), &inputs) + err = json.Unmarshal([]byte(string(privateInputsFile)), &inputs.Private) + panicErr(err) + err = json.Unmarshal([]byte(string(publicInputsFile)), &inputs.Public) panicErr(err) + // calculate wittness w, err := circuit.CalculateWitness(inputs.Private, inputs.Public) panicErr(err)

@@ -245,23 +251,22 @@

// calculate wittness w, err := circuit.CalculateWitness(inputs.Private, inputs.Public) panicErr(err) - fmt.Println("\nwitness", w) + fmt.Println("witness", w) // flat code to R1CS - // a, b, c := circuit.GenerateR1CS() a := circuit.R1CS.A b := circuit.R1CS.B c := circuit.R1CS.C // R1CS to QAP - alphas, betas, gammas, zx := snark.Utils.PF.R1CSToQAP(a, b, c) + alphas, betas, gammas, _ := snark.Utils.PF.R1CSToQAP(a, b, c) _, _, _, px := snark.Utils.PF.CombinePolynomials(w, alphas, betas, gammas) - hx := snark.Utils.PF.DivisorPolynomial(px, zx) + hx := snark.Utils.PF.DivisorPolynomial(px, trustedsetup.Pk.Z) fmt.Println(circuit) fmt.Println(trustedsetup.G1T) fmt.Println(hx) fmt.Println(w) - proof, err := snark.GenerateProofs(circuit, trustedsetup, hx, w) + proof, err := snark.GenerateProofs(circuit, trustedsetup, w, px) panicErr(err) fmt.Println("\n proofs:")