diff --git a/rln-cli/README.md b/rln-cli/README.md index 4cf2971..8289e17 100644 --- a/rln-cli/README.md +++ b/rln-cli/README.md @@ -37,9 +37,9 @@ You can run the example using the following command: cargo run --example relay ``` -You can also change **MESSAGE_LIMIT** and **TREEE_HEIGHT** in the [relay.rs](src/examples/relay.rs) file to see how the RLN instance behaves with different parameters. +You can also change **MESSAGE_LIMIT** and **TREE_DEPTH** in the [relay.rs](src/examples/relay.rs) file to see how the RLN instance behaves with different parameters. -The customize **TREEE_HEIGHT** constant differs from the default value of `20` should follow [Custom Circuit Compilation](../rln/README.md#advanced-custom-circuit-compilation) instructions. +The customize **TREE_DEPTH** constant differs from the default value of `20` should follow [Custom Circuit Compilation](../rln/README.md#advanced-custom-circuit-compilation) instructions. ## Stateless Example @@ -60,19 +60,19 @@ cargo run --example stateless --no-default-features --features stateless To initialize a new RLN instance: ```bash -cargo run new --tree-height +cargo run new --tree-depth ``` To initialize an RLN instance with custom parameters: ```bash -cargo run new-with-params --resources-path --tree-height +cargo run new-with-params --resources-path --tree-depth ``` -To update the Merkle tree height: +To update the Merkle tree depth: ```bash -cargo run set-tree --tree-height +cargo run set-tree --tree-depth ``` ### Leaf Operations diff --git a/rln-cli/example.config.json b/rln-cli/example.config.json index 472eba5..e81aa1a 100644 --- a/rln-cli/example.config.json +++ b/rln-cli/example.config.json @@ -7,5 +7,5 @@ "mode": "HighThroughput", "use_compression": false }, - "tree_height": 20 + "tree_depth": 20 } diff --git a/rln-cli/src/commands.rs b/rln-cli/src/commands.rs index 1b48c64..d18ca1e 100644 --- a/rln-cli/src/commands.rs +++ b/rln-cli/src/commands.rs @@ -1,23 +1,23 @@ use std::path::PathBuf; use clap::Subcommand; -use rln::circuit::TEST_TREE_HEIGHT; +use rln::circuit::TEST_TREE_DEPTH; #[derive(Subcommand)] pub(crate) enum Commands { New { - #[arg(short, long, default_value_t = TEST_TREE_HEIGHT)] - tree_height: usize, + #[arg(short, long, default_value_t = TEST_TREE_DEPTH)] + tree_depth: usize, }, NewWithParams { - #[arg(short, long, default_value_t = TEST_TREE_HEIGHT)] - tree_height: usize, - #[arg(short, long, default_value = "../rln/resources/tree_height_20")] + #[arg(short, long, default_value_t = TEST_TREE_DEPTH)] + tree_depth: usize, + #[arg(short, long, default_value = "../rln/resources/tree_depth_20")] resources_path: PathBuf, }, SetTree { - #[arg(short, long, default_value_t = TEST_TREE_HEIGHT)] - tree_height: usize, + #[arg(short, long, default_value_t = TEST_TREE_DEPTH)] + tree_depth: usize, }, SetLeaf { #[arg(short, long)] diff --git a/rln-cli/src/config.rs b/rln-cli/src/config.rs index 92befa4..b97ca7a 100644 --- a/rln-cli/src/config.rs +++ b/rln-cli/src/config.rs @@ -13,7 +13,7 @@ pub(crate) struct Config { #[derive(Default, Serialize, Deserialize)] pub(crate) struct InnerConfig { - pub tree_height: usize, + pub tree_depth: usize, pub tree_config: Value, } diff --git a/rln-cli/src/examples/relay.rs b/rln-cli/src/examples/relay.rs index 566e5c6..2c70673 100644 --- a/rln-cli/src/examples/relay.rs +++ b/rln-cli/src/examples/relay.rs @@ -17,7 +17,7 @@ use rln::{ const MESSAGE_LIMIT: u32 = 1; -const TREEE_HEIGHT: usize = 20; +const TREE_DEPTH: usize = 20; #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -67,7 +67,7 @@ struct RLNSystem { impl RLNSystem { fn new() -> Result { let mut resources: Vec> = Vec::new(); - let resources_path: PathBuf = format!("../rln/resources/tree_height_{TREEE_HEIGHT}").into(); + let resources_path: PathBuf = format!("../rln/resources/tree_depth_{TREE_DEPTH}").into(); let filenames = ["rln_final.arkzkey", "graph.bin"]; for filename in filenames { let fullpath = resources_path.join(Path::new(filename)); @@ -78,7 +78,7 @@ impl RLNSystem { resources.push(output_buffer); } let rln = RLN::new_with_params( - TREEE_HEIGHT, + TREE_DEPTH, resources[0].clone(), resources[1].clone(), generate_input_buffer(), @@ -120,7 +120,7 @@ impl RLNSystem { self.local_identities.insert(index, identity); } Err(_) => { - println!("Maximum user limit reached: 2^{TREEE_HEIGHT}"); + println!("Maximum user limit reached: 2^{TREE_DEPTH}"); } }; diff --git a/rln-cli/src/examples/stateless.rs b/rln-cli/src/examples/stateless.rs index 738c743..aebcea3 100644 --- a/rln-cli/src/examples/stateless.rs +++ b/rln-cli/src/examples/stateless.rs @@ -8,7 +8,7 @@ use std::{ use clap::{Parser, Subcommand}; use color_eyre::{eyre::eyre, Result}; use rln::{ - circuit::{Fr, TEST_TREE_HEIGHT}, + circuit::{Fr, TEST_TREE_DEPTH}, hashers::{hash_to_field_le, poseidon_hash, PoseidonHash}, protocol::{keygen, prepare_verify_input, rln_witness_from_values, serialize_witness}, public::RLN, @@ -71,7 +71,7 @@ impl RLNSystem { let rln = RLN::new()?; let default_leaf = Fr::from(0); let tree: OptimalMerkleTree = OptimalMerkleTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::>::default(), ) diff --git a/rln-cli/src/main.rs b/rln-cli/src/main.rs index dd4d551..998935c 100644 --- a/rln-cli/src/main.rs +++ b/rln-cli/src/main.rs @@ -35,19 +35,19 @@ fn main() -> Result<()> { }; match cli.command { - Some(Commands::New { tree_height }) => { + Some(Commands::New { tree_depth }) => { let config = Config::load_config()?; - state.rln = if let Some(InnerConfig { tree_height, .. }) = config.inner { + state.rln = if let Some(InnerConfig { tree_depth, .. }) = config.inner { println!("Initializing RLN with custom config"); - Some(RLN::new(tree_height, Cursor::new(config.as_bytes()))?) + Some(RLN::new(tree_depth, Cursor::new(config.as_bytes()))?) } else { println!("Initializing RLN with default config"); - Some(RLN::new(tree_height, Cursor::new(json!({}).to_string()))?) + Some(RLN::new(tree_depth, Cursor::new(json!({}).to_string()))?) }; Ok(()) } Some(Commands::NewWithParams { - tree_height, + tree_depth, resources_path, }) => { let mut resources: Vec> = Vec::new(); @@ -62,13 +62,13 @@ fn main() -> Result<()> { } let config = Config::load_config()?; if let Some(InnerConfig { - tree_height, + tree_depth, tree_config, }) = config.inner { println!("Initializing RLN with custom config"); state.rln = Some(RLN::new_with_params( - tree_height, + tree_depth, resources[0].clone(), resources[1].clone(), Cursor::new(tree_config.to_string().as_bytes()), @@ -76,7 +76,7 @@ fn main() -> Result<()> { } else { println!("Initializing RLN with default config"); state.rln = Some(RLN::new_with_params( - tree_height, + tree_depth, resources[0].clone(), resources[1].clone(), Cursor::new(json!({}).to_string()), @@ -84,11 +84,11 @@ fn main() -> Result<()> { }; Ok(()) } - Some(Commands::SetTree { tree_height }) => { + Some(Commands::SetTree { tree_depth }) => { state .rln .ok_or(Report::msg("no RLN instance initialized"))? - .set_tree(tree_height)?; + .set_tree(tree_depth)?; Ok(()) } Some(Commands::SetLeaf { index, input }) => { diff --git a/rln-cli/src/state.rs b/rln-cli/src/state.rs index 15e5c15..c984b0c 100644 --- a/rln-cli/src/state.rs +++ b/rln-cli/src/state.rs @@ -13,8 +13,8 @@ pub(crate) struct State { impl State { pub(crate) fn load_state() -> Result { let config = Config::load_config()?; - let rln = if let Some(InnerConfig { tree_height, .. }) = config.inner { - Some(RLN::new(tree_height, Cursor::new(config.as_bytes()))?) + let rln = if let Some(InnerConfig { tree_depth, .. }) = config.inner { + Some(RLN::new(tree_depth, Cursor::new(config.as_bytes()))?) } else { None }; diff --git a/rln-wasm/tests/browser.rs b/rln-wasm/tests/browser.rs index 2c07644..4ec16ee 100644 --- a/rln-wasm/tests/browser.rs +++ b/rln-wasm/tests/browser.rs @@ -3,7 +3,7 @@ #[cfg(test)] mod tests { use js_sys::{BigInt as JsBigInt, Date, Object, Uint8Array}; - use rln::circuit::{Fr, TEST_TREE_HEIGHT}; + use rln::circuit::{Fr, TEST_TREE_DEPTH}; use rln::hashers::{hash_to_field_le, poseidon_hash, PoseidonHash}; use rln::protocol::{prepare_verify_input, rln_witness_from_values, serialize_witness}; use rln::utils::{bytes_le_to_fr, fr_to_bytes_le, IdSecret}; @@ -75,9 +75,9 @@ mod tests { const WITNESS_CALCULATOR_JS: &str = include_str!("../resources/witness_calculator.js"); const ARKZKEY_BYTES: &[u8] = - include_bytes!("../../rln/resources/tree_height_20/rln_final.arkzkey"); + include_bytes!("../../rln/resources/tree_depth_20/rln_final.arkzkey"); - const CIRCOM_BYTES: &[u8] = include_bytes!("../../rln/resources/tree_height_20/rln.wasm"); + const CIRCOM_BYTES: &[u8] = include_bytes!("../../rln/resources/tree_depth_20/rln.wasm"); wasm_bindgen_test_configure!(run_in_browser); @@ -117,7 +117,7 @@ mod tests { // Create RLN instance for other benchmarks let rln_instance = wasm_new(zkey).expect("Failed to create RLN instance"); let mut tree: OptimalMerkleTree = - OptimalMerkleTree::default(TEST_TREE_HEIGHT).expect("Failed to create tree"); + OptimalMerkleTree::default(TEST_TREE_DEPTH).expect("Failed to create tree"); // Benchmark wasm_key_gen let start_wasm_key_gen = Date::now(); diff --git a/rln-wasm/tests/node.rs b/rln-wasm/tests/node.rs index 8e26c98..85ffaa6 100644 --- a/rln-wasm/tests/node.rs +++ b/rln-wasm/tests/node.rs @@ -4,7 +4,7 @@ #[cfg(test)] mod tests { use js_sys::{BigInt as JsBigInt, Date, Object, Uint8Array}; - use rln::circuit::{Fr, TEST_TREE_HEIGHT}; + use rln::circuit::{Fr, TEST_TREE_DEPTH}; use rln::hashers::{hash_to_field_le, poseidon_hash, PoseidonHash}; use rln::protocol::{prepare_verify_input, rln_witness_from_values, serialize_witness}; use rln::utils::{bytes_le_to_fr, fr_to_bytes_le, IdSecret}; @@ -73,9 +73,9 @@ mod tests { async fn calculateWitness(circom_path: &str, input: Object) -> Result; } - const ARKZKEY_PATH: &str = "../rln/resources/tree_height_20/rln_final.arkzkey"; + const ARKZKEY_PATH: &str = "../rln/resources/tree_depth_20/rln_final.arkzkey"; - const CIRCOM_PATH: &str = "../rln/resources/tree_height_20/rln.wasm"; + const CIRCOM_PATH: &str = "../rln/resources/tree_depth_20/rln.wasm"; #[wasm_bindgen_test] pub async fn rln_wasm_benchmark() { @@ -98,7 +98,7 @@ mod tests { // Create RLN instance for other benchmarks let rln_instance = wasm_new(zkey).expect("Failed to create RLN instance"); let mut tree: OptimalMerkleTree = - OptimalMerkleTree::default(TEST_TREE_HEIGHT).expect("Failed to create tree"); + OptimalMerkleTree::default(TEST_TREE_DEPTH).expect("Failed to create tree"); // Benchmark wasm_key_gen let start_wasm_key_gen = Date::now(); diff --git a/rln/Cargo.toml b/rln/Cargo.toml index a69f766..2b1b314 100644 --- a/rln/Cargo.toml +++ b/rln/Cargo.toml @@ -67,10 +67,9 @@ parallel = [ "ark-groth16/parallel", "ark-serialize/parallel", ] -fullmerkletree = [] -optimalmerkletree = [] -# Note: pmtree feature is still experimental -pmtree-ft = ["utils/pmtree-ft"] +fullmerkletree = [] # Pre-allocated tree, fastest access +optimalmerkletree = [] # Sparse storage, memory efficient +pmtree-ft = ["utils/pmtree-ft"] # Persistent storage, disk-based [[bench]] name = "pmtree_benchmark" diff --git a/rln/README.md b/rln/README.md index a38b27a..88d1f54 100644 --- a/rln/README.md +++ b/rln/README.md @@ -53,11 +53,11 @@ use serde_json::json; fn main() { // 1. Initialize RLN with parameters: - // - the tree height; + // - the tree depth; // - the tree config, if it is not defined, the default value will be set - let tree_height = 20; + let tree_depth = 20; let input = Cursor::new(json!({}).to_string()); - let mut rln = RLN::new(tree_height, input).unwrap(); + let mut rln = RLN::new(tree_depth, input).unwrap(); // 2. Generate an identity keypair let (identity_secret_hash, id_commitment) = keygen(); @@ -141,6 +141,10 @@ for one application to be re-used in another one. - Browser and Node.js compatibility - Optional parallel feature support using [wasm-bindgen-rayon](https://github.com/RReverser/wasm-bindgen-rayon) - Headless browser testing capabilities +- **Merkle Tree Implementations**: Multiple tree variants optimized for different use cases: + - **Full Merkle Tree**: Fastest access with complete pre-allocated tree in memory. Best for frequent random access (enable with `fullmerkletree` feature). + - **Optimal Merkle Tree**: Memory-efficient sparse storage using HashMap. Ideal for partially populated trees (enable with `optimalmerkletree` feature). + - **Persistent Merkle Tree**: Disk-based storage with [sled](https://github.com/spacejam/sled) for persistence across application restarts and large datasets (enable with `pmtree-ft` feature). ## Building and Testing diff --git a/rln/benches/poseidon_tree_benchmark.rs b/rln/benches/poseidon_tree_benchmark.rs index 2731982..6d79827 100644 --- a/rln/benches/poseidon_tree_benchmark.rs +++ b/rln/benches/poseidon_tree_benchmark.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use rln::{ - circuit::{Fr, TEST_TREE_HEIGHT}, + circuit::{Fr, TEST_TREE_DEPTH}, hashers::PoseidonHash, }; use utils::{FullMerkleTree, OptimalMerkleTree, ZerokitMerkleTree}; @@ -10,9 +10,9 @@ pub fn get_leaves(n: u32) -> Vec { } pub fn optimal_merkle_tree_poseidon_benchmark(c: &mut Criterion) { - c.bench_function("OptimalMerkleTree::::full_height_gen", |b| { + c.bench_function("OptimalMerkleTree::::full_depth_gen", |b| { b.iter(|| { - OptimalMerkleTree::::default(TEST_TREE_HEIGHT).unwrap(); + OptimalMerkleTree::::default(TEST_TREE_DEPTH).unwrap(); }) }); @@ -20,7 +20,7 @@ pub fn optimal_merkle_tree_poseidon_benchmark(c: &mut Criterion) { for &n in [1u32, 10, 100].iter() { let leaves = get_leaves(n); - let mut tree = OptimalMerkleTree::::default(TEST_TREE_HEIGHT).unwrap(); + let mut tree = OptimalMerkleTree::::default(TEST_TREE_DEPTH).unwrap(); group.bench_function( BenchmarkId::new("OptimalMerkleTree::::set", n), |b| { @@ -41,9 +41,9 @@ pub fn optimal_merkle_tree_poseidon_benchmark(c: &mut Criterion) { } pub fn full_merkle_tree_poseidon_benchmark(c: &mut Criterion) { - c.bench_function("FullMerkleTree::::full_height_gen", |b| { + c.bench_function("FullMerkleTree::::full_depth_gen", |b| { b.iter(|| { - FullMerkleTree::::default(TEST_TREE_HEIGHT).unwrap(); + FullMerkleTree::::default(TEST_TREE_DEPTH).unwrap(); }) }); @@ -51,7 +51,7 @@ pub fn full_merkle_tree_poseidon_benchmark(c: &mut Criterion) { for &n in [1u32, 10, 100].iter() { let leaves = get_leaves(n); - let mut tree = FullMerkleTree::::default(TEST_TREE_HEIGHT).unwrap(); + let mut tree = FullMerkleTree::::default(TEST_TREE_DEPTH).unwrap(); group.bench_function( BenchmarkId::new("FullMerkleTree::::set", n), |b| { diff --git a/rln/resources/tree_height_20/graph.bin b/rln/resources/tree_depth_20/graph.bin similarity index 100% rename from rln/resources/tree_height_20/graph.bin rename to rln/resources/tree_depth_20/graph.bin diff --git a/rln/resources/tree_height_20/rln.wasm b/rln/resources/tree_depth_20/rln.wasm similarity index 100% rename from rln/resources/tree_height_20/rln.wasm rename to rln/resources/tree_depth_20/rln.wasm diff --git a/rln/resources/tree_height_20/rln_final.arkzkey b/rln/resources/tree_depth_20/rln_final.arkzkey similarity index 100% rename from rln/resources/tree_height_20/rln_final.arkzkey rename to rln/resources/tree_depth_20/rln_final.arkzkey diff --git a/rln/src/circuit/mod.rs b/rln/src/circuit/mod.rs index cd5c62b..0121f59 100644 --- a/rln/src/circuit/mod.rs +++ b/rln/src/circuit/mod.rs @@ -19,17 +19,17 @@ use {ark_ff::Field, ark_serialize::CanonicalDeserialize, ark_serialize::Canonica use crate::utils::FrOrSecret; -pub const ARKZKEY_BYTES: &[u8] = include_bytes!("../../resources/tree_height_20/rln_final.arkzkey"); +pub const ARKZKEY_BYTES: &[u8] = include_bytes!("../../resources/tree_depth_20/rln_final.arkzkey"); #[cfg(not(target_arch = "wasm32"))] -const GRAPH_BYTES: &[u8] = include_bytes!("../../resources/tree_height_20/graph.bin"); +const GRAPH_BYTES: &[u8] = include_bytes!("../../resources/tree_depth_20/graph.bin"); lazy_static! { static ref ARKZKEY: (ProvingKey, ConstraintMatrices) = read_arkzkey_from_bytes_uncompressed(ARKZKEY_BYTES).expect("Failed to read arkzkey"); } -pub const TEST_TREE_HEIGHT: usize = 20; +pub const TEST_TREE_DEPTH: usize = 20; // The following types define the pairing friendly elliptic curve, the underlying finite fields and groups default to this module // Note that proofs are serialized assuming Fr to be 4x8 = 32 bytes in size. Hence, changing to a curve with different encoding will make proof verification to fail diff --git a/rln/src/ffi.rs b/rln/src/ffi.rs index 02632e4..9451067 100644 --- a/rln/src/ffi.rs +++ b/rln/src/ffi.rs @@ -232,8 +232,8 @@ impl<'a> From<&Buffer> for &'a [u8] { #[allow(clippy::not_unsafe_ptr_arg_deref)] #[cfg(not(feature = "stateless"))] #[no_mangle] -pub extern "C" fn new(tree_height: usize, input_buffer: *const Buffer, ctx: *mut *mut RLN) -> bool { - match RLN::new(tree_height, input_buffer.process()) { +pub extern "C" fn new(tree_depth: usize, input_buffer: *const Buffer, ctx: *mut *mut RLN) -> bool { + match RLN::new(tree_depth, input_buffer.process()) { Ok(rln) => { unsafe { *ctx = Box::into_raw(Box::new(rln)) }; true @@ -265,14 +265,14 @@ pub extern "C" fn new(ctx: *mut *mut RLN) -> bool { #[cfg(not(feature = "stateless"))] #[no_mangle] pub extern "C" fn new_with_params( - tree_height: usize, + tree_depth: usize, zkey_buffer: *const Buffer, graph_data: *const Buffer, tree_config: *const Buffer, ctx: *mut *mut RLN, ) -> bool { match RLN::new_with_params( - tree_height, + tree_depth, zkey_buffer.process().to_vec(), graph_data.process().to_vec(), tree_config.process(), @@ -317,8 +317,8 @@ pub extern "C" fn new_with_params( #[allow(clippy::not_unsafe_ptr_arg_deref)] #[no_mangle] #[cfg(not(feature = "stateless"))] -pub extern "C" fn set_tree(ctx: *mut RLN, tree_height: usize) -> bool { - call!(ctx, set_tree, tree_height) +pub extern "C" fn set_tree(ctx: *mut RLN, tree_depth: usize) -> bool { + call!(ctx, set_tree, tree_depth) } #[allow(clippy::not_unsafe_ptr_arg_deref)] diff --git a/rln/src/protocol.rs b/rln/src/protocol.rs index 2596e6b..3858636 100644 --- a/rln/src/protocol.rs +++ b/rln/src/protocol.rs @@ -296,18 +296,18 @@ pub fn rln_witness_from_values( }) } -pub fn random_rln_witness(tree_height: usize) -> RLNWitnessInput { +pub fn random_rln_witness(tree_depth: usize) -> RLNWitnessInput { let mut rng = thread_rng(); let identity_secret = IdSecret::rand(&mut rng); let x = hash_to_field_le(&rng.gen::<[u8; 32]>()); let epoch = hash_to_field_le(&rng.gen::<[u8; 32]>()); - let rln_identifier = hash_to_field_le(RLN_IDENTIFIER); //hash_to_field(&rng.gen::<[u8; 32]>()); + let rln_identifier = hash_to_field_le(RLN_IDENTIFIER); let mut path_elements: Vec = Vec::new(); let mut identity_path_index: Vec = Vec::new(); - for _ in 0..tree_height { + for _ in 0..tree_depth { path_elements.push(hash_to_field_le(&rng.gen::<[u8; 32]>())); identity_path_index.push(rng.gen_range(0..2) as u8); } diff --git a/rln/src/public.rs b/rln/src/public.rs index 922edca..1c1fb9e 100644 --- a/rln/src/public.rs +++ b/rln/src/public.rs @@ -27,7 +27,7 @@ use crate::protocol::generate_proof_with_witness; use { crate::protocol::{proof_inputs_to_rln_witness, serialize_witness}, crate::utils::{bytes_le_to_vec_u8, vec_fr_to_bytes_le, vec_u8_to_bytes_le}, - crate::{circuit::TEST_TREE_HEIGHT, poseidon_tree::PoseidonTree}, + crate::{circuit::TEST_TREE_DEPTH, poseidon_tree::PoseidonTree}, serde_json::{json, Value}, std::str::FromStr, utils::error::ZerokitMerkleTreeError, @@ -65,21 +65,21 @@ impl RLN { /// Creates a new RLN object by loading circuit resources from a folder. /// /// Input parameters are - /// - `tree_height`: the height of the internal Merkle tree + /// - `tree_depth`: the depth of the internal Merkle tree /// - `input_data`: include `tree_config` a reader for a string containing a json with the merkle tree configuration /// /// Example: /// ``` /// use std::io::Cursor; /// - /// let tree_height = 20; + /// let tree_depth = 20; /// let input = Cursor::new(json!({}).to_string()); /// /// // We create a new RLN instance - /// let mut rln = RLN::new(tree_height, input); + /// let mut rln = RLN::new(tree_depth, input); /// ``` #[cfg(all(not(target_arch = "wasm32"), not(feature = "stateless")))] - pub fn new(tree_height: usize, mut input_data: R) -> Result { + pub fn new(tree_depth: usize, mut input_data: R) -> Result { // We read input let mut input: Vec = Vec::new(); input_data.read_to_end(&mut input)?; @@ -99,7 +99,7 @@ impl RLN { // We compute a default empty tree let tree = PoseidonTree::new( - tree_height, + tree_depth, ::Hasher::default_leaf(), tree_config, )?; @@ -137,7 +137,7 @@ impl RLN { /// Creates a new RLN object by passing circuit resources as byte vectors. /// /// Input parameters are - /// - `tree_height`: the height of the internal Merkle tree + /// - `tree_depth`: the depth of the internal Merkle tree /// - `zkey_vec`: a byte vector containing to the proving key (`rln_final.arkzkey`) as binary file /// - `graph_data`: a byte vector containing the graph data (`graph.bin`) as binary file /// - `tree_config_input`: a reader for a string containing a json with the merkle tree configuration @@ -147,8 +147,8 @@ impl RLN { /// use std::fs::File; /// use std::io::Read; /// - /// let tree_height = 20; - /// let resources_folder = "./resources/tree_height_20/"; + /// let tree_depth = 20; + /// let resources_folder = "./resources/tree_depth_20/"; /// /// let mut resources: Vec> = Vec::new(); /// for filename in ["rln_final.arkzkey", "graph.bin"] { @@ -164,7 +164,7 @@ impl RLN { /// let tree_config_buffer = &Buffer::from(tree_config.as_bytes()); /// /// let mut rln = RLN::new_with_params( - /// tree_height, + /// tree_depth, /// resources[0].clone(), /// resources[1].clone(), /// tree_config_buffer, @@ -172,7 +172,7 @@ impl RLN { /// ``` #[cfg(all(not(target_arch = "wasm32"), not(feature = "stateless")))] pub fn new_with_params( - tree_height: usize, + tree_depth: usize, zkey_vec: Vec, graph_data: Vec, mut tree_config_input: R, @@ -192,7 +192,7 @@ impl RLN { // We compute a default empty tree let tree = PoseidonTree::new( - tree_height, + tree_depth, ::Hasher::default_leaf(), tree_config, )?; @@ -217,7 +217,7 @@ impl RLN { /// use std::fs::File; /// use std::io::Read; /// - /// let resources_folder = "./resources/tree_height_20/"; + /// let resources_folder = "./resources/tree_depth_20/"; /// /// let mut resources: Vec> = Vec::new(); /// for filename in ["rln_final.arkzkey", "graph.bin"] { @@ -256,7 +256,7 @@ impl RLN { /// use std::fs::File; /// use std::io::Read; /// - /// let zkey_path = "./resources/tree_height_20/rln_final.arkzkey"; + /// let zkey_path = "./resources/tree_depth_20/rln_final.arkzkey"; /// /// let mut file = File::open(zkey_path).expect("Failed to open file"); /// let metadata = std::fs::metadata(zkey_path).expect("Failed to read metadata"); @@ -284,11 +284,11 @@ impl RLN { /// Leaves are set to the default value implemented in PoseidonTree implementation. /// /// Input values are: - /// - `tree_height`: the height of the Merkle tree. + /// - `tree_depth`: the depth of the Merkle tree. #[cfg(not(feature = "stateless"))] - pub fn set_tree(&mut self, tree_height: usize) -> Result<(), RLNError> { - // We compute a default empty tree of desired height - self.tree = PoseidonTree::default(tree_height)?; + pub fn set_tree(&mut self, tree_depth: usize) -> Result<(), RLNError> { + // We compute a default empty tree of desired depth + self.tree = PoseidonTree::default(tree_depth)?; Ok(()) } @@ -416,8 +416,8 @@ impl RLN { #[cfg(not(feature = "stateless"))] pub fn init_tree_with_leaves(&mut self, input_data: R) -> Result<(), RLNError> { // reset the tree - // NOTE: this requires the tree to be initialized with the correct height initially - // TODO: accept tree_height as a parameter and initialize the tree with that height + // NOTE: this requires the tree to be initialized with the correct depth initially + // TODO: accept tree_depth as a parameter and initialize the tree with that depth self.set_tree(self.tree.depth())?; self.set_leaves_from(0, input_data) } @@ -506,12 +506,12 @@ impl RLN { /// use rln::circuit::Fr; /// use rln::utils::*; /// - /// let tree_height = 20; + /// let tree_depth = 20; /// let start_index = 10; /// let no_of_leaves = 256; /// /// // We reset the tree - /// rln.set_tree(tree_height).unwrap(); + /// rln.set_tree(tree_depth).unwrap(); /// /// // Internal Merkle tree next_index value is now 0 /// @@ -746,7 +746,7 @@ impl RLN { /// ``` /// use rln::protocol::*; /// - /// let rln_witness = random_rln_witness(tree_height); + /// let rln_witness = random_rln_witness(tree_depth); /// let proof_values = proof_values_from_witness(&rln_witness); /// /// // We compute a Groth16 proof @@ -786,7 +786,7 @@ impl RLN { /// ``` /// use rln::protocol::*; /// - /// let rln_witness = random_rln_witness(tree_height); + /// let rln_witness = random_rln_witness(tree_depth); /// /// // We compute a Groth16 proof /// let mut input_buffer = Cursor::new(serialize_witness(&rln_witness)); @@ -1257,9 +1257,9 @@ impl Default for RLN { fn default() -> Self { #[cfg(not(feature = "stateless"))] { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let buffer = Cursor::new(json!({}).to_string()); - Self::new(tree_height, buffer).unwrap() + Self::new(tree_depth, buffer).unwrap() } #[cfg(feature = "stateless")] Self::new().unwrap() diff --git a/rln/src/public_api_tests.rs b/rln/src/public_api_tests.rs index a01c71d..1888382 100644 --- a/rln/src/public_api_tests.rs +++ b/rln/src/public_api_tests.rs @@ -1,4 +1,4 @@ -use crate::circuit::TEST_TREE_HEIGHT; +use crate::circuit::TEST_TREE_DEPTH; use crate::protocol::{ proof_values_from_witness, random_rln_witness, serialize_proof_values, serialize_witness, verify_proof, RLNProofValues, @@ -53,7 +53,7 @@ fn value_to_string_vec(value: &Value) -> Vec { #[test] fn test_groth16_proof_hardcoded() { #[cfg(not(feature = "stateless"))] - let rln = RLN::new(TEST_TREE_HEIGHT, generate_input_buffer()).unwrap(); + let rln = RLN::new(TEST_TREE_DEPTH, generate_input_buffer()).unwrap(); #[cfg(feature = "stateless")] let rln = RLN::new().unwrap(); @@ -133,15 +133,15 @@ fn test_groth16_proof_hardcoded() { #[test] // This test is similar to the one in lib, but uses only public API fn test_groth16_proof() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; #[cfg(not(feature = "stateless"))] - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); #[cfg(feature = "stateless")] let mut rln = RLN::new().unwrap(); // Note: we only test Groth16 proof generation, so we ignore setting the tree in the RLN object - let rln_witness = random_rln_witness(tree_height); + let rln_witness = random_rln_witness(tree_depth); let proof_values = proof_values_from_witness(&rln_witness).unwrap(); // We compute a Groth16 proof @@ -171,7 +171,7 @@ fn test_groth16_proof() { #[cfg(not(feature = "stateless"))] mod tree_test { - use crate::circuit::{Fr, TEST_TREE_HEIGHT}; + use crate::circuit::{Fr, TEST_TREE_DEPTH}; use crate::hashers::{hash_to_field_le, poseidon_hash as utils_poseidon_hash}; use crate::protocol::*; use crate::public::RLN; @@ -186,7 +186,7 @@ mod tree_test { #[test] // We test merkle batch Merkle tree additions fn test_merkle_operations() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -197,7 +197,7 @@ mod tree_test { } // We create a new tree - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We first add leaves one by one specifying the index for (i, leaf) in leaves.iter().enumerate() { @@ -214,7 +214,7 @@ mod tree_test { let (root_single, _) = bytes_le_to_fr(&buffer.into_inner()); // We reset the tree to default - rln.set_tree(tree_height).unwrap(); + rln.set_tree(tree_depth).unwrap(); // We add leaves one by one using the internal index (new leaves goes in next available position) for leaf in &leaves { @@ -233,7 +233,7 @@ mod tree_test { assert_eq!(root_single, root_next); // We reset the tree to default - rln.set_tree(tree_height).unwrap(); + rln.set_tree(tree_depth).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -263,7 +263,7 @@ mod tree_test { let (root_delete, _) = bytes_le_to_fr(&buffer.into_inner()); // We reset the tree to default - rln.set_tree(tree_height).unwrap(); + rln.set_tree(tree_depth).unwrap(); let mut buffer = Cursor::new(Vec::::new()); rln.get_root(&mut buffer).unwrap(); @@ -276,7 +276,7 @@ mod tree_test { // We test leaf setting with a custom index, to enable batch updates to the root // Uses `set_leaves_from` to set leaves in a batch, from index `start_index` fn test_leaf_setting_with_index() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -291,7 +291,7 @@ mod tree_test { let set_index = rng.gen_range(0..no_of_leaves) as usize; // We create a new tree - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -305,7 +305,7 @@ mod tree_test { rln.get_root(&mut buffer).unwrap(); let (root_batch_with_init, _) = bytes_le_to_fr(&buffer.into_inner()); - // `init_tree_with_leaves` resets the tree to the height it was initialized with, using `set_tree` + // `init_tree_with_leaves` resets the tree to the depth it was initialized with, using `set_tree` // We add leaves in a batch starting from index 0..set_index let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves[0..set_index])); @@ -326,7 +326,7 @@ mod tree_test { assert_eq!(root_batch_with_init, root_batch_with_custom_index); // We reset the tree to default - rln.set_tree(tree_height).unwrap(); + rln.set_tree(tree_depth).unwrap(); // We add leaves one by one using the internal index (new leaves goes in next available position) for leaf in &leaves { @@ -350,7 +350,7 @@ mod tree_test { #[test] // Tests the atomic_operation fn, which set_leaves_from uses internally fn test_atomic_operation() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -361,7 +361,7 @@ mod tree_test { } // We create a new tree - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -399,7 +399,7 @@ mod tree_test { #[test] fn test_atomic_operation_zero_indexed() { // Test duplicated from https://github.com/waku-org/go-zerokit-rln/pull/12/files - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -410,7 +410,7 @@ mod tree_test { } // We create a new tree - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -443,7 +443,7 @@ mod tree_test { #[test] fn test_atomic_operation_consistency() { // Test duplicated from https://github.com/waku-org/go-zerokit-rln/pull/12/files - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -454,7 +454,7 @@ mod tree_test { } // We create a new tree - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -494,7 +494,7 @@ mod tree_test { #[test] // This test checks if `set_leaves_from` throws an error when the index is out of bounds fn test_set_leaves_bad_index() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -503,10 +503,10 @@ mod tree_test { for _ in 0..no_of_leaves { leaves.push(Fr::rand(&mut rng)); } - let bad_index = (1 << tree_height) - rng.gen_range(0..no_of_leaves) as usize; + let bad_index = (1 << tree_depth) - rng.gen_range(0..no_of_leaves) as usize; // We create a new tree - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // Get root of empty tree let mut buffer = Cursor::new(Vec::::new()); @@ -534,9 +534,9 @@ mod tree_test { #[test] fn test_get_leaf() { // We generate a random tree - let tree_height = 10; + let tree_depth = 10; let mut rng = thread_rng(); - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We generate a random leaf let leaf = Fr::rand(&mut rng); @@ -559,9 +559,9 @@ mod tree_test { #[test] fn test_valid_metadata() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); let arbitrary_metadata: &[u8] = b"block_number:200000"; rln.set_metadata(arbitrary_metadata).unwrap(); @@ -575,9 +575,9 @@ mod tree_test { #[test] fn test_empty_metadata() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; - let rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); let mut buffer = Cursor::new(Vec::::new()); rln.get_metadata(&mut buffer).unwrap(); @@ -588,7 +588,7 @@ mod tree_test { #[test] fn test_rln_proof() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -601,7 +601,7 @@ mod tree_test { } // We create a new RLN instance - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -662,7 +662,7 @@ mod tree_test { #[test] fn test_rln_with_witness() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -673,7 +673,7 @@ mod tree_test { } // We create a new RLN instance - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -745,7 +745,7 @@ mod tree_test { #[test] fn proof_verification_with_roots() { // The first part is similar to test_rln_with_witness - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; let no_of_leaves = 256; // We generate a vector of random leaves @@ -756,7 +756,7 @@ mod tree_test { } // We create a new RLN instance - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // We add leaves in a batch into the tree let mut buffer = Cursor::new(vec_fr_to_bytes_le(&leaves)); @@ -847,10 +847,10 @@ mod tree_test { #[test] fn test_recover_id_secret() { - let tree_height = TEST_TREE_HEIGHT; + let tree_depth = TEST_TREE_DEPTH; // We create a new RLN instance - let mut rln = RLN::new(tree_height, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(tree_depth, generate_input_buffer()).unwrap(); // Generate identity pair let (identity_secret_hash, id_commitment) = keygen(); @@ -993,7 +993,7 @@ mod tree_test { #[cfg(feature = "stateless")] mod stateless_test { - use crate::circuit::{Fr, TEST_TREE_HEIGHT}; + use crate::circuit::{Fr, TEST_TREE_DEPTH}; use crate::hashers::{hash_to_field_le, poseidon_hash as utils_poseidon_hash, PoseidonHash}; use crate::protocol::*; use crate::public::RLN; @@ -1013,7 +1013,7 @@ mod stateless_test { let default_leaf = Fr::from(0); let mut tree: OptimalMerkleTree = OptimalMerkleTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::>::default(), ) @@ -1111,7 +1111,7 @@ mod stateless_test { let default_leaf = Fr::from(0); let mut tree: OptimalMerkleTree = OptimalMerkleTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::>::default(), ) diff --git a/rln/tests/ffi.rs b/rln/tests/ffi.rs index 409fd71..f71ebe1 100644 --- a/rln/tests/ffi.rs +++ b/rln/tests/ffi.rs @@ -3,7 +3,7 @@ mod test { use ark_std::{rand::thread_rng, UniformRand}; use rand::Rng; - use rln::circuit::{Fr, TEST_TREE_HEIGHT}; + use rln::circuit::{Fr, TEST_TREE_DEPTH}; use rln::ffi::*; use rln::hashers::{hash_to_field_le, poseidon_hash as utils_poseidon_hash}; use rln::protocol::{deserialize_identity_tuple_le, *}; @@ -22,7 +22,7 @@ mod test { let mut rln_pointer = MaybeUninit::<*mut RLN>::uninit(); let input_config = json!({}).to_string(); let input_buffer = &Buffer::from(input_config.as_bytes()); - let success = new(TEST_TREE_HEIGHT, input_buffer, rln_pointer.as_mut_ptr()); + let success = new(TEST_TREE_DEPTH, input_buffer, rln_pointer.as_mut_ptr()); assert!(success, "RLN object creation failed"); unsafe { &mut *rln_pointer.assume_init() } } @@ -91,7 +91,7 @@ mod test { let root_single = get_tree_root(rln_pointer); // We reset the tree to default - let success = set_tree(rln_pointer, TEST_TREE_HEIGHT); + let success = set_tree(rln_pointer, TEST_TREE_DEPTH); assert!(success, "set tree call failed"); // We add leaves one by one using the internal index (new leaves goes in next available position) @@ -109,7 +109,7 @@ mod test { assert_eq!(root_single, root_next); // We reset the tree to default - let success = set_tree(rln_pointer, TEST_TREE_HEIGHT); + let success = set_tree(rln_pointer, TEST_TREE_DEPTH); assert!(success, "set tree call failed"); // We add leaves in a batch into the tree @@ -132,7 +132,7 @@ mod test { let root_delete = get_tree_root(rln_pointer); // We reset the tree to default - let success = set_tree(rln_pointer, TEST_TREE_HEIGHT); + let success = set_tree(rln_pointer, TEST_TREE_DEPTH); assert!(success, "set tree call failed"); // We get the root of the empty tree @@ -165,7 +165,7 @@ mod test { // We get the root of the tree obtained adding leaves in batch let root_batch_with_init = get_tree_root(rln_pointer); - // `init_tree_with_leaves` resets the tree to the height it was initialized with, using `set_tree` + // `init_tree_with_leaves` resets the tree to the depth it was initialized with, using `set_tree` // We add leaves in a batch starting from index 0..set_index set_leaves_init(rln_pointer, &leaves[0..set_index]); @@ -184,7 +184,7 @@ mod test { ); // We reset the tree to default - let success = set_tree(rln_pointer, TEST_TREE_HEIGHT); + let success = set_tree(rln_pointer, TEST_TREE_DEPTH); assert!(success, "set tree call failed"); // We add leaves one by one using the internal index (new leaves goes in next available position) @@ -243,7 +243,7 @@ mod test { let rln_pointer = create_rln_instance(); let mut rng = thread_rng(); - let bad_index = (1 << TEST_TREE_HEIGHT) - rng.gen_range(0..NO_OF_LEAVES) as usize; + let bad_index = (1 << TEST_TREE_DEPTH) - rng.gen_range(0..NO_OF_LEAVES) as usize; // Get root of empty tree let root_empty = get_tree_root(rln_pointer); @@ -364,7 +364,7 @@ mod test { for _ in 0..sample_size { // We generate random witness instances and relative proof values - let rln_witness = random_rln_witness(TEST_TREE_HEIGHT); + let rln_witness = random_rln_witness(TEST_TREE_DEPTH); let proof_values = proof_values_from_witness(&rln_witness).unwrap(); // We prepare id_commitment and we set the leaf at provided index @@ -414,7 +414,7 @@ mod test { // We obtain the root from the RLN instance let root_rln_folder = get_tree_root(rln_pointer); - let zkey_path = "./resources/tree_height_20/rln_final.arkzkey"; + let zkey_path = "./resources/tree_depth_20/rln_final.arkzkey"; let mut zkey_file = File::open(zkey_path).expect("no file found"); let metadata = std::fs::metadata(zkey_path).expect("unable to read metadata"); let mut zkey_buffer = vec![0; metadata.len() as usize]; @@ -424,7 +424,7 @@ mod test { let zkey_data = &Buffer::from(&zkey_buffer[..]); - let graph_data = "./resources/tree_height_20/graph.bin"; + let graph_data = "./resources/tree_depth_20/graph.bin"; let mut graph_file = File::open(graph_data).expect("no file found"); let metadata = std::fs::metadata(graph_data).expect("unable to read metadata"); let mut graph_buffer = vec![0; metadata.len() as usize]; @@ -439,7 +439,7 @@ mod test { let tree_config = "".to_string(); let tree_config_buffer = &Buffer::from(tree_config.as_bytes()); let success = new_with_params( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, zkey_data, graph_data, tree_config_buffer, @@ -777,7 +777,7 @@ mod test { #[test] fn test_get_leaf_ffi() { // We create a RLN instance - let no_of_leaves = 1 << TEST_TREE_HEIGHT; + let no_of_leaves = 1 << TEST_TREE_DEPTH; // We create a RLN instance let rln_pointer = create_rln_instance(); @@ -898,7 +898,7 @@ mod stateless_test { fn test_recover_id_secret_stateless_ffi() { let default_leaf = Fr::from(0); let mut tree: OptimalMerkleTree = OptimalMerkleTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::>::default(), ) @@ -1044,7 +1044,7 @@ mod stateless_test { fn test_verify_with_roots_stateless_ffi() { let default_leaf = Fr::from(0); let mut tree: OptimalMerkleTree = OptimalMerkleTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::>::default(), ) @@ -1147,7 +1147,7 @@ mod stateless_test { for _ in 0..sample_size { // We generate random witness instances and relative proof values - let rln_witness = random_rln_witness(TEST_TREE_HEIGHT); + let rln_witness = random_rln_witness(TEST_TREE_DEPTH); let proof_values = proof_values_from_witness(&rln_witness).unwrap(); // We prepare id_commitment and we set the leaf at provided index diff --git a/rln/tests/poseidon_tree.rs b/rln/tests/poseidon_tree.rs index 14c337a..a54f935 100644 --- a/rln/tests/poseidon_tree.rs +++ b/rln/tests/poseidon_tree.rs @@ -8,7 +8,7 @@ mod test { use rln::hashers::{poseidon_hash, PoseidonHash}; use rln::{ - circuit::{Fr, TEST_TREE_HEIGHT}, + circuit::{Fr, TEST_TREE_DEPTH}, poseidon_tree::PoseidonTree, }; use utils::{FullMerkleTree, OptimalMerkleTree, ZerokitMerkleProof, ZerokitMerkleTree}; @@ -19,8 +19,8 @@ mod test { let sample_size = 100; let leaves: Vec = (0..sample_size).map(Fr::from).collect(); - let mut tree_full = FullMerkleTree::::default(TEST_TREE_HEIGHT).unwrap(); - let mut tree_opt = OptimalMerkleTree::::default(TEST_TREE_HEIGHT).unwrap(); + let mut tree_full = FullMerkleTree::::default(TEST_TREE_DEPTH).unwrap(); + let mut tree_opt = OptimalMerkleTree::::default(TEST_TREE_DEPTH).unwrap(); for (i, leave) in leaves .into_iter() diff --git a/rln/tests/protocol.rs b/rln/tests/protocol.rs index 67bfb0f..d8f2880 100644 --- a/rln/tests/protocol.rs +++ b/rln/tests/protocol.rs @@ -4,7 +4,7 @@ mod test { use ark_ff::BigInt; use rln::circuit::{graph_from_folder, zkey_from_folder}; - use rln::circuit::{Fr, TEST_TREE_HEIGHT}; + use rln::circuit::{Fr, TEST_TREE_DEPTH}; use rln::hashers::{hash_to_field_le, poseidon_hash}; use rln::poseidon_tree::PoseidonTree; use rln::protocol::{ @@ -31,7 +31,7 @@ mod test { // generate merkle tree let default_leaf = Fr::from(0); let mut tree = PoseidonTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::::default(), ) @@ -102,7 +102,7 @@ mod test { //// generate merkle tree let default_leaf = Fr::from(0); let mut tree = PoseidonTree::new( - TEST_TREE_HEIGHT, + TEST_TREE_DEPTH, default_leaf, ConfigOf::::default(), ) diff --git a/rln/tests/public.rs b/rln/tests/public.rs index 9869c4f..061deaa 100644 --- a/rln/tests/public.rs +++ b/rln/tests/public.rs @@ -4,7 +4,7 @@ mod test { use { ark_ff::BigInt, rln::{ - circuit::TEST_TREE_HEIGHT, + circuit::TEST_TREE_DEPTH, protocol::compute_tree_root, public::RLN, utils::{ @@ -41,7 +41,7 @@ mod test { let leaf_index = 3; let user_message_limit = 1; - let mut rln = RLN::new(TEST_TREE_HEIGHT, generate_input_buffer()).unwrap(); + let mut rln = RLN::new(TEST_TREE_DEPTH, generate_input_buffer()).unwrap(); // generate identity let mut identity_secret_hash_ = hash_to_field_le(b"test-merkle-proof"); @@ -126,9 +126,9 @@ mod test { // check subtree root computation for leaf 0 for all corresponding node until the root let l_idx = 0; - for n in (1..=TEST_TREE_HEIGHT).rev() { - let idx_l = l_idx * (1 << (TEST_TREE_HEIGHT - n)); - let idx_r = (l_idx + 1) * (1 << (TEST_TREE_HEIGHT - n)); + for n in (1..=TEST_TREE_DEPTH).rev() { + let idx_l = l_idx * (1 << (TEST_TREE_DEPTH - n)); + let idx_r = (l_idx + 1) * (1 << (TEST_TREE_DEPTH - n)); let idx_sr = idx_l; let mut buffer = Cursor::new(Vec::::new()); diff --git a/utils/src/merkle_tree/full_merkle_tree.rs b/utils/src/merkle_tree/full_merkle_tree.rs index 7a39ffc..5c816ff 100644 --- a/utils/src/merkle_tree/full_merkle_tree.rs +++ b/utils/src/merkle_tree/full_merkle_tree.rs @@ -78,7 +78,7 @@ where } /// Creates a new `MerkleTree` - /// depth - the height of the tree made only of hash nodes. 2^depth is the maximum number of leaves hash nodes + /// depth - the depth of the tree made only of hash nodes. 2^depth is the maximum number of leaves hash nodes fn new( depth: usize, default_leaf: FrOf, diff --git a/utils/src/merkle_tree/optimal_merkle_tree.rs b/utils/src/merkle_tree/optimal_merkle_tree.rs index 21bb5f7..af0d4eb 100644 --- a/utils/src/merkle_tree/optimal_merkle_tree.rs +++ b/utils/src/merkle_tree/optimal_merkle_tree.rs @@ -70,7 +70,7 @@ where } /// Creates a new `MerkleTree` - /// depth - the height of the tree made only of hash nodes. 2^depth is the maximum number of leaves hash nodes + /// depth - the depth of the tree made only of hash nodes. 2^depth is the maximum number of leaves hash nodes fn new( depth: usize, default_leaf: H::Fr,