Skip to content

Commit 5f2bc6d

Browse files
authored
Challenge zk voting (#376)
* changes regarding grader, verifier contract, etc. * adapt readme to changes for grader
1 parent 0620df9 commit 5f2bc6d

File tree

5 files changed

+62
-61
lines changed

5 files changed

+62
-61
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Our contract will support three main functions:
161161
🔍 Open it up and check out the placeholder functions. Each of them represents a key piece of the voting logic.
162162
If you can already explain what they’re supposed to do, you’re ahead of the game! 😎
163163

164+
💡 The `Verifier.sol` contract is currently just a placeholder and will be replaced with the actual implementation later.
165+
164166
But this time you won’t just be working on the smart contract **🙂**
165167

166168
### **🥅 Goals**
@@ -943,7 +945,7 @@ You’ve built the circuit, created the verifier contract — now it’s time to
943945

944946
### 🔹 Step 1: Bring in the Verifier Contract
945947

946-
1. Copy your verifier contract into **`packages/hardhat/contracts`**.
948+
1. Replace the placeholder verifier contract **`Verifier.sol`** in **`packages/hardhat/contracts`** with the newly generated contract located in **`packages/circuits/target`**.
947949
2. Open **`00_deploy_your_voting_contract.ts`** and:
948950
- Uncomment the verifier deployment
949951
- Comment out the `verifierAddress`
@@ -982,8 +984,6 @@ That’s why **nullifiers are the cornerstone** of privacy-preserving voting.
982984
- Increment `s_yesVotes` or `s_noVotes` accordingly
983985
- Emit the `VoteCast` event
984986

985-
> 🚨⚠️ Go to packages/hardhat/contracts/mocks and uncomment all the code. This enables the mock contracts needed for local testing and verification.
986-
987987
<details>
988988
<summary>🦉 Guiding Questions</summary>
989989

@@ -1714,8 +1714,8 @@ const voteOnSepolia = async ({
17141714
functionName: "vote",
17151715
args: [
17161716
toHex(proofData.proof),
1717-
proofData.publicInputs[0], // _root
1718-
proofData.publicInputs[1], // _nullifierHash
1717+
proofData.publicInputs[0], // _nullifierHash
1718+
proofData.publicInputs[1], // _root
17191719
proofData.publicInputs[2], // _vote
17201720
proofData.publicInputs[3], // _depth
17211721
],

extension/README.md.args.mjs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ Our contract will support three main functions:
163163
🔍 Open it up and check out the placeholder functions. Each of them represents a key piece of the voting logic.
164164
If you can already explain what they’re supposed to do, you’re ahead of the game! 😎
165165
166+
💡 The \`Verifier.sol\` contract is currently just a placeholder and will be replaced with the actual implementation later.
167+
166168
But this time you won’t just be working on the smart contract **🙂**
167169
168170
### **🥅 Goals**
@@ -948,7 +950,7 @@ You’ve built the circuit, created the verifier contract — now it’s time to
948950
949951
### 🔹 Step 1: Bring in the Verifier Contract
950952
951-
1. Copy your verifier contract into **\`packages/hardhat/contracts\`**.
953+
1. Replace the placeholder verifier contract **\`Verifier.sol\`** in **\`packages/hardhat/contracts\`** with the newly generated contract located in **\`packages/circuits/target\`**.
952954
2. Open **\`00_deploy_your_voting_contract.ts\`** and:
953955
- Uncomment the verifier deployment
954956
- Comment out the \`verifierAddress\`
@@ -987,8 +989,6 @@ That’s why **nullifiers are the cornerstone** of privacy-preserving voting.
987989
- Increment \`s_yesVotes\` or \`s_noVotes\` accordingly
988990
- Emit the \`VoteCast\` event
989991
990-
> 🚨⚠️ Go to packages/hardhat/contracts/mocks and uncomment all the code. This enables the mock contracts needed for local testing and verification.
991-
992992
<details>
993993
<summary>🦉 Guiding Questions</summary>
994994
@@ -1075,16 +1075,6 @@ function vote(bytes memory _proof, bytes32 _nullifierHash, bytes32 _root, bytes3
10751075
10761076
emit VoteCast(_nullifierHash, msg.sender, _vote == bytes32(uint256(1)), block.timestamp, s_yesVotes, s_noVotes);
10771077
}
1078-
1079-
emit VoteCast(
1080-
_nullifierHash,
1081-
msg.sender,
1082-
_vote == bytes32(uint256(1)),
1083-
block.timestamp,
1084-
s_yesVotes,
1085-
s_noVotes
1086-
);
1087-
}
10881078
\`\`\`
10891079
10901080
</details>
@@ -1729,8 +1719,8 @@ const voteOnSepolia = async ({
17291719
functionName: "vote",
17301720
args: [
17311721
toHex(proofData.proof),
1732-
proofData.publicInputs[0], // _root
1733-
proofData.publicInputs[1], // _nullifierHash
1722+
proofData.publicInputs[0], // _nullifierHash
1723+
proofData.publicInputs[1], // _root
17341724
proofData.publicInputs[2], // _vote
17351725
proofData.publicInputs[3], // _depth
17361726
],
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.27;
3+
4+
interface IVerifier {
5+
function verify(bytes calldata _proof, bytes32[] calldata _publicInputs) external view returns (bool);
6+
}

extension/packages/hardhat/contracts/mocks/VerifierMock.sol

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,50 @@
22
pragma solidity >=0.8.0 <0.9.0;
33

44
/// Checkpoint 6 //////
5-
// import {IVerifier} from "../Verifier.sol";
5+
import {IVerifier} from "../Verifier.sol";
66

7-
// contract VerifierMock is IVerifier {
8-
// bool public shouldVerify = true;
7+
contract VerifierMock is IVerifier {
8+
bool public shouldVerify = true;
99

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;
1616

17-
// function setShouldVerify(bool _shouldVerify) external {
18-
// shouldVerify = _shouldVerify;
19-
// }
17+
function setShouldVerify(bool _shouldVerify) external {
18+
shouldVerify = _shouldVerify;
19+
}
2020

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+
}
2828

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+
}
3636

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+
}

extension/packages/hardhat/hardhat.config.ts.args.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ export const configOverrides = {
1313
},
1414
],
1515
},
16+
networks: {
17+
hardhat: {
18+
allowUnlimitedContractSize: true,
19+
},
20+
},
1621
};

0 commit comments

Comments
 (0)