Browse Source

update cli, update readme

pull/8/head
arnaucube 5 years ago
committed by mottla
parent
commit
dca8738d6e
5 changed files with 78 additions and 67 deletions
  1. +2
    -1
      .gitignore
  2. +57
    -56
      README.md
  3. +4
    -0
      build-cli.sh
  4. +15
    -10
      cli/main.go
  5. BIN
      go-snark-cli

+ 2
- 1
.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

+ 57
- 56
README.md

@ -36,6 +36,63 @@ Current implementation status:
- [![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.
@ -101,62 +158,6 @@ 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.
## Test

+ 4
- 0
build-cli.sh

@ -0,0 +1,4 @@
#!/bin/sh
cd cli && go build
mv ./cli ../go-snark-cli

+ 15
- 10
cli/main.go

@ -53,7 +53,7 @@ var commands = []cli.Command{
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 @@ func TrustedSetup(context *cli.Context) error {
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 @@ func GenerateProofs(context *cli.Context) error {
// 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:")

BIN
go-snark-cli


Loading…
Cancel
Save