diff --git a/src/merkle/partial_mt/mod.rs b/src/merkle/partial_mt/mod.rs index c29b6e8b..278e992f 100644 --- a/src/merkle/partial_mt/mod.rs +++ b/src/merkle/partial_mt/mod.rs @@ -107,16 +107,15 @@ impl PartialMerkleTree { .or_insert(vec![node_index.value()]); } - // check if the number of leaves can be accommodated by the tree's depth; we use a min - // depth of 63 because we consider passing in a vector of size 2^64 infeasible. - let max = (1_u64 << 63) as usize; + // Get maximum depth + let max_depth = *layers.keys().next_back().unwrap_or(&0); + + // check if the number of leaves can be accommodated by the tree's depth + let max = (1_u64 << max_depth) as usize; if layers.len() > max { return Err(MerkleError::InvalidNumEntries(max, layers.len())); } - // Get maximum depth - let max_depth = *layers.keys().next_back().unwrap_or(&0); - // fill layers without nodes with empty vector for depth in 0..max_depth { layers.entry(depth).or_default(); diff --git a/src/merkle/simple_smt/mod.rs b/src/merkle/simple_smt/mod.rs index 39f52930..0e1b8756 100644 --- a/src/merkle/simple_smt/mod.rs +++ b/src/merkle/simple_smt/mod.rs @@ -79,10 +79,9 @@ impl SimpleSmt { // create an empty tree let mut tree = Self::new(depth)?; - // check if the number of leaves can be accommodated by the tree's depth; we use a min - // depth of 63 because we consider passing in a vector of size 2^64 infeasible. + // check if the number of leaves can be accommodated by the tree's depth let entries = entries.into_iter(); - let max = 1 << tree.depth.min(63); + let max = 1 << tree.depth; if entries.len() > max { return Err(MerkleError::InvalidNumEntries(max, entries.len())); }