Skip to content

Commit ad758e1

Browse files
committed
trie/bintrie: spec change, big endian hashing of slot key
1 parent 8a3a309 commit ad758e1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

trie/bintrie/key_encoding.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ func getBinaryTreeKey(addr common.Address, offset []byte, overflow bool) []byte
5454
defer returnSha256(hasher)
5555
hasher.Write(zeroHash[:12])
5656
hasher.Write(addr[:])
57-
var buf [32]byte
58-
// key is big endian, hashed value is little endian
59-
for i := range offset[:31] {
60-
buf[i] = offset[30-i]
61-
}
57+
var buf [32]byte // TODO: make offset a 33-byte value to avoid an extra stack alloc
58+
copy(buf[1:32], offset[:31])
6259
if overflow {
6360
// Overflow detected when adding MAIN_STORAGE_OFFSET,
6461
// reporting it in the shifter 32 byte value.
65-
buf[31] = 1
62+
buf[0] = 1
6663
}
6764
hasher.Write(buf[:])
6865
k := hasher.Sum(nil)

0 commit comments

Comments
 (0)