Browse Source

remove circuit parameter from proof Verification

pull/14/head
arnaucube 5 years ago
parent
commit
41f7a3518a
8 changed files with 28 additions and 65 deletions
  1. +2
    -16
      cli/main.go
  2. +1
    -1
      groth16/groth16.go
  3. +2
    -2
      groth16/groth16_test.go
  4. +1
    -1
      snark.go
  5. +8
    -8
      snark_test.go
  6. +14
    -36
      wasm/go-snark-wasm-wrapper.go
  7. BIN
      wasm/go-snark.wasm
  8. +0
    -1
      wasm/index.js

+ 2
- 16
cli/main.go

@ -374,13 +374,6 @@ func VerifyProofs(context *cli.Context) error {
json.Unmarshal([]byte(string(proofsFile)), &proof) json.Unmarshal([]byte(string(proofsFile)), &proof)
panicErr(err) 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 // open trustedsetup.json
trustedsetupFile, err := ioutil.ReadFile("trustedsetup.json") trustedsetupFile, err := ioutil.ReadFile("trustedsetup.json")
panicErr(err) panicErr(err)
@ -395,7 +388,7 @@ func VerifyProofs(context *cli.Context) error {
err = json.Unmarshal([]byte(string(publicInputsFile)), &publicSignals) err = json.Unmarshal([]byte(string(publicInputsFile)), &publicSignals)
panicErr(err) panicErr(err)
verified := snark.VerifyProof(circuit, trustedsetup, proof, publicSignals, true)
verified := snark.VerifyProof(trustedsetup, proof, publicSignals, true)
if !verified { if !verified {
fmt.Println("ERROR: proofs not verified") fmt.Println("ERROR: proofs not verified")
} else { } else {
@ -533,13 +526,6 @@ func Groth16VerifyProofs(context *cli.Context) error {
json.Unmarshal([]byte(string(proofsFile)), &proof) json.Unmarshal([]byte(string(proofsFile)), &proof)
panicErr(err) 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 // open trustedsetup.json
trustedsetupFile, err := ioutil.ReadFile("trustedsetup.json") trustedsetupFile, err := ioutil.ReadFile("trustedsetup.json")
panicErr(err) panicErr(err)
@ -554,7 +540,7 @@ func Groth16VerifyProofs(context *cli.Context) error {
err = json.Unmarshal([]byte(string(publicInputsFile)), &publicSignals) err = json.Unmarshal([]byte(string(publicInputsFile)), &publicSignals)
panicErr(err) panicErr(err)
verified := groth16.VerifyProof(circuit, trustedsetup, proof, publicSignals, true)
verified := groth16.VerifyProof(trustedsetup, proof, publicSignals, true)
if !verified { if !verified {
fmt.Println("ERROR: proofs not verified") fmt.Println("ERROR: proofs not verified")
} else { } else {

+ 1
- 1
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 // 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] icPubl := setup.Vk.IC[0]
for i := 0; i < len(publicSignals); i++ { for i := 0; i < len(publicSignals); i++ {

+ 2
- 2
groth16/groth16_test.go

@ -97,11 +97,11 @@ func TestGroth16MinimalFlow(t *testing.T) {
b35Verif := big.NewInt(int64(35)) b35Verif := big.NewInt(int64(35))
publicSignalsVerif := []*big.Int{b35Verif} publicSignalsVerif := []*big.Int{b35Verif}
before := time.Now() 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)) fmt.Println("verify proof time elapsed:", time.Since(before))
// check that with another public input the verification returns false // check that with another public input the verification returns false
bOtherWrongPublic := big.NewInt(int64(34)) bOtherWrongPublic := big.NewInt(int64(34))
wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic}
assert.True(t, !VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false))
assert.True(t, !VerifyProof(setup, proof, wrongPublicSignalsVerif, false))
} }

+ 1
- 1
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 // 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) // e(piA, Va) == e(piA', g2)
pairingPiaVa := Utils.Bn.Pairing(proof.PiA, setup.Vk.Vka) pairingPiaVa := Utils.Bn.Pairing(proof.PiA, setup.Vk.Vka)
pairingPiapG2 := Utils.Bn.Pairing(proof.PiAp, Utils.Bn.G2.G) pairingPiapG2 := Utils.Bn.Pairing(proof.PiAp, Utils.Bn.G2.G)

+ 8
- 8
snark_test.go

@ -98,13 +98,13 @@ func TestGroth16MinimalFlow(t *testing.T) {
b35Verif := big.NewInt(int64(35)) b35Verif := big.NewInt(int64(35))
publicSignalsVerif := []*big.Int{b35Verif} publicSignalsVerif := []*big.Int{b35Verif}
before := time.Now() 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)) fmt.Println("verify proof time elapsed:", time.Since(before))
// check that with another public input the verification returns false // check that with another public input the verification returns false
bOtherWrongPublic := big.NewInt(int64(34)) bOtherWrongPublic := big.NewInt(int64(34))
wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} 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) { func TestZkFromFlatCircuitCode(t *testing.T) {
@ -233,13 +233,13 @@ func TestZkFromFlatCircuitCode(t *testing.T) {
b35Verif := big.NewInt(int64(35)) b35Verif := big.NewInt(int64(35))
publicSignalsVerif := []*big.Int{b35Verif} publicSignalsVerif := []*big.Int{b35Verif}
before := time.Now() 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)) fmt.Println("verify proof time elapsed:", time.Since(before))
// check that with another public input the verification returns false // check that with another public input the verification returns false
bOtherWrongPublic := big.NewInt(int64(34)) bOtherWrongPublic := big.NewInt(int64(34))
wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} 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) { func TestZkMultiplication(t *testing.T) {
@ -341,13 +341,13 @@ func TestZkMultiplication(t *testing.T) {
b12Verif := big.NewInt(int64(12)) b12Verif := big.NewInt(int64(12))
publicSignalsVerif := []*big.Int{b12Verif} publicSignalsVerif := []*big.Int{b12Verif}
before := time.Now() 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)) fmt.Println("verify proof time elapsed:", time.Since(before))
// check that with another public input the verification returns false // check that with another public input the verification returns false
bOtherWrongPublic := big.NewInt(int64(11)) bOtherWrongPublic := big.NewInt(int64(11))
wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} 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) { func TestMinimalFlow(t *testing.T) {
@ -430,11 +430,11 @@ func TestMinimalFlow(t *testing.T) {
b35Verif := big.NewInt(int64(35)) b35Verif := big.NewInt(int64(35))
publicSignalsVerif := []*big.Int{b35Verif} publicSignalsVerif := []*big.Int{b35Verif}
before := time.Now() 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)) fmt.Println("verify proof time elapsed:", time.Since(before))
// check that with another public input the verification returns false // check that with another public input the verification returns false
bOtherWrongPublic := big.NewInt(int64(34)) bOtherWrongPublic := big.NewInt(int64(34))
wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic} wrongPublicSignalsVerif := []*big.Int{bOtherWrongPublic}
assert.True(t, !VerifyProof(*circuit, setup, proof, wrongPublicSignalsVerif, false))
assert.True(t, !VerifyProof(setup, proof, wrongPublicSignalsVerif, false))
} }

