|
2 | 2 | pragma solidity >=0.8.0 <0.9.0; |
3 | 3 |
|
4 | 4 | /// Checkpoint 6 ////// |
5 | | -// import {IVerifier} from "../Verifier.sol"; |
| 5 | +import {IVerifier} from "../Verifier.sol"; |
6 | 6 |
|
7 | | -// contract VerifierMock is IVerifier { |
8 | | -// bool public shouldVerify = true; |
| 7 | +contract VerifierMock is IVerifier { |
| 8 | + bool public shouldVerify = true; |
9 | 9 |
|
10 | | -// // Optional: enforce an exact public inputs set and order for tests |
11 | | -// bool public enforceExpectedInputs; |
12 | | -// bytes32 public expectedNullifier; |
13 | | -// bytes32 public expectedRoot; |
14 | | -// bytes32 public expectedVote; |
15 | | -// bytes32 public expectedDepth; |
| 10 | + // Optional: enforce an exact public inputs set and order for tests |
| 11 | + bool public enforceExpectedInputs; |
| 12 | + bytes32 public expectedNullifier; |
| 13 | + bytes32 public expectedRoot; |
| 14 | + bytes32 public expectedVote; |
| 15 | + bytes32 public expectedDepth; |
16 | 16 |
|
17 | | -// function setShouldVerify(bool _shouldVerify) external { |
18 | | -// shouldVerify = _shouldVerify; |
19 | | -// } |
| 17 | + function setShouldVerify(bool _shouldVerify) external { |
| 18 | + shouldVerify = _shouldVerify; |
| 19 | + } |
20 | 20 |
|
21 | | -// function setExpectedInputs(bytes32 _nullifier, bytes32 _root, bytes32 _vote, bytes32 _depth) external { |
22 | | -// enforceExpectedInputs = true; |
23 | | -// expectedNullifier = _nullifier; |
24 | | -// expectedRoot = _root; |
25 | | -// expectedVote = _vote; |
26 | | -// expectedDepth = _depth; |
27 | | -// } |
| 21 | + function setExpectedInputs(bytes32 _nullifier, bytes32 _root, bytes32 _vote, bytes32 _depth) external { |
| 22 | + enforceExpectedInputs = true; |
| 23 | + expectedNullifier = _nullifier; |
| 24 | + expectedRoot = _root; |
| 25 | + expectedVote = _vote; |
| 26 | + expectedDepth = _depth; |
| 27 | + } |
28 | 28 |
|
29 | | -// function clearExpectedInputs() external { |
30 | | -// enforceExpectedInputs = false; |
31 | | -// expectedNullifier = 0x0; |
32 | | -// expectedRoot = 0x0; |
33 | | -// expectedVote = 0x0; |
34 | | -// expectedDepth = 0x0; |
35 | | -// } |
| 29 | + function clearExpectedInputs() external { |
| 30 | + enforceExpectedInputs = false; |
| 31 | + expectedNullifier = 0x0; |
| 32 | + expectedRoot = 0x0; |
| 33 | + expectedVote = 0x0; |
| 34 | + expectedDepth = 0x0; |
| 35 | + } |
36 | 36 |
|
37 | | -// function verify(bytes calldata, bytes32[] calldata _publicInputs) external view returns (bool) { |
38 | | -// if (!shouldVerify) { |
39 | | -// return false; |
40 | | -// } |
41 | | -// if (enforceExpectedInputs) { |
42 | | -// if ( |
43 | | -// _publicInputs.length != 4 || _publicInputs[0] != expectedNullifier || _publicInputs[1] != expectedRoot |
44 | | -// || _publicInputs[2] != expectedVote || _publicInputs[3] != expectedDepth |
45 | | -// ) { |
46 | | -// return false; |
47 | | -// } |
48 | | -// } |
49 | | -// return true; |
50 | | -// } |
51 | | -// } |
| 37 | + function verify(bytes calldata, bytes32[] calldata _publicInputs) external view returns (bool) { |
| 38 | + if (!shouldVerify) { |
| 39 | + return false; |
| 40 | + } |
| 41 | + if (enforceExpectedInputs) { |
| 42 | + if ( |
| 43 | + _publicInputs.length != 4 || _publicInputs[0] != expectedNullifier || _publicInputs[1] != expectedRoot |
| 44 | + || _publicInputs[2] != expectedVote || _publicInputs[3] != expectedDepth |
| 45 | + ) { |
| 46 | + return false; |
| 47 | + } |
| 48 | + } |
| 49 | + return true; |
| 50 | + } |
| 51 | +} |
0 commit comments