From 998e2ed7eba1cba6b28b09852c47118bac7511df Mon Sep 17 00:00:00 2001 From: Johns Beharry Date: Fri, 11 Jan 2019 19:45:31 -0400 Subject: [PATCH] feat(hashing): fill o with 0s placeholders #146 Signed-off-by: Johns Beharry --- beacon_chain/utils/hashing/src/merkle_root.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/beacon_chain/utils/hashing/src/merkle_root.rs b/beacon_chain/utils/hashing/src/merkle_root.rs index 3251154f0..9a05ed450 100644 --- a/beacon_chain/utils/hashing/src/merkle_root.rs +++ b/beacon_chain/utils/hashing/src/merkle_root.rs @@ -1,8 +1,9 @@ use types::{Hash256} use hashing::canonical_hash; -fn merkle_root(values: Vec<>) -> Hash256 { - let o = values.len(); +fn merkle_root(values: Vec) -> Hash256 { + let mut o = vec![0; values.len()]; + o.append(values); for v in &values { canonical_hash(v.as_bytes()); @@ -19,8 +20,8 @@ mod tests { let test_leaf_2 = canonical_hash(values[1]); let test_leaf_3 = canonical_hash(values[2]); let test_leaf_4 = canonical_hash(values[3]); - let test_node_1 = canonical_hash(vec![test_leaf_1, test_leaf_2]); - let test_node_2 = canonical_hash(vec![test_leaf_3, test_leaf_4]); + let test_node_1 = canonical_hash(vec![test_leaf_4, test_leaf_3]); + let test_node_2 = canonical_hash(vec![test_leaf_2, test_leaf_1]); let test_root = canonical_hash(vec![test_node_1, test_node_2]); let result = merkle_root(values);