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

fix calculation in get_tree_key_for_storage_slot #35

Merged
Merged
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
10 changes: 7 additions & 3 deletions trie/utils/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
CodeOffset = uint256.NewInt(128)
MainStorageOffset = new(uint256.Int).Lsh(uint256.NewInt(256), 31)
VerkleNodeWidth = uint256.NewInt(8)
codeStorageDelta = uint256.NewInt(0).Sub(HeaderStorageOffset, CodeOffset)
codeStorageDelta = uint256.NewInt(0).Sub(CodeOffset, HeaderStorageOffset)
)

func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte {
Expand Down Expand Up @@ -94,10 +94,14 @@ func GetTreeKeyStorageSlot(address []byte, storageKey *uint256.Int) []byte {
treeIndex.Add(MainStorageOffset, storageKey)
}
treeIndex.Div(treeIndex, VerkleNodeWidth)
subIndexMod := new(uint256.Int).Mod(treeIndex, VerkleNodeWidth).Bytes()

// calculate the sub_index, i.e. the index in the stem tree.
// Because the modulus is 256, it's the last byte of treeIndex
subIndexMod := treeIndex.Bytes()
var subIndex byte
if len(subIndexMod) != 0 {
subIndex = subIndexMod[0]
// Get the last byte, as uint256.Int is big-endian
subIndex = subIndexMod[len(subIndexMod)-1]
}
return GetTreeKey(address, treeIndex, subIndex)
}