Verifier returns false when one of the operations fails
This commit is contained in:
parent
c495770679
commit
601ed18455
|
@ -160,12 +160,18 @@ contract Groth16Verifier {
|
||||||
);
|
);
|
||||||
G1Point memory product;
|
G1Point memory product;
|
||||||
(success, product) = Pairing.multiply(_verifyingKey.ic[i + 1], input[i]);
|
(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);
|
(success, vkX) = Pairing.add(vkX, product);
|
||||||
require(success, "pairing-add-failed");
|
if (!success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(success, vkX) = Pairing.add(vkX, _verifyingKey.ic[0]);
|
(success, vkX) = Pairing.add(vkX, _verifyingKey.ic[0]);
|
||||||
require(success, "pairing-add-failed");
|
if (!success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
uint outcome;
|
uint outcome;
|
||||||
(success, outcome) =
|
(success, outcome) =
|
||||||
Pairing.pairingProd4(
|
Pairing.pairingProd4(
|
||||||
|
@ -178,7 +184,9 @@ contract Groth16Verifier {
|
||||||
proof.c,
|
proof.c,
|
||||||
_verifyingKey.delta2
|
_verifyingKey.delta2
|
||||||
);
|
);
|
||||||
require(success, "pairing-opcode-failed");
|
if (!success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return outcome == 1;
|
return outcome == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,13 +205,16 @@ describe("Proofs", function () {
|
||||||
|
|
||||||
it("fails proof submission when proof is incorrect", async function () {
|
it("fails proof submission when proof is incorrect", async function () {
|
||||||
let invalid = exampleProof()
|
let invalid = exampleProof()
|
||||||
await expect(proofs.proofReceived(slotId, invalid, pubSignals)).to.be
|
await expect(
|
||||||
.reverted
|
proofs.proofReceived(slotId, invalid, pubSignals)
|
||||||
|
).to.be.revertedWith("Invalid proof")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("fails proof submission when public input is incorrect", async function () {
|
it("fails proof submission when public input is incorrect", async function () {
|
||||||
let invalid = [1, 2, 3]
|
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 () {
|
it("emits an event when proof was submitted", async function () {
|
||||||
|
|
Loading…
Reference in New Issue