From 7859da2b22c41d0c674a8175dfd699d546c1e0dc Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Fri, 11 Mar 2022 11:12:44 -0800 Subject: [PATCH] Solve merge conflicts --- README.md | 5 +++-- src/lib.rs | 19 ++++++++++++++----- src/protocol.rs | 16 ++++++++-------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f08fdb7..eab3d35 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Rust support library for using [semaphore](https://github.com/appliedzkp/semapho ## Usage Add this line to your `cargo.toml`: -``` + +```toml semaphore = { git = "https://github.com/worldcoin/semaphore-rs" } ``` @@ -13,7 +14,7 @@ semaphore = { git = "https://github.com/worldcoin/semaphore-rs" } 1. Check out submodule (if not done before already): `git submodule update --init --recursive` 1. Install semaphore dependencies `cd semaphore && npm install` -1. Compile circuits `ts-node ./scripts/compile-circuits.ts` +1. Compile circuits `npm exec ts-node ./scripts/compile-circuits.ts` 1. You'll find the `zkey` and `wasm` file in `semaphore/build/snark` ## Example diff --git a/src/lib.rs b/src/lib.rs index fff3375..02c5bdd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,10 @@ mod test { hash::Hash, identity::Identity, poseidon_tree::PoseidonTree, - protocol::{generate_nullifier_hash, generate_proof, verify_proof, SnarkFileConfig}, + protocol::{ + generate_nullifier_hash, generate_proof, hash_external_nullifier, verify_proof, + SnarkFileConfig, + }, }; use hex_literal::hex; @@ -60,8 +63,14 @@ mod test { wasm: "./semaphore/build/snark/semaphore.wasm".to_string(), }; - let proof = - generate_proof(&config, &id, &merkle_proof, &external_nullifier_hash, signal).unwrap(); + let proof = generate_proof( + &config, + &id, + &merkle_proof, + &external_nullifier_hash, + signal, + ) + .unwrap(); let success = verify_proof( &config, @@ -113,8 +122,8 @@ pub mod bench { let external_nullifier = b"appId"; let config = SnarkFileConfig { - zkey: "./snarkfiles/semaphore.zkey".to_string(), - wasm: "./snarkfiles/semaphore.wasm".to_string(), + zkey: "./semaphore/build/snark/semaphore_final.zkey".to_string(), + wasm: "./semaphore/build/snark/semaphore.wasm".to_string(), }; criterion.bench_function("proof", move |b| { diff --git a/src/protocol.rs b/src/protocol.rs index c692745..f9e823c 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -46,10 +46,13 @@ fn hash_signal(signal: &[u8]) -> BigInt { /// Internal helper to hash the external nullifier #[must_use] -pub fn hash_external_nullifier(nullifier: &[u8]) -> BigInt { - let mut hash = keccak256(nullifier).to_vec(); - hash.splice(..3, vec![0; 4]); - BigInt::from_bytes_be(Sign::Plus, &hash) +pub fn hash_external_nullifier(nullifier: &[u8]) -> [u8; 32] { + let mut hash = keccak256(nullifier); + hash[0] = 0; + hash[1] = 0; + hash[2] = 0; + hash[3] = 0; + hash } /// Generates the nullifier hash @@ -57,10 +60,7 @@ pub fn hash_external_nullifier(nullifier: &[u8]) -> BigInt { pub fn generate_nullifier_hash(identity: &Identity, external_nullifier: &[u8]) -> BigInt { let res = POSEIDON .hash(vec![ - bigint_to_fr(&BigInt::from_bytes_be( - Sign::Plus, - external_nullifier, - )), + bigint_to_fr(&BigInt::from_bytes_be(Sign::Plus, external_nullifier)), bigint_to_fr(&identity.nullifier), ]) .expect("hash with fixed input size can't fail");