-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83909b1
commit a6ac92e
Showing
7 changed files
with
7 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"debug_symbols":[{"locations":{"0":[{"span":{"start":199,"end":233},"file":0},{"span":{"start":755,"end":793},"file":23}],"1":[{"span":{"start":255,"end":307},"file":0},{"span":{"start":755,"end":793},"file":23}],"2":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":529,"end":555},"file":25},{"span":{"start":122,"end":149},"file":15}],"3":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":529,"end":555},"file":25},{"span":{"start":122,"end":149},"file":15}],"4":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":529,"end":555},"file":25},{"span":{"start":122,"end":149},"file":15}],"5":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":529,"end":555},"file":25},{"span":{"start":122,"end":149},"file":15}],"6":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":716,"end":728},"file":25}],"7":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"8":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"9":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"10":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"11":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"12":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"13":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"14":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":716,"end":728},"file":25}],"15":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"16":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"17":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"18":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"19":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"20":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"21":[{"span":{"start":331,"end":398},"file":0},{"span":{"start":821,"end":872},"file":25},{"span":{"start":755,"end":793},"file":23}],"22":[{"span":{"start":411,"end":429},"file":0}]}}],"file_map":{"0":{"source":"use dep::std;\n\nfn main(\n root: pub Field,\n index: Field,\n hash_path: [Field; 2],\n secret: Field,\n proposalId: pub Field,\n vote: pub Field\n) -> pub Field {\n let note_commitment = std::hash::pedersen_hash([secret]);\n let nullifier = std::hash::pedersen_hash([root, secret, proposalId]);\n\n let check_root = std::merkle::compute_merkle_root(note_commitment, index, hash_path);\n assert(root == check_root);\n\n // Originally contrained the vote to avoid front-running,\n // but including the vote as a public input is sufficient\n\n // assert(vote <= 1);\n\n nullifier\n}\n\n#[test]\nfn test_valid_build_merkle_tree() {\n let commitment_0 = std::hash::pedersen_hash([1]);\n let commitment_1 = std::hash::pedersen_hash([2]);\n let commitment_2 = std::hash::pedersen_hash([3]);\n let commitment_3 = std::hash::pedersen_hash([4]);\n\n let left_branch = std::hash::pedersen_hash([commitment_0, commitment_1]);\n let right_branch = std::hash::pedersen_hash([commitment_2, commitment_3]);\n\n let root = std::hash::pedersen_hash([left_branch, right_branch]);\n\n let proposalId = 0;\n let vote = 1;\n\n let nullifier = main(root, 0, [commitment_1, right_branch], 1, proposalId, vote);\n\n let expected_nullifier = std::hash::pedersen_hash([root, 1, proposalId]);\n\n std::println(\"Merkle Tree:\");\n std::println([root]);\n std::println([left_branch, right_branch]);\n std::println([commitment_0, commitment_1, commitment_2, commitment_3]);\n\n assert(nullifier == expected_nullifier);\n}\n\n// fn main(root : pub Field, index : Field, hash_path : [Field; 2], secret: Field, priv_key: Field, proposalId: pub Field, vote: pub u8) -> pub Field {\n// let note_commitment = std::hash::pedersen([priv_key, secret]);\n// let nullifier = std::hash::pedersen([root, priv_key, proposalId]);\n\n// let check_root = std::merkle::compute_merkle_root(note_commitment[0], index, hash_path);\n// assert(root == check_root);\n\n// // Originally contrained the vote to avoid front-running,\n// // but including the vote as a public input is sufficient\n\n// assert(vote <= 1);\n\n// nullifier[0]\n// }\n\n// Helpers for getting note_commitments to build the merkle tree.\n// To view: nargo test --show-output\n\n#[test]\nfn test_build_merkle_tree() {\n let secret = 9;\n let commitment_0 = std::hash::pedersen_hash([0, secret]);\n let commitment_1 = std::hash::pedersen_hash([1, secret]);\n let commitment_2 = std::hash::pedersen_hash([2, secret]);\n let commitment_3 = std::hash::pedersen_hash([3, secret]);\n\n let left_branch = std::hash::pedersen_hash([commitment_0, commitment_1]);\n let right_branch = std::hash::pedersen_hash([commitment_2, commitment_3]);\n\n let root = std::hash::pedersen_hash([left_branch, right_branch]);\n\n std::println(\"Merkle Tree:\");\n std::println([root]);\n std::println([left_branch, right_branch]);\n std::println([commitment_0, commitment_1, commitment_2, commitment_3]);\n}\n","path":"/home/josh/Documents/Github/noir-examples/foundry-voting/circuits/src/main.nr"},"15":{"source":"impl Field {\n pub fn to_le_bits(self: Self, bit_size: u32) -> [u1] {\n crate::assert_constant(bit_size);\n self.__to_le_bits(bit_size)\n }\n \n pub fn to_be_bits(self: Self, bit_size: u32) -> [u1] {\n crate::assert_constant(bit_size);\n self.__to_be_bits(bit_size)\n }\n\n #[builtin(to_le_bits)]\n fn __to_le_bits(_self: Self, _bit_size: u32) -> [u1] {}\n \n #[builtin(to_be_bits)]\n fn __to_be_bits(_self: Self, _bit_size: u32) -> [u1] {}\n\n pub fn to_le_bytes(self: Self, byte_size: u32) -> [u8] {\n self.to_le_radix(256, byte_size)\n }\n\n pub fn to_be_bytes(self: Self, byte_size: u32) -> [u8] {\n self.to_be_radix(256, byte_size)\n }\n\n\n pub fn to_le_radix(self: Self, radix: u32, result_len: u32) -> [u8] {\n crate::assert_constant(radix);\n crate::assert_constant(result_len);\n self.__to_le_radix(radix, result_len)\n }\n\n pub fn to_be_radix(self: Self, radix: u32, result_len: u32) -> [u8] {\n crate::assert_constant(radix);\n crate::assert_constant(result_len);\n self.__to_be_radix(radix, result_len)\n }\n\n\n\n // decompose `_self` into a `_result_len` vector over the `_radix` basis\n // `_radix` must be less than 256\n #[builtin(to_le_radix)]\n fn __to_le_radix(_self: Self, _radix: u32, _result_len: u32) -> [u8] {}\n \n #[builtin(to_be_radix)]\n fn __to_be_radix(_self: Self, _radix: u32, _result_len: u32) -> [u8] {}\n\n\n // Returns self to the power of the given exponent value.\n // Caution: we assume the exponent fits into 32 bits\n // using a bigger bit size impacts negatively the performance and should be done only if the exponent does not fit in 32 bits\n pub fn pow_32(self, exponent: Field) -> Field {\n let mut r: Field = 1;\n let b = exponent.to_le_bits(32);\n\n for i in 1..33 {\n r *= r;\n r = (b[32-i] as Field) * (r * self) + (1 - b[32-i] as Field) * r;\n }\n r\n }\n\n // Parity of (prime) Field element, i.e. sgn0(x mod p) = 0 if x ∈ {0, ..., p-1} is even, otherwise sgn0(x mod p) = 1.\n pub fn sgn0(self) -> u1 {\n self as u1\n }\n}\n\n#[builtin(modulus_num_bits)]\npub fn modulus_num_bits() -> Field {}\n\n#[builtin(modulus_be_bits)]\npub fn modulus_be_bits() -> [u1] {}\n\n#[builtin(modulus_le_bits)]\npub fn modulus_le_bits() -> [u1] {}\n\n#[builtin(modulus_be_bytes)]\npub fn modulus_be_bytes() -> [u8] {}\n\n#[builtin(modulus_le_bytes)]\npub fn modulus_le_bytes() -> [u8] {}\n// Convert a 32 byte array to a field element\npub fn bytes32_to_field(bytes32: [u8; 32]) -> Field {\n // Convert it to a field element\n let mut v = 1;\n let mut high = 0 as Field;\n let mut low = 0 as Field;\n\n for i in 0..16 {\n high = high + (bytes32[15 - i] as Field) * v;\n low = low + (bytes32[16 + 15 - i] as Field) * v;\n v = v * 256;\n }\n // Abuse that a % p + b % p = (a + b) % p and that low < p\n low + high * v\n}\n","path":"std/field.nr"},"23":{"source":"mod poseidon;\nmod mimc;\n\n#[foreign(sha256)]\npub fn sha256<N>(_input: [u8; N]) -> [u8; 32] {}\n\n#[foreign(blake2s)]\npub fn blake2s<N>(_input: [u8; N]) -> [u8; 32] {}\n\nstruct PedersenPoint {\n x : Field,\n y : Field,\n}\n\npub fn pedersen_commitment<N>(input: [Field; N]) -> PedersenPoint {\n pedersen_commitment_with_separator(input, 0)\n}\n\n#[foreign(pedersen_commitment)]\npub fn __pedersen_commitment_with_separator<N>(_input: [Field; N], _separator: u32) -> [Field; 2] {}\n\npub fn pedersen_commitment_with_separator<N>(input: [Field; N], separator: u32) -> PedersenPoint {\n let values = __pedersen_commitment_with_separator(input, separator);\n PedersenPoint { x: values[0], y: values[1] }\n}\n\npub fn pedersen_hash<N>(input: [Field; N]) -> Field {\n pedersen_hash_with_separator(input, 0)\n}\n\n#[foreign(pedersen_hash)]\npub fn pedersen_hash_with_separator<N>(_input: [Field; N], _separator: u32) -> Field {}\n\npub fn hash_to_field<N>(_input: [Field; N]) -> Field {\n let mut inputs_as_bytes = [];\n\n for i in 0..N {\n let input_bytes = _input[i].to_le_bytes(32);\n for i in 0..32 {\n inputs_as_bytes = inputs_as_bytes.push_back(input_bytes[i]);\n }\n }\n\n let hashed_input = blake2s(inputs_as_bytes);\n crate::field::bytes32_to_field(hashed_input)\n}\n\n#[foreign(keccak256)]\npub fn keccak256<N>(_input: [u8; N], _message_size: u32) -> [u8; 32] {}\n\n","path":"std/hash.nr"},"25":{"source":"// Regular merkle tree means a append-only merkle tree (Explain why this is the only way to have privacy and alternatives if you don't want it)\n// Currently we assume that it is a binary tree, so depth k implies a width of 2^k\n// XXX: In the future we can add an arity parameter\n// Returns the merkle root of the tree from the provided leaf, its hashpath, using a pedersen hash function.\npub fn compute_merkle_root<N>(leaf: Field, index: Field, hash_path: [Field; N]) -> Field {\n let n = hash_path.len();\n let index_bits = index.to_le_bits(n as u32);\n let mut current = leaf;\n for i in 0..n {\n let path_bit = index_bits[i] as bool;\n let (hash_left, hash_right) = if path_bit {\n (hash_path[i], current)\n } else {\n (current, hash_path[i])\n };\n current = crate::hash::pedersen_hash([hash_left, hash_right]);\n }\n current\n}\n","path":"std/merkle.nr"}},"warnings":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"root","type":{"kind":"field"},"visibility":"public"},{"name":"index","type":{"kind":"field"},"visibility":"private"},{"name":"hash_path","type":{"kind":"array","length":2,"type":{"kind":"field"}},"visibility":"private"},{"name":"secret","type":{"kind":"field"},"visibility":"private"},{"name":"proposalId","type":{"kind":"field"},"visibility":"public"},{"name":"vote","type":{"kind":"field"},"visibility":"public"}],"param_witnesses":{"hash_path":[3,4],"index":[2],"proposalId":[6],"root":[1],"secret":[5],"vote":[7]},"return_type":{"kind":"field"},"return_witnesses":[10]},"bytecode":"H4sIAAAAAAAA/9VZbU/CMBC+bYBvGwiCIBJMNNFEY9KyDbpv/hWJ4///AmMbrqGb+8bTZGtyubKUa5/netfb+klEazq2PuuQdaSlpyXQMmBtx/1y/1LLlTMm4ucBj7FjB85/rrXc8Dx2LnLsf7EW5zUZ4mwJu85YS8LrDljH3Le/EwcLOVz6wpaKbZaVu00pU/ktNsVe5SLL91sllcxV/rNRaVqqTO2KfbEThczSUh7yIj2wsRhgqzwcWwLk3OUvrPHXBszW1hDo165gHoExo2PfxFvcYPdc3GvC7m80bpOPhx5wP5GfuI7A67wFcgn0tUTz5yNeRh72zXMH4sVHnnihbsTLGMgl0NcSyZ+tTe15anKEqUXHdKpJJ1ruqNrQ528CtDWlbtQcSMwzanfNYd6VEsLnkldqdw41sTP1gPuNupFD74FcAn0t0fz5iJeZh33z3nLcJkdMPOD+oG7EyxzIJdDXEslfveYwOcLUGnM61RwLLQ9UbejvRAHQbwugrSUOo4jo//c2InzcItfsrvfR6fdYhw17YuABE9XmqfM4bHjW6iJsyYSi7a4It/l94V7hfVQ5CNrMqRs49uKiT9ULCRNAFw4OcxHxB5AbxdoBGQAA","proving_key":null,"verification_key":null} | ||
{"noir_version":"0.22.0+3fae4a03fded4e3f5065e7461c563f7e39745604","hash":14491308408831426258,"abi":{"parameters":[{"name":"root","type":{"kind":"field"},"visibility":"public"},{"name":"index","type":{"kind":"field"},"visibility":"private"},{"name":"hash_path","type":{"kind":"array","length":2,"type":{"kind":"field"}},"visibility":"private"},{"name":"secret","type":{"kind":"field"},"visibility":"private"},{"name":"proposalId","type":{"kind":"field"},"visibility":"public"},{"name":"vote","type":{"kind":"field"},"visibility":"public"}],"param_witnesses":{"hash_path":[{"start":3,"end":5}],"index":[{"start":2,"end":3}],"proposalId":[{"start":6,"end":7}],"root":[{"start":1,"end":2}],"secret":[{"start":5,"end":6}],"vote":[{"start":7,"end":8}]},"return_type":{"abi_type":{"kind":"field"},"visibility":"public"},"return_witnesses":[9]},"bytecode":"H4sIAAAAAAAA/9VYbW6DMAx16cdW6Nqu3bRN2qROu0BCoIR/u8rQ4P4nqIrVoAZ+lucKLEUEET3iZ/s5yg8RvdHFJvV4cE+2eT1Obv7ofZ9660/euoW3flmPwMMib/7rnqqf6QCHpQKHE9YjcnuX2HPo/tHFNeqYJGUWl9roPxXnhU1VkhZHq61ObfofW2NKm9gsL/JM5Toxpa7S3FQOOARyIeF35HhF+x2B/W5sKpiryFjfilVWF5PiLxDM775YK2BcJWqFc09CI15o2BrBPWYl4Pcr3Ucj+u7zCcglMNYazZ9EvUjkzfsI6kVCJz5oHPWyBnIJjLVG8tecuZt+yhrBZ+w1Xc/aG2obuvdGQKwtDbv3zkjmnPpJw9YSzqGtgN9fNA4teQZyCYy1RvMnUS8SeXMYuN+sERsBv79pHPWyA3J5AGIh+ev2XtYI7rk7uvbePbWt23tVP9MTYMz2QG5mnr+cW/w+p/bd4ILa94lLj6czaflhJ3gUAAA="} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.