From 81f3105a9185dd1570681eb88ce4c962e559899a Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Wed, 1 Apr 2020 22:44:10 -0700 Subject: [PATCH] Fix MerkleTree leaf index calculation --- crypto-primitives/src/merkle_tree/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 80e002e..ecc8745 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -130,7 +130,7 @@ impl MerkleHashTree

{ } // Compute and store the hash values for each leaf. - let last_level_index = level_indices.pop().unwrap(); + let last_level_index = level_indices.pop().unwrap_or(0); let mut buffer = [0u8; 128]; for (i, leaf) in leaves.iter().enumerate() { tree[last_level_index + i] = hash_leaf::(¶meters, leaf, &mut buffer)?;