+ 14
- 36
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{} { 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 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 { if err != nil {
println("error parsing setup from stringified json") println("error parsing setup from stringified json")
} }
@ -117,9 +106,9 @@ func verifyProofs(this js.Value, i []js.Value) interface{} {
} }
var proofStr utils.ProofString var proofStr utils.ProofString
err = json.Unmarshal([]byte(i[2].String()), &proofStr)
err = json.Unmarshal([]byte(i[1].String()), &proofStr)
if err != nil { if err != nil {
println(i[0].String())
println(i[1].String())
println("error parsing proof from stringified json") println("error parsing proof from stringified json")
} }
proof, err := utils.ProofFromString(proofStr) proof, err := utils.ProofFromString(proofStr)
@ -128,13 +117,13 @@ func verifyProofs(this js.Value, i []js.Value) interface{} {
} }
var publicInputs []*big.Int var publicInputs []*big.Int
err = json.Unmarshal([]byte(i[3].String()), &publicInputs)
err = json.Unmarshal([]byte(i[2].String()), &publicInputs)
if err != nil { if err != nil {
println(i[0].String())
println(i[2].String())
println("error parsing publicInputs from stringified json") 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 { if err != nil {
println("error verifiyng proof", err) 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{} { 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 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 { if err != nil {
println("error parsing setup from stringified json") println("error parsing setup from stringified json")
} }
@ -238,9 +216,9 @@ func grothVerifyProofs(this js.Value, i []js.Value) interface{} {
} }
var proofStr utils.GrothProofString var proofStr utils.GrothProofString
err = json.Unmarshal([]byte(i[2].String()), &proofStr)
err = json.Unmarshal([]byte(i[1].String()), &proofStr)
if err != nil { if err != nil {
println(i[0].String())
println(i[1].String())
println("error parsing proof from stringified json") println("error parsing proof from stringified json")
} }
proof, err := utils.GrothProofFromString(proofStr) proof, err := utils.GrothProofFromString(proofStr)
@ -249,13 +227,13 @@ func grothVerifyProofs(this js.Value, i []js.Value) interface{} {
} }
var publicInputs []*big.Int var publicInputs []*big.Int
err = json.Unmarshal([]byte(i[3].String()), &publicInputs)
err = json.Unmarshal([]byte(i[2].String()), &publicInputs)
if err != nil { if err != nil {
println(i[0].String())
println(i[2].String())
println("error parsing publicInputs from stringified json") 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 { if err != nil {
println("error verifiyng proof", err) println("error verifiyng proof", err)
} }

BIN
wasm/go-snark.wasm


+ 0
- 1
wasm/index.js

@ -21,7 +21,6 @@ function callGenerateProof() {
function callVerifyProof() { function callVerifyProof() {
const proof = document.getElementById("proofResult").value; const proof = document.getElementById("proofResult").value;
let r = verifyProofs( let r = verifyProofs(
JSON.stringify(circuit),
JSON.stringify(setup), JSON.stringify(setup),
proof, proof,
JSON.stringify([35]) JSON.stringify([35])

Loading…
Cancel
Save