Skip to content

Commit

Permalink
Merge pull request #13 from noir-lang/critesjosh-patch-1
Browse files Browse the repository at this point in the history
Update with-foundry to use 0.22.0, remove old code
  • Loading branch information
critesjosh authored Feb 8, 2024
2 parents 7564857 + ad1e012 commit 6c6feaa
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 2,929 deletions.
4 changes: 2 additions & 2 deletions foundry-voting/circuits/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = [""]
compiler_version = "~0.10.3"
compiler_version = ">=0.22.0"
name="foundry_voting"
type="bin"

[dependencies]
[dependencies]
6 changes: 3 additions & 3 deletions foundry-voting/circuits/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
hash_path = [
"0x2d961d9814298c04a4639a56c5c95030d704340ab6d13c135a326da5e515559d",
"0x1501e80783ee5c988327f46f5fcdce388cb97aa7e959ad345c1e2cbaa0b42b83"
"0x1efa9d6bb4dfdf86063cc77efdec90eb9262079230f1898049efad264835b6c8",
"0x2a653551d87767c545a2a11b29f0581a392b4e177a87c8e3eb425c51a26a8c77"
]
index = "0"
proposalId = "0"
root = "0x29fd5ee89e33f559a7b32ac39f57400aa5a6c77492e28c088f9eb511b0c73e78"
root = "0x215597bacd9c7e977dfc170f320074155de974be494579d2586e5b268fa3b629"
secret = "1"
vote = "1"
4 changes: 2 additions & 2 deletions foundry-voting/circuits/Verifier.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
proposalId = "0x0000000000000000000000000000000000000000000000000000000000000000"
return = "0x1cbb284a43dde14da2c3790e12872bcb7e53c53e27b5187384c617841174ace5"
root = "0x29fd5ee89e33f559a7b32ac39f57400aa5a6c77492e28c088f9eb511b0c73e78"
return = "0x079d88735cdd786b64a950b1cd887ae89308e3b4176ef4adb308267888fe1f91"
root = "0x215597bacd9c7e977dfc170f320074155de974be494579d2586e5b268fa3b629"
vote = "0x0000000000000000000000000000000000000000000000000000000000000001"
2,611 changes: 0 additions & 2,611 deletions foundry-voting/circuits/contract/foundry_voting/plonk_vk.sol

This file was deleted.

1 change: 0 additions & 1 deletion foundry-voting/circuits/proofs/foundry_voting.proof

This file was deleted.

88 changes: 43 additions & 45 deletions foundry-voting/circuits/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
use dep::std;

fn main(root : pub Field, index : Field, hash_path : [Field; 2], secret: Field, proposalId: pub Field, vote: pub Field) -> pub Field {
let note_commitment = std::hash::pedersen([secret]);
let nullifier = std::hash::pedersen([root, secret, proposalId]);

let check_root = std::merkle::compute_merkle_root(note_commitment[0], index, hash_path);
fn main(
root: pub Field,
index: Field,
hash_path: [Field; 2],
secret: Field,
proposalId: pub Field,
vote: pub Field
) -> pub Field {
let note_commitment = std::hash::pedersen_hash([secret]);
let nullifier = std::hash::pedersen_hash([root, secret, proposalId]);

let check_root = std::merkle::compute_merkle_root(note_commitment, index, hash_path);
assert(root == check_root);

// Originally contrained the vote to avoid front-running,
// but including the vote as a public input is sufficient

// assert(vote <= 1);
// Originally contrained the vote to avoid front-running,
// but including the vote as a public input is sufficient

nullifier[0]
}
// assert(vote <= 1);

nullifier
}

#[test]
fn test_valid_build_merkle_tree() {
let commitment_0 = std::hash::pedersen([1])[0];
let commitment_1 = std::hash::pedersen([2])[0];
let commitment_2 = std::hash::pedersen([3])[0];
let commitment_3 = std::hash::pedersen([4])[0];
let commitment_0 = std::hash::pedersen_hash([1]);
let commitment_1 = std::hash::pedersen_hash([2]);
let commitment_2 = std::hash::pedersen_hash([3]);
let commitment_3 = std::hash::pedersen_hash([4]);

let left_branch = std::hash::pedersen([commitment_0, commitment_1])[0];
let right_branch = std::hash::pedersen([commitment_2, commitment_3])[0];
let left_branch = std::hash::pedersen_hash([commitment_0, commitment_1]);
let right_branch = std::hash::pedersen_hash([commitment_2, commitment_3]);

let root = std::hash::pedersen_hash([left_branch, right_branch]);

let root = std::hash::pedersen([left_branch, right_branch])[0];

let proposalId = 0;
let vote = 1;

let nullifier = main(
root,
0,
[commitment_1, right_branch],
1,
proposalId,
vote
);
let nullifier = main(root, 0, [commitment_1, right_branch], 1, proposalId, vote);

let expected_nullifier = std::hash::pedersen([root, 1, proposalId]);
let expected_nullifier = std::hash::pedersen_hash([root, 1, proposalId]);

std::println("Merkle Tree:");
std::println([root]);
std::println([left_branch, right_branch]);
std::println([commitment_0, commitment_1, commitment_2, commitment_3]);

assert(nullifier == expected_nullifier[0]);
assert(nullifier == expected_nullifier);
}


