mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 18:51:19 +00:00
Remove leaf hashing in MerkleRoot function (#1653)
* Remove leaf hashing in MerkleRoot function See https://github.com/ethereum/eth2.0-specs/pull/646 for clarification. * Add comment clarifying leaf hashing removal
This commit is contained in:
parent
9bee695a3b
commit
e3ba3e181c
@ -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
|
||||
@ -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...)
|
||||
|
||||
|
@ -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[:]...))
|
||||
|
Loading…
Reference in New Issue
Block a user