Skip to content

Commit 84253ae

Browse files
committed
shortend struct init for multipath
1 parent 387e018 commit 84253ae

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/merkle_tree/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
77
use ark_std::borrow::Borrow;
88
use ark_std::hash::Hash;
99
use ark_std::vec::Vec;
10-
use ark_std::collections::{BTreeSet, HashMap};
10+
use std::collections::{BTreeSet, HashMap};
1111

1212
#[cfg(test)]
1313
mod tests;
@@ -107,9 +107,8 @@ pub type LeafParam<P> = <<P as Config>::LeafHash as CRHScheme>::Parameters;
107107
/// [I] J
108108
/// ```
109109
/// Suppose we want to prove I, then `leaf_sibling_hash` is J, `auth_path` is `[C,D]`
110-
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
110+
#[derive(PartialEq, Derivative, CanonicalSerialize, CanonicalDeserialize)]
111111
#[derivative(
112-
PartialEq(bound = "P: Config"),
113112
Clone(bound = "P: Config"),
114113
Debug(bound = "P: Config"),
115114
Default(bound = "P: Config")
@@ -270,9 +269,9 @@ impl<P: Config> MultiPath<P> {
270269

271270
Ok(MultiPath {
272271
leaf_indexes: indexes,
273-
auth_paths_prefix_lenghts: auth_paths_prefix_lenghts,
274-
auth_paths_suffixes: auth_paths_suffixes,
275-
leaf_siblings_hashes: leaf_siblings_hashes,
272+
auth_paths_prefix_lenghts,
273+
auth_paths_suffixes,
274+
leaf_siblings_hashes,
276275
})
277276
}
278277

@@ -309,20 +308,20 @@ impl<P: Config> MultiPath<P> {
309308
) -> Result<bool, crate::Error> {
310309
// array of auth paths as arrays of InnerDigests
311310

312-
let mut leaves = leaves.into_iter();
311+
let leaves: Vec<L> = leaves.into_iter().collect();
313312

314-
let mut auth_paths: Vec<Vec<P::InnerDigest>> = self.decompress()?.peekable();
313+
let auth_paths: Vec<Vec<P::InnerDigest>> = self.decompress()?.collect();
315314

316-
let tree_height = auth_paths.peek().unwrap().len() + 2;
315+
let tree_height = auth_paths[0].len() + 2;
317316

318317
// LookUp table to speedup computation avoid redundant hash computations
319318
let mut hash_lut: HashMap<usize, P::InnerDigest> = HashMap::new();
320319

321320
for i in 0..self.leaf_indexes.len() {
322321
let leaf_index = self.leaf_indexes[i];
323-
let leaf = leaves.next().unwrap();
322+
let leaf = &leaves[i];
324323
let leaf_sibling_hash = &self.leaf_siblings_hashes[i];
325-
let auth_path = auth_paths.next().unwrap();
324+
let auth_path = &auth_paths[i];
326325

327326
let claimed_leaf_hash = P::LeafHash::evaluate(&leaf_hash_params, leaf.clone())?;
328327
let (left_child, right_child) =

0 commit comments

Comments
 (0)