// fn main(root : pub Field, index : Field, hash_path : [Field; 2], secret: Field, priv_key: Field, proposalId: pub Field, vote: pub u8) -> pub Field {
// let note_commitment = std::hash::pedersen([priv_key, secret]);
// let nullifier = std::hash::pedersen([root, priv_key, proposalId]);
Expand All @@ -69,21 +67,21 @@ fn test_valid_build_merkle_tree() {
// Helpers for getting note_commitments to build the merkle tree.
// To view: nargo test --show-output

// #[test]
// fn test_build_merkle_tree() {
// let secret = 9;
// let commitment_0 = std::hash::pedersen([0, secret])[0];
// let commitment_1 = std::hash::pedersen([1, secret])[0];
// let commitment_2 = std::hash::pedersen([2, secret])[0];
// let commitment_3 = std::hash::pedersen([3, secret])[0];
#[test]
fn test_build_merkle_tree() {
let secret = 9;
let commitment_0 = std::hash::pedersen_hash([0, secret]);
let commitment_1 = std::hash::pedersen_hash([1, secret]);
let commitment_2 = std::hash::pedersen_hash([2, secret]);
let commitment_3 = std::hash::pedersen_hash([3, secret]);

// let left_branch = std::hash::pedersen([commitment_0, commitment_1])[0];
// let right_branch = std::hash::pedersen([commitment_2, commitment_3])[0];
let left_branch = std::hash::pedersen_hash([commitment_0, commitment_1]);
let right_branch = std::hash::pedersen_hash([commitment_2, commitment_3]);

// let root = std::hash::pedersen([left_branch, right_branch])[0];
let root = std::hash::pedersen_hash([left_branch, right_branch]);

// std::println("Merkle Tree:");
// std::println([root]);
// std::println([left_branch, right_branch]);
// std::println([commitment_0, commitment_1, commitment_2, commitment_3]);
// }
std::println("Merkle Tree:");
std::println([root]);
std::println([left_branch, right_branch]);
std::println([commitment_0, commitment_1, commitment_2, commitment_3]);
}
1 change: 0 additions & 1 deletion foundry-voting/circuits/target/foundry_voting.json

This file was deleted.

6 changes: 3 additions & 3 deletions foundry-voting/data/input.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"merkleRoot": "0x29fd5ee89e33f559a7b32ac39f57400aa5a6c77492e28c088f9eb511b0c73e78",
"nullifierHash": "0x1cbb284a43dde14da2c3790e12872bcb7e53c53e27b5187384c617841174ace5"
}
"merkleRoot": "0x215597bacd9c7e977dfc170f320074155de974be494579d2586e5b268fa3b629",
"nullifierHash": "0x079d88735cdd786b64a950b1cd887ae89308e3b4176ef4adb308267888fe1f91"
}
9 changes: 2 additions & 7 deletions foundry-voting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,19 @@
"test": "test"
},
"scripts": {
"test": "forge test",
"integration-test": "vitest",
"populate-prover-toml": "ts-node --esm --experimental-specifier-resolution=node ./utils/populate.ts"
"test": "forge test"
},
"author": "",
"license": "ISC",
"dependencies": {
"@aztec/bb.js": "0.3.6",
"@iarna/toml": "^2.2.5",
"@noir-lang/acvm_js": "git+https://github.com/noir-lang/acvm-simulator-wasm.git",
"@types/mocha": "^10.0.1",
"fflate": "^0.8.0",
"toml": "^3.0.0"
},
"devDependencies": {
"@typechain/ethers-v5": "^10.0.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "^17.0.35",
"chai": "^4.3.6",
"ethers": "^5.7.2",
Expand Down
95 changes: 0 additions & 95 deletions foundry-voting/test/integration.test.ts

This file was deleted.

18 changes: 4 additions & 14 deletions foundry-voting/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@
"resolveJsonModule": true,
"noImplicitAny": true,
"plugins": [],
"lib": [
"dom",
"EsNext"
]
},
"include": [
"./test/**/*"
],
"exclude": [
"node_modules",
"**/node_modules/**"
]

}
"lib": ["dom", "EsNext"]
},
"exclude": ["node_modules", "**/node_modules/**"]
}
Loading

0 comments on commit 6c6feaa

Please sign in to comment.