Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove leaf hashing in MerkleRoot function #1653

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions shared/hashutil/merkleRoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,12 +14,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...)

Expand Down
8 changes: 4 additions & 4 deletions shared/hashutil/merkleRoot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]...))
Expand Down