Skip to content

Instantly share code, notes, and snippets.

@critesjosh
Created May 9, 2023 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save critesjosh/99c5893fb1399b13ff6301f33a513856 to your computer and use it in GitHub Desktop.
Save critesjosh/99c5893fb1399b13ff6301f33a513856 to your computer and use it in GitHub Desktop.
simple zk voting circuit for noir. to be used with https://gist.github.com/critesjosh/bfddfdab1c9e7f4eb5cec57105526508
// https://gist.github.com/Turupawn/12cefea88476ce556d01d15705efcd70
/*
Try with these iputs in Prover.toml
hash_path = ["0x2fbbcae1f6072bd17986e7d705a1a92a634d698f94620b8c5170c470be747d0b", "0x244156862f17c9aa11c1d39da925e4d9e03505e3836804c6774f0a4049ec6eac"]
index = "0"
priv_key = "1"
proposalId = "0"
root = "0x02b54b6daa0b81c12a9d75f44d39e52dcbfa2ef2ab04dbe9159559a547a9ae82"
secret = "9"
vote = "1"
*/
use dep::std;
fn main(root : pub Field, index : Field, hash_path : [Field; 2], secret: Field, priv_key: Field, proposalId: pub Field, vote: pub Field) -> pub Field {
constrain index == index;
let pubkey = std::scalar_mul::fixed_base(priv_key);
let pubkey_x = pubkey[0];
let pubkey_y = pubkey[1];
let note_commitment = std::hash::pedersen([pubkey_x, pubkey_y, secret]);
let nullifier = std::hash::pedersen([root, priv_key, proposalId, vote]);
let is_member = std::merkle::check_membership(root, note_commitment[0], index, hash_path);
constrain is_member == 1;
nullifier[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment