Skip to content

Commit 735bfd1

Browse files
authored
trie/bintrie: spec change, big endian hashing of slot key (#34670)
The spec has been changed during SIC #49, the offset is encoded as a big-endian number.
1 parent 6333855 commit 735bfd1

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

core/genesis_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func TestVerkleGenesisCommit(t *testing.T) {
308308
},
309309
}
310310

311-
expected := common.FromHex("1fd154971d9a386c4ec75fe7138c17efb569bfc2962e46e94a376ba997e3fadc")
311+
expected := common.FromHex("0870fd587c41dc778019de8c5cb3193fe4ef1f417976461952d3712ba39163f5")
312312
got := genesis.ToBlock().Root().Bytes()
313313
if !bytes.Equal(got, expected) {
314314
t.Fatalf("invalid genesis state root, expected %x, got %x", expected, got)

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)