mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 05:41:35 +00:00
34 lines
1 KiB
Go
34 lines
1 KiB
Go
package contracts
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
)
|
|
|
|
func getLocSimpleVariable(slot uint64) common.Hash {
|
|
slotHash := common.BigToHash(new(big.Int).SetUint64(slot))
|
|
return slotHash
|
|
}
|
|
|
|
func getLocMappingAtKey(key common.Hash, slot uint64) *big.Int {
|
|
slotHash := common.BigToHash(new(big.Int).SetUint64(slot))
|
|
retByte := crypto.Keccak256(key.Bytes(), slotHash.Bytes())
|
|
ret := new(big.Int)
|
|
ret.SetBytes(retByte)
|
|
return ret
|
|
}
|
|
|
|
func getLocDynamicArrAtElement(slotHash common.Hash, index uint64, elementSize uint64) common.Hash {
|
|
slotKecBig := crypto.Keccak256Hash(slotHash.Bytes()).Big()
|
|
//arrBig = slotKecBig + index * elementSize
|
|
arrBig := slotKecBig.Add(slotKecBig, new(big.Int).SetUint64(index*elementSize))
|
|
return common.BigToHash(arrBig)
|
|
}
|
|
|
|
func getLocFixedArrAtElement(slot uint64, index uint64, elementSize uint64) common.Hash {
|
|
slotBig := new(big.Int).SetUint64(slot)
|
|
arrBig := slotBig.Add(slotBig, new(big.Int).SetUint64(index*elementSize))
|
|
return common.BigToHash(arrBig)
|
|
}
|