-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ eth: calculate slot hash (#88)
Signed-off-by: thanhpp <thanhphanphu18@gmail.com>
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package eth | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
) | ||
|
||
func OverrideSet(stateDiff map[common.Hash]common.Hash, storageSlot int, key common.Hash) { | ||
// for a set the first slot is used to store the array to support enumerable. | ||
// The slot right after it is used to store the map (need to override this map). | ||
OverrideMap(stateDiff, storageSlot+1, key, common.BigToHash(common.Big1)) | ||
} | ||
|
||
func OverrideVariable(stateDiff map[common.Hash]common.Hash, storageSlot int, value common.Hash) { | ||
slotHash := common.BigToHash(big.NewInt(int64(storageSlot))) | ||
stateDiff[slotHash] = value | ||
} | ||
|
||
func OverrideMap(stateDiff map[common.Hash]common.Hash, storageSlot int, key, value common.Hash) { | ||
overrideSlot32 := common.BigToHash(big.NewInt(int64(storageSlot))) | ||
overrideSlotHash := crypto.Keccak256Hash(key[:], overrideSlot32[:]) | ||
stateDiff[overrideSlotHash] = value | ||
} |