diff --git a/src/merkle/smt/full/concurrent/mod.rs b/src/merkle/smt/full/concurrent/mod.rs index 698a8cf..1785642 100644 --- a/src/merkle/smt/full/concurrent/mod.rs +++ b/src/merkle/smt/full/concurrent/mod.rs @@ -247,6 +247,25 @@ impl Smt { Self::process_sorted_pairs_to_leaves(pairs, Self::pairs_to_leaf) } + /// Constructs a single leaf from an arbitrary amount of key-value pairs. + /// Those pairs must all have the same leaf index. + fn pairs_to_leaf(mut pairs: Vec<(RpoDigest, Word)>) -> SmtLeaf { + assert!(!pairs.is_empty()); + + if pairs.len() > 1 { + SmtLeaf::new_multiple(pairs).unwrap() + } else { + let (key, value) = pairs.pop().unwrap(); + // TODO: should we ever be constructing empty leaves from pairs? + if value == Self::EMPTY_VALUE { + let index = Self::key_to_leaf_index(&key); + SmtLeaf::new_empty(index) + } else { + SmtLeaf::new_single(key, value) + } + } + } + /// Computes leaves from a set of key-value pairs and current leaf values. /// Derived from `sorted_pairs_to_leaves` fn sorted_pairs_to_mutated_subtree_leaves( diff --git a/src/merkle/smt/full/mod.rs b/src/merkle/smt/full/mod.rs index 15b4f28..11c28f4 100644 --- a/src/merkle/smt/full/mod.rs +++ b/src/merkle/smt/full/mod.rs @@ -430,23 +430,6 @@ impl SparseMerkleTree for Smt { fn path_and_leaf_to_opening(path: MerklePath, leaf: SmtLeaf) -> SmtProof { SmtProof::new_unchecked(path, leaf) } - - fn pairs_to_leaf(mut pairs: Vec<(RpoDigest, Word)>) -> SmtLeaf { - assert!(!pairs.is_empty()); - - if pairs.len() > 1 { - SmtLeaf::new_multiple(pairs).unwrap() - } else { - let (key, value) = pairs.pop().unwrap(); - // TODO: should we ever be constructing empty leaves from pairs? - if value == Self::EMPTY_VALUE { - let index = Self::key_to_leaf_index(&key); - SmtLeaf::new_empty(index) - } else { - SmtLeaf::new_single(key, value) - } - } - } } impl Default for Smt { diff --git a/src/merkle/smt/mod.rs b/src/merkle/smt/mod.rs index ddca78b..5d8c933 100644 --- a/src/merkle/smt/mod.rs +++ b/src/merkle/smt/mod.rs @@ -451,10 +451,6 @@ pub(crate) trait SparseMerkleTree { /// Maps a key to a leaf index fn key_to_leaf_index(key: &Self::Key) -> LeafIndex; - /// Constructs a single leaf from an arbitrary amount of key-value pairs. - /// Those pairs must all have the same leaf index. - fn pairs_to_leaf(pairs: Vec<(Self::Key, Self::Value)>) -> Self::Leaf; - /// Maps a (MerklePath, Self::Leaf) to an opening. /// /// The length `path` is guaranteed to be equal to `DEPTH` diff --git a/src/merkle/smt/simple/mod.rs b/src/merkle/smt/simple/mod.rs index 166cc98..11f9cf3 100644 --- a/src/merkle/smt/simple/mod.rs +++ b/src/merkle/smt/simple/mod.rs @@ -1,4 +1,4 @@ -use alloc::{collections::BTreeSet, vec::Vec}; +use alloc::collections::BTreeSet; use super::{ super::ValuePath, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes, LeafIndex, @@ -415,11 +415,4 @@ impl SparseMerkleTree for SimpleSmt { fn path_and_leaf_to_opening(path: MerklePath, leaf: Word) -> ValuePath { (path, leaf).into() } - - fn pairs_to_leaf(mut pairs: Vec<(LeafIndex, Word)>) -> Word { - // SimpleSmt can't have more than one value per key. - assert_eq!(pairs.len(), 1); - let (_key, value) = pairs.pop().unwrap(); - value - } }