You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: foundry-voting/README.md
+23-7
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,30 @@
4
4
5
5
This example project shows how to create a simple zk voting circuit in Noir with a corresponding Solidity contract to track eligible voters, proposals and votes.
6
6
7
+
This example was last tested with Noir version 0.10.3. You can install it with [noirup](https://noir-lang.org/getting_started/nargo_installation#option-1-noirup) using
8
+
9
+
```bash
10
+
noirup -v 0.10.3
11
+
```
12
+
7
13
## Overview
8
14
9
15
This is the model used for creating the [circuit](circuits/src/main.nr) and the [zkVote contract](src/zkVote.sol) to manage private voting.
10
16
11
17
1. Create a set of voters. A merkle root is stored in the zkVote Solidity contract that voters will use to verify membership against. In this example, there are 4 accounts in the set of voters. The private keys are 0, 1, 2, 3 and the secret value to create the commitment is 9.
This gives intermediate hashes of `0x0a93e3f9a5af4abe169499e3ecb3e0025014467d673983c959a359a1ae5f25b7` (`pedersen(commitment0, commitment1)`) and `0x189f8f83d5a665aa299216fb5562f7064885af3e879ac53aeba450d73ca425b3` (`pedersen(commitment2, commitment3)`) and a root hash of `0x19ac85420cee4b5231c575ed4ab7a4bdade6c4de28ca651a406a02307f3e6ca1`.
26
+
This gives intermediate hashes of `0x083ed6aeca136c6159a761749f6db0c192bacf04294e22ed968ae1a845f97285` (`pedersen(commitment0, commitment1)`) and `0x1501e80783ee5c988327f46f5fcdce388cb97aa7e959ad345c1e2cbaa0b42b83` (`pedersen(commitment2, commitment3)`) and a root hash of `0x29fd5ee89e33f559a7b32ac39f57400aa5a6c77492e28c088f9eb511b0c73e78`.
21
27
22
28
2. Users will input their information into the circuit and generate a proof (see example inputs in [Prover.toml](./circuits/Prover.toml) and run `nargo prove` to generate the proof.)
23
29
1. Public inputs and outputs are printed in [Verifier.toml](./circuits/Verifier.toml).
30
+
2. The proof is saved to `./proofs/foundry_voting.proof`.
24
31
3. The generated proof + the contents of Verifier.toml are sent in a transaction to the `castVote` function in the [zkVote](./src/zkVote.sol) contract. The function verifies that the sender is authorized to vote on the proposal, that they haven't already voted and tallies their vote.
25
32
26
33
## Testing
@@ -29,10 +36,19 @@ You can run the Noir tests (also defined in main.nr) with `nargo test`. To print
29
36
30
37
See the test file [here](./test/zkVote.t.sol). Run tests with `forge test`.
31
38
39
+
1. Run `nargo compile` to compile the circuit.
40
+
2. Run `nargo prove` to generate the proof (with the inputs in Prover.toml).
41
+
3. Run `yarn test` to run the Foundry test the Solidity verifier contract at `./test/zkVote.t.sol`.
42
+
4. Run `yarn integration-test` to run Javascript tests (at `./test/integration.test.ts`) using [bb.js](https://www.npmjs.com/package/@aztec/bb.js).
43
+
32
44
## Development
33
45
34
46
If you change the circuit at `./circuits/src/main.nr` you will need to recompile (`nargo compile`) the circuit and regenerate the Solidity verifier (saved to `./circuits/contract/plonk_vk.sol`).
35
47
36
-
The merkle tree will need to be recalculated whenever there are users added to the set or if there are any changes to the voters private keys (private keys are an input to the merkle membership commitment, so changing a key changes the corresponding leaf in the merkle tree, which changes the root). See `test_build_merkle_tree` for an example calculation.
48
+
The merkle tree will need to be recalculated whenever there are users added to the set or if there are any changes to the voters secrets (secrets are the input to the merkle membership commitment, so changing a key changes the corresponding leaf in the merkle tree, which changes the root). See `test_valid_build_merkle_tree` for an example calculation.
37
49
38
50
Run `nargo test --show-output` in `./circuits` to print the example merkle tree.
51
+
52
+
## Contributions
53
+
54
+
Thanks to the folks at zkCamp modifying the original example and adding tests. You can see their repo [here](https://github.com/ZKCamp/noir-voting/tree/6-security).
0 commit comments