Test verifier accepts any proof, except all 0 values
This commit is contained in:
parent
331bc56e8f
commit
ec803adb3d
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue