From 601ed18455612e7c7699cf79e1a2a7cfc0a8ba1c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 30 Jan 2024 11:17:04 +0100 Subject: [PATCH] Verifier returns false when one of the operations fails --- contracts/Groth16Verifier.sol | 16 ++++++++++++---- test/Proofs.test.js | 9 ++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/contracts/Groth16Verifier.sol b/contracts/Groth16Verifier.sol index 972c2be..3e29aed 100644 --- a/contracts/Groth16Verifier.sol +++ b/contracts/Groth16Verifier.sol @@ -160,12 +160,18 @@ contract Groth16Verifier { ); G1Point memory product; (success, product) = Pairing.multiply(_verifyingKey.ic[i + 1], input[i]); - require(success, "pairing-mul-failed"); + if (!success) { + return false; + } (success, vkX) = Pairing.add(vkX, product); - require(success, "pairing-add-failed"); + if (!success) { + return false; + } } (success, vkX) = Pairing.add(vkX, _verifyingKey.ic[0]); - require(success, "pairing-add-failed"); + if (!success) { + return false; + } uint outcome; (success, outcome) = Pairing.pairingProd4( @@ -178,7 +184,9 @@ contract Groth16Verifier { proof.c, _verifyingKey.delta2 ); - require(success, "pairing-opcode-failed"); + if (!success) { + return false; + } return outcome == 1; } } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index ce0e4f7..7ebe87c 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -205,13 +205,16 @@ describe("Proofs", function () { it("fails proof submission when proof is incorrect", async function () { let invalid = exampleProof() - await expect(proofs.proofReceived(slotId, invalid, pubSignals)).to.be - .reverted + await expect( + proofs.proofReceived(slotId, invalid, pubSignals) + ).to.be.revertedWith("Invalid proof") }) it("fails proof submission when public input is incorrect", async function () { let invalid = [1, 2, 3] - await expect(proofs.proofReceived(slotId, proof, invalid)).to.be.reverted + await expect( + proofs.proofReceived(slotId, proof, invalid) + ).to.be.revertedWith("Invalid proof") }) it("emits an event when proof was submitted", async function () {