test(rln): merkle proof

This commit is contained in:
Oskar Thoren 2022-03-17 13:59:00 +08:00
parent ccdf1e75d7
commit 0774674c6e
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
1 changed files with 57 additions and 0 deletions

View File

@ -8,3 +8,60 @@ pub mod merkle_tree;
pub mod poseidon_tree;
pub mod public;
pub mod util;
#[cfg(test)]
mod test {
use super::*;
use hash::*;
use identity::*;
use poseidon_tree::*;
// use protocol::*;
// Adapted from https://github.com/worldcoin/semaphore-rs/blob/main/src/lib.rs
#[test]
fn test_merkle_proof() {
//fn test_end_to_end() {
// generate identity
let id = Identity::new(b"secret");
// generate merkle tree
const LEAF: Hash = Hash::from_bytes_be([0u8; 32]);
let mut tree = PoseidonTree::new(21, LEAF);
let (_, leaf) = id.commitment().to_bytes_be();
tree.set(0, leaf.into());
let merkle_proof = tree.proof(0).expect("proof should exist");
let root = tree.root();
println!("Root: {:#}", root);
println!("Merkle proof: {:#?}", merkle_proof);
// change signal and external_nullifier here
// let signal = "xxx".as_bytes();
// let external_nullifier = "appId".as_bytes();
// let external_nullifier_hash = hash_external_nullifier(external_nullifier);
// let nullifier_hash = generate_nullifier_hash(&id, &external_nullifier_hash);
// let config = SnarkFileConfig {
// zkey: "./semaphore/build/snark/semaphore_final.zkey".to_string(),
// wasm: "./semaphore/build/snark/semaphore.wasm".to_string(),
// };
// let proof =
// generate_proof(&config, &id, &merkle_proof, &external_nullifier_hash, signal).unwrap();
// let success = verify_proof(
// &config,
// &root.into(),
// &nullifier_hash,
// signal,
// &external_nullifier_hash,
// &proof,
// )
// .unwrap();
// assert!(success);
}
}