diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 366bd1a..1ea81b2 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -161,14 +161,16 @@ impl MerkleHashTree

{ let mut cur_height = tree_height; let mut padding_tree = Vec::new(); let mut cur_hash = tree[0].clone(); - while cur_height < (Self::HEIGHT - 1) as usize { - cur_hash = hash_inner_node::(¶meters, &cur_hash, &empty_hash, &mut buffer)?; - padding_tree.push((cur_hash.clone(), empty_hash.clone())); - cur_height += 1; - } - - let root_hash = hash_inner_node::(¶meters, &cur_hash, &empty_hash, &mut buffer)?; - + let root_hash = if cur_height < Self::HEIGHT as usize { + while cur_height < (Self::HEIGHT - 1) as usize { + cur_hash = hash_inner_node::(¶meters, &cur_hash, &empty_hash, &mut buffer)?; + padding_tree.push((cur_hash.clone(), empty_hash.clone())); + cur_height += 1; + } + hash_inner_node::(¶meters, &cur_hash, &empty_hash, &mut buffer)? + } else { + cur_hash + }; end_timer!(new_time); Ok(MerkleHashTree {