Fix mutation of inputs in Verify

This commit is contained in:
Eduard S
2020-04-23 16:02:00 +02:00
parent bbcbba3113
commit 40b280fc96
2 changed files with 5 additions and 1 deletions

View File

@@ -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])
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}
return bn256.PairingCheck(g1, g2)
}

View File

@@ -27,6 +27,10 @@ func TestVerify1(t *testing.T) {
v := Verify(vk, proof, public)
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) {