From fcf3168e7721abb9b2211ec13a03eec5ebab813f Mon Sep 17 00:00:00 2001 From: Cayman Date: Tue, 19 Feb 2019 17:45:42 -0600 Subject: [PATCH 1/2] Remove leaf hashing in MerkleRoot function See https://github.com/ethereum/eth2.0-specs/pull/646 for clarification. --- shared/hashutil/merkleRoot.go | 6 ------ shared/hashutil/merkleRoot_test.go | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/shared/hashutil/merkleRoot.go b/shared/hashutil/merkleRoot.go index 352d4ea064e..629a8494e23 100644 --- a/shared/hashutil/merkleRoot.go +++ b/shared/hashutil/merkleRoot.go @@ -12,12 +12,6 @@ package hashutil func MerkleRoot(values [][]byte) []byte { length := len(values) - // Data is hashed so as to be stored as leaves in the tree. - for i, v := range values { - hashedValue := Hash(v) - values[i] = hashedValue[:] - } - newSet := make([][]byte, length, length*2) newSet = append(newSet, values...) diff --git a/shared/hashutil/merkleRoot_test.go b/shared/hashutil/merkleRoot_test.go index 5c908ccd5ba..42fdf244802 100644 --- a/shared/hashutil/merkleRoot_test.go +++ b/shared/hashutil/merkleRoot_test.go @@ -13,10 +13,10 @@ func TestMerkleRoot(t *testing.T) { {'d'}, } - hashedV1 := Hash([]byte{'a'}) - hashedV2 := Hash([]byte{'b'}) - hashedV3 := Hash([]byte{'c'}) - hashedV4 := Hash([]byte{'d'}) + hashedV1 := []byte{'a'} + hashedV2 := []byte{'b'} + hashedV3 := []byte{'c'} + hashedV4 := []byte{'d'} leftNode := Hash(append(hashedV1[:], hashedV2[:]...)) rightNode := Hash(append(hashedV3[:], hashedV4[:]...)) From b9f971a8d665bcba672cf1b50e506eef2cc617ed Mon Sep 17 00:00:00 2001 From: Cayman Date: Wed, 20 Feb 2019 11:38:29 -0600 Subject: [PATCH 2/2] Add comment clarifying leaf hashing removal --- shared/hashutil/merkleRoot.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/hashutil/merkleRoot.go b/shared/hashutil/merkleRoot.go index 629a8494e23..46fe3b02a43 100644 --- a/shared/hashutil/merkleRoot.go +++ b/shared/hashutil/merkleRoot.go @@ -3,6 +3,8 @@ package hashutil // MerkleRoot derives the merkle root from a 2d byte array with each element // in the outer array signifying the data that is to be represented in the // merkle tree. +// Note: This function is only used to merklize a list of block root hashes. +// As such, we assume the input comes pre-hashed and do NOT hash the leaves. // Spec: // def merkle_root(values): // o = [0] * len(values) + values