Skip to content

Commit

Permalink
don't call Bytes() in GetTreeKey (ethereum#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Oct 31, 2022
1 parent f0e4ab0 commit 85dae8f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions trie/utils/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ func GetTreeKeyCodeSize(address []byte) []byte {
func GetTreeKeyCodeChunk(address []byte, chunk *uint256.Int) []byte {
chunkOffset := new(uint256.Int).Add(CodeOffset, chunk)
treeIndex := new(uint256.Int).Div(chunkOffset, VerkleNodeWidth)
subIndexMod := new(uint256.Int).Mod(chunkOffset, VerkleNodeWidth).Bytes()
subIndexMod := new(uint256.Int).Mod(chunkOffset, VerkleNodeWidth)
var subIndex byte
if len(subIndexMod) != 0 {
subIndex = subIndexMod[0]
subIndex = byte(subIndexMod[0])
}
return GetTreeKey(address, treeIndex, subIndex)
}

func GetTreeKeyCodeChunkWithEvaluatedAddress(addressPoint *verkle.Point, chunk *uint256.Int) []byte {
chunkOffset := new(uint256.Int).Add(CodeOffset, chunk)
treeIndex := new(uint256.Int).Div(chunkOffset, VerkleNodeWidth)
subIndexMod := new(uint256.Int).Mod(chunkOffset, VerkleNodeWidth).Bytes()
subIndexMod := new(uint256.Int).Mod(chunkOffset, VerkleNodeWidth)
var subIndex byte
if len(subIndexMod) != 0 {
subIndex = subIndexMod[0]
subIndex = byte(subIndexMod[0])
}
return getTreeKeyWithEvaluatedAddess(addressPoint, treeIndex, subIndex)
}
Expand All @@ -147,13 +147,13 @@ func GetTreeKeyStorageSlot(address []byte, storageKey *uint256.Int) []byte {

// 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 := new(uint256.Int).Mod(pos, VerkleNodeWidth).Bytes()
subIndexMod := new(uint256.Int).Mod(pos, VerkleNodeWidth)
var subIndex byte
if len(subIndexMod) != 0 {
// uint256 is broken into 4 little-endian quads,
// each with native endianness. Extract the least
// significant byte.
subIndex = subIndexMod[0] & 0xFF
subIndex = byte(subIndexMod[0])
}
return GetTreeKey(address, treeIndex, subIndex)
}
Expand Down Expand Up @@ -230,13 +230,13 @@ func GetTreeKeyStorageSlotWithEvaluatedAddress(evaluated *verkle.Point, storageK
treeIndex := new(uint256.Int).Div(pos, VerkleNodeWidth)
// 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 := new(uint256.Int).Mod(pos, VerkleNodeWidth).Bytes()
subIndexMod := new(uint256.Int).Mod(pos, VerkleNodeWidth)
var subIndex byte
if len(subIndexMod) != 0 {
// uint256 is broken into 4 little-endian quads,
// each with native endianness. Extract the least
// significant byte.
subIndex = subIndexMod[0] & 0xFF
subIndex = byte(subIndexMod[0])
}
return getTreeKeyWithEvaluatedAddess(evaluated, treeIndex, subIndex)
}

0 comments on commit 85dae8f

Please sign in to comment.