Verifier returns false when one of the operations fails

This commit is contained in:
Mark Spanbroek 2024-01-30 11:17:04 +01:00 committed by markspanbroek
parent c495770679
commit 601ed18455
2 changed files with 18 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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 () {