diff --git a/cli/main.go b/cli/main.go index 6584bf7..3733e48 100644 --- a/cli/main.go +++ b/cli/main.go @@ -374,13 +374,6 @@ func VerifyProofs(context *cli.Context) error { json.Unmarshal([]byte(string(proofsFile)), &proof) panicErr(err) - // open compiledcircuit.json - compiledcircuitFile, err := ioutil.ReadFile("compiledcircuit.json") - panicErr(err) - var circuit circuitcompiler.Circuit - json.Unmarshal([]byte(string(compiledcircuitFile)), &circuit) - panicErr(err) - // open trustedsetup.json trustedsetupFile, err := ioutil.ReadFile("trustedsetup.json") panicErr(err) @@ -395,7 +388,7 @@ func VerifyProofs(context *cli.Context) error { err = json.Unmarshal([]byte(string(publicInputsFile)), &publicSignals) panicErr(err) - verified := snark.VerifyProof(circuit, trustedsetup, proof, publicSignals, true) + verified := snark.VerifyProof(trustedsetup, proof, publicSignals, true) if !verified { fmt.Println("ERROR: proofs not verified") } else { @@ -533,13 +526,6 @@ func Groth16VerifyProofs(context *cli.Context) error { json.Unmarshal([]byte(string(proofsFile)), &proof) panicErr(err) - // open compiledcircuit.json - compiledcircuitFile, err := ioutil.ReadFile("compiledcircuit.json") - panicErr(err) - var circuit circuitcompiler.Circuit - json.Unmarshal([]byte(string(compiledcircuitFile)), &circuit) - panicErr(err) - // open trustedsetup.json trustedsetupFile, err := ioutil.ReadFile("trustedsetup.json") panicErr(err) @@ -554,7 +540,7 @@ func Groth16VerifyProofs(context *cli.Context) error { err = json.Unmarshal([]byte(string(publicInputsFile)), &publicSignals) panicErr(err) - verified := groth16.VerifyProof(circuit, trustedsetup, proof, publicSignals, true) + verified := groth16.VerifyProof(trustedsetup, proof, publicSignals, true) if !verified { fmt.Println("ERROR: proofs not verified") } else { diff --git a/groth16/groth16.go b/groth16/groth16.go index 79592d2..e028997 100644 --- a/groth16/groth16.go +++ b/groth16/groth16.go @@ -275,7 +275,7 @@ func GenerateProofs(circuit circuitcompiler.Circuit, setup Setup, w []*big.Int, } // VerifyProof verifies over the BN128 the Pairings of the Proof -func VerifyProof(circuit circuitcompiler.Circuit, setup Setup, proof Proof, publicSignals []*big.Int, debug bool) bool { +func VerifyProof(setup Setup, proof Proof, publicSignals []*big.Int, debug bool) bool { icPubl := setup.Vk.IC[0] for i := 0; i < len(publicSignals); i++ { diff --git a/groth16/groth16_test.go b/groth16/groth16_test.go index fc91226..63c48b9 100644 --- a/groth16/groth16_test.go +++ b/groth16/groth16_test.go @@ -97,11 +97,11 @@ func TestGroth16MinimalFlow(t *testing.T) { b35Verif := big.NewInt(int64(35)) publicSignalsVerif := []*big.Int{b35Verif} before := time.Now() - assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true)) + assert.True(t, VerifyProof(setup, proof, publicSignalsVerif, true)) fmt.Println("verify proof time elapsed:", time.Since(before)) // check that with another public input the verification returns false bOtherWrongPublic := big.NewInt(int64(34)) wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} - assert.True(t, !VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false)) + assert.True(t, !VerifyProof(setup, proof, wrongPublicSignalsVerif, false)) } diff --git a/snark.go b/snark.go index 9bfe5cb..6e6e8c1 100644 --- a/snark.go +++ b/snark.go @@ -286,7 +286,7 @@ func GenerateProofs(circuit circuitcompiler.Circuit, setup Setup, w []*big.Int, } // VerifyProof verifies over the BN128 the Pairings of the Proof -func VerifyProof(circuit circuitcompiler.Circuit, setup Setup, proof Proof, publicSignals []*big.Int, debug bool) bool { +func VerifyProof(setup Setup, proof Proof, publicSignals []*big.Int, debug bool) bool { // e(piA, Va) == e(piA', g2) pairingPiaVa := Utils.Bn.Pairing(proof.PiA, setup.Vk.Vka) pairingPiapG2 := Utils.Bn.Pairing(proof.PiAp, Utils.Bn.G2.G) diff --git a/snark_test.go b/snark_test.go index 4cb4a85..0263185 100644 --- a/snark_test.go +++ b/snark_test.go @@ -98,13 +98,13 @@ func TestGroth16MinimalFlow(t *testing.T) { b35Verif := big.NewInt(int64(35)) publicSignalsVerif := []*big.Int{b35Verif} before := time.Now() - assert.True(t, groth16.VerifyProof(*circuit, setup, proof, publicSignalsVerif, true)) + assert.True(t, groth16.VerifyProof(setup, proof, publicSignalsVerif, true)) fmt.Println("verify proof time elapsed:", time.Since(before)) // check that with another public input the verification returns false bOtherWrongPublic := big.NewInt(int64(34)) wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} - assert.True(t, !groth16.VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false)) + assert.True(t, !groth16.VerifyProof(setup, proof, wrongPublicSignalsVerif, false)) } func TestZkFromFlatCircuitCode(t *testing.T) { @@ -233,13 +233,13 @@ func TestZkFromFlatCircuitCode(t *testing.T) { b35Verif := big.NewInt(int64(35)) publicSignalsVerif := []*big.Int{b35Verif} before := time.Now() - assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true)) + assert.True(t, VerifyProof(setup, proof, publicSignalsVerif, true)) fmt.Println("verify proof time elapsed:", time.Since(before)) // check that with another public input the verification returns false bOtherWrongPublic := big.NewInt(int64(34)) wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} - assert.True(t, !VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false)) + assert.True(t, !VerifyProof(setup, proof, wrongPublicSignalsVerif, false)) } func TestZkMultiplication(t *testing.T) { @@ -341,13 +341,13 @@ func TestZkMultiplication(t *testing.T) { b12Verif := big.NewInt(int64(12)) publicSignalsVerif := []*big.Int{b12Verif} before := time.Now() - assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true)) + assert.True(t, VerifyProof(setup, proof, publicSignalsVerif, true)) fmt.Println("verify proof time elapsed:", time.Since(before)) // check that with another public input the verification returns false bOtherWrongPublic := big.NewInt(int64(11)) wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} - assert.True(t, !VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false)) + assert.True(t, !VerifyProof(setup, proof, wrongPublicSignalsVerif, false)) } func TestMinimalFlow(t *testing.T) { @@ -430,11 +430,11 @@ func TestMinimalFlow(t *testing.T) { b35Verif := big.NewInt(int64(35)) publicSignalsVerif := []*big.Int{b35Verif} before := time.Now() - assert.True(t, VerifyProof(*circuit, setup, proof, publicSignalsVerif, true)) + assert.True(t, VerifyProof(setup, proof, publicSignalsVerif, true)) fmt.Println("verify proof time elapsed:", time.Since(before)) // check that with another public input the verification returns false bOtherWrongPublic := big.NewInt(int64(34)) wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} - assert.True(t, !VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false)) + assert.True(t, !VerifyProof(setup, proof, wrongPublicSignalsVerif, false)) } diff --git a/wasm/go-snark-wasm-wrapper.go b/wasm/go-snark-wasm-wrapper.go index b924abc..92b2f45 100644 --- a/wasm/go-snark-wasm-wrapper.go +++ b/wasm/go-snark-wasm-wrapper.go @@ -94,20 +94,9 @@ func generateProofs(this js.Value, i []js.Value) interface{} { } func verifyProofs(this js.Value, i []js.Value) interface{} { - var circuitStr utils.CircuitString - err := json.Unmarshal([]byte(i[0].String()), &circuitStr) - if err != nil { - println(i[0].String()) - println("error parsing circuit from stringified json") - } - circuit, err := utils.CircuitFromString(circuitStr) - if err != nil { - println("error " + err.Error()) - } - var setupStr utils.SetupString - println(i[1].String()) - err = json.Unmarshal([]byte(i[1].String()), &setupStr) + println(i[0].String()) + err := json.Unmarshal([]byte(i[0].String()), &setupStr) if err != nil { println("error parsing setup from stringified json") } @@ -117,9 +106,9 @@ func verifyProofs(this js.Value, i []js.Value) interface{} { } var proofStr utils.ProofString - err = json.Unmarshal([]byte(i[2].String()), &proofStr) + err = json.Unmarshal([]byte(i[1].String()), &proofStr) if err != nil { - println(i[0].String()) + println(i[1].String()) println("error parsing proof from stringified json") } proof, err := utils.ProofFromString(proofStr) @@ -128,13 +117,13 @@ func verifyProofs(this js.Value, i []js.Value) interface{} { } var publicInputs []*big.Int - err = json.Unmarshal([]byte(i[3].String()), &publicInputs) + err = json.Unmarshal([]byte(i[2].String()), &publicInputs) if err != nil { - println(i[0].String()) + println(i[2].String()) println("error parsing publicInputs from stringified json") } - verified := snark.VerifyProof(circuit, setup, proof, publicInputs, false) + verified := snark.VerifyProof(setup, proof, publicInputs, false) if err != nil { println("error verifiyng proof", err) } @@ -215,20 +204,9 @@ func grothGenerateProofs(this js.Value, i []js.Value) interface{} { } func grothVerifyProofs(this js.Value, i []js.Value) interface{} { - var circuitStr utils.CircuitString - err := json.Unmarshal([]byte(i[0].String()), &circuitStr) - if err != nil { - println(i[0].String()) - println("error parsing circuit from stringified json") - } - circuit, err := utils.CircuitFromString(circuitStr) - if err != nil { - println("error " + err.Error()) - } - var setupStr utils.GrothSetupString - println(i[1].String()) - err = json.Unmarshal([]byte(i[1].String()), &setupStr) + println(i[0].String()) + err := json.Unmarshal([]byte(i[0].String()), &setupStr) if err != nil { println("error parsing setup from stringified json") } @@ -238,9 +216,9 @@ func grothVerifyProofs(this js.Value, i []js.Value) interface{} { } var proofStr utils.GrothProofString - err = json.Unmarshal([]byte(i[2].String()), &proofStr) + err = json.Unmarshal([]byte(i[1].String()), &proofStr) if err != nil { - println(i[0].String()) + println(i[1].String()) println("error parsing proof from stringified json") } proof, err := utils.GrothProofFromString(proofStr) @@ -249,13 +227,13 @@ func grothVerifyProofs(this js.Value, i []js.Value) interface{} { } var publicInputs []*big.Int - err = json.Unmarshal([]byte(i[3].String()), &publicInputs) + err = json.Unmarshal([]byte(i[2].String()), &publicInputs) if err != nil { - println(i[0].String()) + println(i[2].String()) println("error parsing publicInputs from stringified json") } - verified := groth16.VerifyProof(circuit, setup, proof, publicInputs, false) + verified := groth16.VerifyProof(setup, proof, publicInputs, false) if err != nil { println("error verifiyng proof", err) } diff --git a/wasm/go-snark.wasm b/wasm/go-snark.wasm index 83d60bd..f2e4a19 100755 Binary files a/wasm/go-snark.wasm and b/wasm/go-snark.wasm differ diff --git a/wasm/index.js b/wasm/index.js index f7ad94b..fbe2e90 100644 --- a/wasm/index.js +++ b/wasm/index.js @@ -21,7 +21,6 @@ function callGenerateProof() { function callVerifyProof() { const proof = document.getElementById("proofResult").value; let r = verifyProofs( - JSON.stringify(circuit), JSON.stringify(setup), proof, JSON.stringify([35])