Browse Source

Merkle tree fails to compute the root when there's no need in dummy nodes - fix

master
Sergey Vasilyev 4 years ago
committed by Pratyush Mishra
parent
commit
4e0d92a6ec
1 changed files with 10 additions and 8 deletions
  1. +10
    -8
      crypto-primitives/src/merkle_tree/mod.rs

+ 10
- 8
crypto-primitives/src/merkle_tree/mod.rs

@ -161,14 +161,16 @@ impl MerkleHashTree

{

let mut cur_height = tree_height; let mut cur_height = tree_height;
let mut padding_tree = Vec::new(); let mut padding_tree = Vec::new();
let mut cur_hash = tree[0].clone(); let mut cur_hash = tree[0].clone();
while cur_height < (Self::HEIGHT - 1) as usize {
cur_hash = hash_inner_node::<P::H>(&parameters, &cur_hash, &empty_hash, &mut buffer)?;
padding_tree.push((cur_hash.clone(), empty_hash.clone()));
cur_height += 1;
}
let root_hash = hash_inner_node::<P::H>(&parameters, &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::<P::H>(&parameters, &cur_hash, &empty_hash, &mut buffer)?;
padding_tree.push((cur_hash.clone(), empty_hash.clone()));
cur_height += 1;
}
hash_inner_node::<P::H>(&parameters, &cur_hash, &empty_hash, &mut buffer)?
} else {
cur_hash
};
end_timer!(new_time); end_timer!(new_time);
Ok(MerkleHashTree { Ok(MerkleHashTree {

Loading…
Cancel
Save