mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
trie/bintrie: fix tree key hashing to match spec (#33694)
Based on [EIP-7864](https://eips.ethereum.org/EIPS/eip-7864), the tree index should be 32 bytes instead of 31 bytes. ``` def get_tree_key(address: Address32, tree_index: int, sub_index: int): # Assumes STEM_SUBTREE_WIDTH = 256 return tree_hash(address + tree_index.to_bytes(32, "little"))[:31] + bytes( [sub_index] ) ```
This commit is contained in:
parent
344d01e2be
commit
3d05284928
2 changed files with 2 additions and 1 deletions
|
|
@ -308,7 +308,7 @@ func TestVerkleGenesisCommit(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
expected := common.FromHex("19056b480530799a4fdaa9fd9407043b965a3a5c37b4d2a1a9a4f3395a327561")
|
||||
expected := common.FromHex("b94812c1674dcf4f2bc98f4503d15f4cc674265135bcf3be6e4417b60881042a")
|
||||
got := genesis.ToBlock().Root().Bytes()
|
||||
if !bytes.Equal(got, expected) {
|
||||
t.Fatalf("invalid genesis state root, expected %x, got %x", expected, got)
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ func GetBinaryTreeKey(addr common.Address, key []byte) []byte {
|
|||
hasher.Write(zeroHash[:12])
|
||||
hasher.Write(addr[:])
|
||||
hasher.Write(key[:31])
|
||||
hasher.Write([]byte{0})
|
||||
k := hasher.Sum(nil)
|
||||
k[31] = key[31]
|
||||
return k
|
||||
|
|
|
|||
Loading…
Reference in a new issue