diff --git a/benches/merkle_tree.rs b/benches/merkle_tree.rs index 71322879..b32168e8 100644 --- a/benches/merkle_tree.rs +++ b/benches/merkle_tree.rs @@ -49,7 +49,7 @@ mod bytes_mt_benches { Sha256MerkleTree::new( &leaf_crh_params.clone(), &two_to_one_params.clone(), - leaves.iter().map(|x| x.as_slice()), + &leaves, ) .unwrap(); }) diff --git a/src/crh/mod.rs b/src/crh/mod.rs index 4a6e5174..e66be16e 100644 --- a/src/crh/mod.rs +++ b/src/crh/mod.rs @@ -21,7 +21,7 @@ pub use constraints::*; /// Interface to CRH. Note that in this release, while all implementations of `CRH` have fixed length, /// variable length CRH may also implement this trait in future. pub trait CRHScheme { - type Input: ?Sized; + type Input: ?Sized + Send; type Output: Clone + Eq + core::fmt::Debug diff --git a/src/merkle_tree/mod.rs b/src/merkle_tree/mod.rs index d6acd254..d2739d7a 100644 --- a/src/merkle_tree/mod.rs +++ b/src/merkle_tree/mod.rs @@ -239,21 +239,14 @@ impl MerkleTree

{ } /// Returns a new merkle tree. `leaves.len()` should be power of two. - pub fn new( + pub fn new + Send>( leaf_hash_param: &LeafParam

, two_to_one_hash_param: &TwoToOneParam

, - leaves: T, - ) -> Result - where - L: Borrow + Send, - T: IntoIterator, - T::IntoIter: Send, - { - #[cfg(feature = "parallel")] - let leaves = leaves.into_iter().par_bridge(); - + #[cfg(not(feature = "parallel"))] leaves: impl IntoIterator, + #[cfg(feature = "parallel")] leaves: impl IntoParallelIterator, + ) -> Result { let leaf_digests: Vec<_> = cfg_into_iter!(leaves) - .map(|leaf| P::LeafHash::evaluate(leaf_hash_param, leaf)) + .map(|input| P::LeafHash::evaluate(leaf_hash_param, input.as_ref())) .collect::, _>>()?; Self::new_with_leaf_digest(leaf_hash_param, two_to_one_hash_param, &leaf_digests) diff --git a/src/merkle_tree/tests/constraints.rs b/src/merkle_tree/tests/constraints.rs index fbe5217c..8f1602d7 100644 --- a/src/merkle_tree/tests/constraints.rs +++ b/src/merkle_tree/tests/constraints.rs @@ -61,12 +61,8 @@ mod byte_mt_tests { let leaf_crh_params = ::setup(&mut rng).unwrap(); let two_to_one_crh_params = ::setup(&mut rng).unwrap(); - let mut tree = JubJubMerkleTree::new( - &leaf_crh_params, - &two_to_one_crh_params, - leaves.iter().map(|v| v.as_slice()), - ) - .unwrap(); + let mut tree = + JubJubMerkleTree::new(&leaf_crh_params, &two_to_one_crh_params, leaves).unwrap(); let root = tree.root(); for (i, leaf) in leaves.iter().enumerate() { let cs = ConstraintSystem::::new_ref(); @@ -288,12 +284,7 @@ mod field_mt_tests { ) { let leaf_crh_params = poseidon_parameters(); let two_to_one_params = leaf_crh_params.clone(); - let mut tree = FieldMT::new( - &leaf_crh_params, - &two_to_one_params, - leaves.iter().map(|x| x.as_slice()), - ) - .unwrap(); + let mut tree = FieldMT::new(&leaf_crh_params, &two_to_one_params, leaves).unwrap(); let root = tree.root(); for (i, leaf) in leaves.iter().enumerate() { let cs = ConstraintSystem::::new_ref(); diff --git a/src/merkle_tree/tests/mod.rs b/src/merkle_tree/tests/mod.rs index 91116ea1..a4968917 100644 --- a/src/merkle_tree/tests/mod.rs +++ b/src/merkle_tree/tests/mod.rs @@ -46,16 +46,10 @@ mod bytes_mt_tests { .collect(); let leaf_crh_params = ::setup(&mut rng).unwrap(); - let two_to_one_params = ::setup(&mut rng) - .unwrap() - .clone(); - - let mut tree = JubJubMerkleTree::new( - &leaf_crh_params.clone(), - &two_to_one_params.clone(), - leaves.iter().map(|x| x.as_slice()), - ) - .unwrap(); + let two_to_one_params = ::setup(&mut rng).unwrap(); + + let mut tree = + JubJubMerkleTree::new(&leaf_crh_params, &two_to_one_params, &leaves).unwrap(); let mut root = tree.root(); // test merkle tree functionality without update @@ -149,12 +143,7 @@ mod field_mt_tests { let leaf_crh_params = poseidon_parameters(); let two_to_one_params = leaf_crh_params.clone(); - let mut tree = FieldMT::new( - &leaf_crh_params, - &two_to_one_params, - leaves.iter().map(|x| x.as_slice()), - ) - .unwrap(); + let mut tree = FieldMT::new(&leaf_crh_params, &two_to_one_params, &leaves).unwrap(); let mut root = tree.root();