Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update foundry voting to 0.28 #20

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion foundry-voting/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ docs/
.env

node_modules
crs
crs

circuits/contract
circuits/proofs
22 changes: 11 additions & 11 deletions foundry-voting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

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.

This example was last tested with Noir version 0.22.0. You can install it with [noirup](https://noir-lang.org/docs/getting_started/installation/#installing-noirup) using
This example was last tested with Noir version 0.28.0. You can install it with [noirup](https://noir-lang.org/docs/getting_started/installation/#installing-noirup) using

```bash
noirup -v 0.22.0
noirup -v 0.28.0
```

## Overview
Expand All @@ -16,14 +16,14 @@ This is the model used for creating the [circuit](circuits/src/main.nr) and the

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.

| Secret | Commitment = pedersen(secret) |
| ------ | ------------------------------------------------------------------ |
| 1 | 0x09489945604c9686e698cb69d7bd6fc0cdb02e9faae3e1a433f1c342c1a5ecc4 |
| 2 | 0x2d961d9814298c04a4639a56c5c95030d704340ab6d13c135a326da5e515559d |
| 3 | 0x0a1d1f62bdd17dbdd447feccd23471821e7e43f1ce9165f636513b83a9933474 |
| 4 | 0x273e0772e851cd0d83d77f05f334d156bc53194e42e8680c6d9469b3aa887eb1 |
| Private Key | Commitment = pedersen(private key, secret) |
| ----------- | ------------------------------------------------------------------ |
| 1 | 0x03542cb720369f19a74fd05b4edfbedb27a78514ad3283f1b3270a1656cced8e |
| 2 | 0x1efa9d6bb4dfdf86063cc77efdec90eb9262079230f1898049efad264835b6c8 |
| 3 | 0x24013340c052ebf847e0d7081f84e6a8e92f54e2e1726a1e559ac46a8f242007 |
| 4 | 0x04fd3da9756f25c72ca8990437b7f7b58e7ca48bfc21e65e7978320db8b1e5c5 |

This gives intermediate hashes of `0x083ed6aeca136c6159a761749f6db0c192bacf04294e22ed968ae1a845f97285` (`pedersen(commitment0, commitment1)`) and `0x1501e80783ee5c988327f46f5fcdce388cb97aa7e959ad345c1e2cbaa0b42b83` (`pedersen(commitment2, commitment3)`) and a root hash of `0x29fd5ee89e33f559a7b32ac39f57400aa5a6c77492e28c088f9eb511b0c73e78`.
This gives intermediate hashes of `0x046394ae1ebbf494f2cd2c2d37171099510d099489c9accef59f90512d5f0477` (`pedersen(commitment0, commitment1)`) and `0x2a653551d87767c545a2a11b29f0581a392b4e177a87c8e3eb425c51a26a8c77` (`pedersen(commitment2, commitment3)`) and a root hash of `0x215597bacd9c7e977dfc170f320074155de974be494579d2586e5b268fa3b629`.

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.)
1. Public inputs and outputs are printed in [Verifier.toml](./circuits/Verifier.toml).
Expand All @@ -38,8 +38,8 @@ See the test file [here](./test/zkVote.t.sol). Run tests with `forge test`.

1. Run `nargo compile` to compile the circuit.
2. Run `nargo prove` to generate the proof (with the inputs in Prover.toml).
3. Run `yarn test` to run the Foundry test the Solidity verifier contract at `./test/zkVote.t.sol`.
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).
3. Run `nargo codegen-verifier` to generate the solidity verifier contract.
4. Run `yarn test` to run the Foundry test the Solidity verifier contract at `./test/zkVote.t.sol`.

## Development

Expand Down
4 changes: 2 additions & 2 deletions foundry-voting/test/zkVote.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract VotingTest is Test {
}

function test_invalidProof() public {
vm.expectRevert(BaseUltraVerifier.EC_SCALAR_MUL_FAILURE.selector);
vm.expectRevert();
voteContract.castVote(hex"12", 0, 1, nullifierHash);
}

Expand All @@ -54,7 +54,7 @@ contract VotingTest is Test {
}

function test_changedVote() public {
vm.expectRevert(BaseUltraVerifier.PROOF_FAILURE.selector);
vm.expectRevert();

voteContract.castVote(proofBytes, 0, 0, nullifierHash);
}
Expand Down
Loading