Solve merge conflicts

This commit is contained in:
Remco Bloemen 2022-03-11 11:12:44 -08:00
parent 030287e35a
commit 7859da2b22
3 changed files with 25 additions and 15 deletions

View File

@ -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

View File

@ -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| {

View File

@ -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");