Browse Source

Fix mutation of inputs in Verify

ed255-patch-1
Eduard S 4 years ago
parent
commit
40b280fc96
2 changed files with 5 additions and 1 deletions
  1. +1
    -1
      verifier/verifier.go
  2. +4
    -0
      verifier/verifier_test.go

+ 1
- 1
verifier/verifier.go

@ -32,7 +32,7 @@ func Verify(vk *types.Vk, proof *types.Proof, inputs []*big.Int) bool {
} }
vkX = new(bn256.G1).Add(vkX, vk.IC[0]) vkX = new(bn256.G1).Add(vkX, vk.IC[0])
g1 := []*bn256.G1{proof.A, vk.Alpha.Neg(vk.Alpha), vkX.Neg(vkX), proof.C.Neg(proof.C)}
g1 := []*bn256.G1{proof.A, new(bn256.G1).Neg(vk.Alpha), vkX.Neg(vkX), new(bn256.G1).Neg(proof.C)}
g2 := []*bn256.G2{proof.B, vk.Beta, vk.Gamma, vk.Delta} g2 := []*bn256.G2{proof.B, vk.Beta, vk.Gamma, vk.Delta}
return bn256.PairingCheck(g1, g2) return bn256.PairingCheck(g1, g2)
} }

+ 4
- 0
verifier/verifier_test.go

@ -27,6 +27,10 @@ func TestVerify1(t *testing.T) {
v := Verify(vk, proof, public) v := Verify(vk, proof, public)
assert.True(t, v) assert.True(t, v)
// Verify again to check that `Verify` hasn't mutated the inputs
v = Verify(vk, proof, public)
assert.True(t, v)
} }
func BenchmarkVerify(b *testing.B) { func BenchmarkVerify(b *testing.B) {

Loading…
Cancel
Save