From ec803adb3dc9d615b86b9dcc863ac428ffc82f6f Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 25 Jan 2024 09:59:01 +0100 Subject: [PATCH] Test verifier accepts any proof, except all 0 values --- contracts/TestVerifier.sol | 25 ++++++++++++------------- test/Marketplace.test.js | 4 ++-- test/examples.js | 13 ++++++++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/contracts/TestVerifier.sol b/contracts/TestVerifier.sol index 862ffcd..7acef95 100644 --- a/contracts/TestVerifier.sol +++ b/contracts/TestVerifier.sol @@ -4,20 +4,19 @@ pragma solidity 0.8.23; import "./Groth16.sol"; contract TestVerifier is IGroth16Verifier { - bool private _proofsAreValid; - - constructor() { - _proofsAreValid = true; - } - - function setProofsAreValid(bool proofsAreValid) public { - _proofsAreValid = proofsAreValid; - } - function verify( - Groth16Proof calldata, + Groth16Proof calldata proof, uint[] calldata - ) external view returns (bool) { - return _proofsAreValid; + ) external pure returns (bool) { + // accepts any proof, except the proof with all zero values + return + !(proof.a.x == 0 && + proof.a.y == 0 && + proof.b.x[0] == 0 && + proof.b.x[1] == 0 && + proof.b.y[0] == 0 && + proof.b.y[1] == 0 && + proof.c.x == 0 && + proof.c.y == 0); } } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 9ef50b7..94fe6e9 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -6,6 +6,7 @@ const { exampleConfiguration, exampleRequest, exampleProof, + invalidProof, } = require("./examples") const { periodic, hours } = require("./time") const { requestId, slotId, askToArray } = require("./ids") @@ -219,9 +220,8 @@ describe("Marketplace", function () { }) it("is rejected when proof is incorrect", async function () { - await verifier.setProofsAreValid(false) await expect( - marketplace.fillSlot(slot.request, slot.index, proof) + marketplace.fillSlot(slot.request, slot.index, invalidProof()) ).to.be.revertedWith("Invalid proof") }) diff --git a/test/examples.js b/test/examples.js index 61b2976..895f429 100644 --- a/test/examples.js +++ b/test/examples.js @@ -46,4 +46,15 @@ const exampleProof = () => ({ c: { x: 7, y: 8 }, }) -module.exports = { exampleConfiguration, exampleRequest, exampleProof } +const invalidProof = () => ({ + a: { x: 0, y: 0 }, + b: { x: [0, 0], y: [0, 0] }, + c: { x: 0, y: 0 }, +}) + +module.exports = { + exampleConfiguration, + exampleRequest, + exampleProof, + invalidProof, +}