rename AccessWitness to AccessEvents

This commit is contained in:
Guillaume Ballet 2024-04-29 11:24:40 +02:00
parent c65d117a92
commit 4030cdd81f
10 changed files with 82 additions and 82 deletions

View file

@ -364,7 +364,7 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.
// Add the balance of each withdrawal to the witness, no gas will
// be charged.
if chain.Config().IsEIP4762(header.Number, header.Time) {
state.Witness().BalanceGas(w.Address[:], true)
state.AccessEvents().BalanceGas(w.Address[:], true)
}
}
// No block reward which is issued by consensus layer instead.

View file

@ -37,27 +37,27 @@ const (
var zeroTreeIndex uint256.Int
// AccessWitness lists the locations of the state that are being accessed
// AccessEvents lists the locations of the state that are being accessed
// during the production of a block.
type AccessWitness struct {
type AccessEvents struct {
branches map[branchAccessKey]mode
chunks map[chunkAccessKey]mode
pointCache *utils.PointCache
}
func NewAccessWitness(pointCache *utils.PointCache) *AccessWitness {
return &AccessWitness{
func NewAccessEvents(pointCache *utils.PointCache) *AccessEvents {
return &AccessEvents{
branches: make(map[branchAccessKey]mode),
chunks: make(map[chunkAccessKey]mode),
pointCache: pointCache,
}
}
// Merge is used to merge the witness that got generated during the execution
// of a tx, with the accumulation of witnesses that were generated during the
// execution of all the txs preceding this one in a given block.
func (aw *AccessWitness) Merge(other *AccessWitness) {
// Merge is used to merge the access events that were generated during the
// execution of a tx, with the accumulation of all access events that were
// generated during the execution of all txs preceding this one in a block.
func (aw *AccessEvents) Merge(other *AccessEvents) {
for k := range other.branches {
aw.branches[k] |= other.branches[k]
}
@ -68,7 +68,7 @@ func (aw *AccessWitness) Merge(other *AccessWitness) {
// Key returns, predictably, the list of keys that were touched during the
// buildup of the access witness.
func (aw *AccessWitness) Keys() [][]byte {
func (aw *AccessEvents) Keys() [][]byte {
// TODO: consider if parallelizing this is worth it, probably depending on len(aw.chunks).
keys := make([][]byte, 0, len(aw.chunks))
for chunk := range aw.chunks {
@ -79,8 +79,8 @@ func (aw *AccessWitness) Keys() [][]byte {
return keys
}
func (aw *AccessWitness) Copy() *AccessWitness {
naw := &AccessWitness{
func (aw *AccessEvents) Copy() *AccessEvents {
naw := &AccessEvents{
branches: make(map[branchAccessKey]mode),
chunks: make(map[chunkAccessKey]mode),
pointCache: aw.pointCache,
@ -91,7 +91,7 @@ func (aw *AccessWitness) Copy() *AccessWitness {
// AddAccount returns the gas to be charged for each of the currently cold
// member fields of an account.
func (aw *AccessWitness) AddAccount(addr []byte, isWrite bool) uint64 {
func (aw *AccessEvents) AddAccount(addr []byte, isWrite bool) uint64 {
var gas uint64
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
gas += aw.touchAddressAndChargeGas(addr, zeroTreeIndex, byte(i), isWrite)
@ -102,7 +102,7 @@ func (aw *AccessWitness) AddAccount(addr []byte, isWrite bool) uint64 {
// MessageCallGas returns the gas to be charged for each of the currently
// cold member fields of an account, that need to be touched when making a message
// call to that account.
func (aw *AccessWitness) MessageCallGas(destination []byte) uint64 {
func (aw *AccessEvents) MessageCallGas(destination []byte) uint64 {
var gas uint64
gas += aw.touchAddressAndChargeGas(destination, zeroTreeIndex, utils.VersionLeafKey, false)
gas += aw.touchAddressAndChargeGas(destination, zeroTreeIndex, utils.CodeSizeLeafKey, false)
@ -111,7 +111,7 @@ func (aw *AccessWitness) MessageCallGas(destination []byte) uint64 {
// ValueTransferGas returns the gas to be charged for each of the currently
// cold balance member fields of the caller and the callee accounts.
func (aw *AccessWitness) ValueTransferGas(callerAddr, targetAddr []byte) uint64 {
func (aw *AccessEvents) ValueTransferGas(callerAddr, targetAddr []byte) uint64 {
var gas uint64
gas += aw.touchAddressAndChargeGas(callerAddr, zeroTreeIndex, utils.BalanceLeafKey, true)
gas += aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BalanceLeafKey, true)
@ -120,7 +120,7 @@ func (aw *AccessWitness) ValueTransferGas(callerAddr, targetAddr []byte) uint64
// ContractCreateInitGas returns the access gas costs for the initialization of
// a contract creation.
func (aw *AccessWitness) ContractCreateInitGas(addr []byte, createSendsValue bool) uint64 {
func (aw *AccessEvents) ContractCreateInitGas(addr []byte, createSendsValue bool) uint64 {
var gas uint64
gas += aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.VersionLeafKey, true)
gas += aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.NonceLeafKey, true)
@ -132,7 +132,7 @@ func (aw *AccessWitness) ContractCreateInitGas(addr []byte, createSendsValue boo
// AddTxOrigin adds the member fields of the sender account to the witness,
// so that cold accesses are not charged, since they are covered by the 21000 gas.
func (aw *AccessWitness) AddTxOrigin(originAddr []byte) {
func (aw *AccessEvents) AddTxOrigin(originAddr []byte) {
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
aw.touchAddressAndChargeGas(originAddr, zeroTreeIndex, byte(i), i == utils.BalanceLeafKey || i == utils.NonceLeafKey)
}
@ -140,21 +140,21 @@ func (aw *AccessWitness) AddTxOrigin(originAddr []byte) {
// AddTxDestination adds the member fields of the sender account to the witness,
// so that cold accesses are not charged, since they are covered by the 21000 gas.
func (aw *AccessWitness) AddTxDestination(targetAddr []byte, sendsValue bool) {
func (aw *AccessEvents) AddTxDestination(targetAddr []byte, sendsValue bool) {
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, byte(i), i == utils.VersionLeafKey && sendsValue)
}
}
// SlotGas returns the amount of gas to be charged for a cold storage access.
func (aw *AccessWitness) SlotGas(addr []byte, slot common.Hash, isWrite bool) uint64 {
func (aw *AccessEvents) SlotGas(addr []byte, slot common.Hash, isWrite bool) uint64 {
treeIndex, subIndex := utils.StorageIndex(slot.Bytes())
return aw.touchAddressAndChargeGas(addr, *treeIndex, subIndex, isWrite)
}
// touchAddressAndChargeGas adds any missing access event to the witness, and returns the cold
// access cost to be charged, if need be.
func (aw *AccessWitness) touchAddressAndChargeGas(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) uint64 {
func (aw *AccessEvents) touchAddressAndChargeGas(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) uint64 {
stemRead, selectorRead, stemWrite, selectorWrite, selectorFill := aw.touchAddress(addr, treeIndex, subIndex, isWrite)
var gas uint64
@ -178,7 +178,7 @@ func (aw *AccessWitness) touchAddressAndChargeGas(addr []byte, treeIndex uint256
}
// touchAddress adds any missing access event to the witness.
func (aw *AccessWitness) touchAddress(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) (bool, bool, bool, bool, bool) {
func (aw *AccessEvents) touchAddress(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) (bool, bool, bool, bool, bool) {
branchKey := newBranchAccessKey(addr, treeIndex)
chunkKey := newChunkAccessKey(branchKey, subIndex)
@ -238,7 +238,7 @@ func newChunkAccessKey(branchKey branchAccessKey, leafKey byte) chunkAccessKey {
}
// touchCodeChunksRangeOnReadAndChargeGas is a helper function to touch every chunk in a code range and charge witness gas costs
func (aw *AccessWitness) CodeChunksRangeGas(contractAddr []byte, startPC, size uint64, codeLen uint64, isWrite bool) uint64 {
func (aw *AccessEvents) CodeChunksRangeGas(contractAddr []byte, startPC, size uint64, codeLen uint64, isWrite bool) uint64 {
// note that in the case where the copied code is outside the range of the
// contract code but touches the last leaf with contract code in it,
// we don't include the last leaf of code in the AccessWitness. The
@ -272,22 +272,22 @@ func (aw *AccessWitness) CodeChunksRangeGas(contractAddr []byte, startPC, size u
return statelessGasCharged
}
func (aw *AccessWitness) VersionGas(addr []byte, isWrite bool) uint64 {
func (aw *AccessEvents) VersionGas(addr []byte, isWrite bool) uint64 {
return aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.VersionLeafKey, isWrite)
}
func (aw *AccessWitness) BalanceGas(addr []byte, isWrite bool) uint64 {
func (aw *AccessEvents) BalanceGas(addr []byte, isWrite bool) uint64 {
return aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BalanceLeafKey, isWrite)
}
func (aw *AccessWitness) NonceGas(addr []byte, isWrite bool) uint64 {
func (aw *AccessEvents) NonceGas(addr []byte, isWrite bool) uint64 {
return aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.NonceLeafKey, isWrite)
}
func (aw *AccessWitness) CodeSizeGas(addr []byte, isWrite bool) uint64 {
func (aw *AccessEvents) CodeSizeGas(addr []byte, isWrite bool) uint64 {
return aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeSizeLeafKey, isWrite)
}
func (aw *AccessWitness) CodeHashGas(addr []byte, isWrite bool) uint64 {
func (aw *AccessEvents) CodeHashGas(addr []byte, isWrite bool) uint64 {
return aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeKeccakLeafKey, isWrite)
}

View file

@ -140,8 +140,8 @@ type StateDB struct {
// Transient storage
transientStorage transientStorage
// Verkle witness
witness *AccessWitness
// State access events, used for Verkle tries/EIP4762
accessEvents *AccessEvents
// Journal of state modifications. This is the backbone of
// Snapshot and RevertToSnapshot.
@ -198,7 +198,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
hasher: crypto.NewKeccakState(),
}
if tr.IsVerkle() {
sdb.witness = sdb.NewAccessWitness()
sdb.accessEvents = sdb.NewAccessEvents()
}
if sdb.snaps != nil {
sdb.snap = sdb.snaps.Snapshot(root)
@ -206,19 +206,19 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
return sdb, nil
}
func (s *StateDB) NewAccessWitness() *AccessWitness {
return NewAccessWitness(utils.NewPointCache(100))
func (s *StateDB) NewAccessEvents() *AccessEvents {
return NewAccessEvents(utils.NewPointCache(100))
}
func (s *StateDB) Witness() *AccessWitness {
if s.witness == nil {
s.witness = s.NewAccessWitness()
func (s *StateDB) AccessEvents() *AccessEvents {
if s.accessEvents == nil {
s.accessEvents = s.NewAccessEvents()
}
return s.witness
return s.accessEvents
}
func (s *StateDB) SetWitness(aw *AccessWitness) {
s.witness = aw
func (s *StateDB) SetAccessEvents(ae *AccessEvents) {
s.accessEvents = ae
}
// SetLogger sets the logger for account update hooks.

View file

@ -120,7 +120,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
}
// Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(msg)
txContext.Accesses = statedb.NewAccessWitness()
txContext.AccessEvents = statedb.NewAccessEvents()
evm.Reset(txContext, statedb)
// Apply the transaction to the current state (included in the env).
@ -159,8 +159,8 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
}
if statedb.Witness() != nil {
statedb.Witness().Merge(txContext.Accesses)
if statedb.AccessEvents() != nil {
statedb.AccessEvents().Merge(txContext.AccessEvents)
}
// Set the receipt logs and create the bloom filter.
@ -209,7 +209,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
}
_, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560)
if vmenv.ChainConfig().Rules(vmenv.Context.BlockNumber, true, vmenv.Context.Time).IsEIP4762 {
statedb.Witness().Merge(txctx.Accesses)
statedb.AccessEvents().Merge(txctx.AccessEvents)
}
statedb.Finalise(true)
}

View file

@ -422,10 +422,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
targetAddr := msg.To
originAddr := msg.From
st.evm.Accesses.AddTxOrigin(originAddr.Bytes())
st.evm.AccessEvents.AddTxOrigin(originAddr.Bytes())
if msg.To != nil {
st.evm.Accesses.AddTxDestination(targetAddr.Bytes(), msg.Value.Sign() != 0)
st.evm.AccessEvents.AddTxDestination(targetAddr.Bytes(), msg.Value.Sign() != 0)
// ensure the code size ends up in the access witness
st.evm.StateDB.GetCodeSize(*targetAddr)
@ -488,7 +488,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// add the coinbase to the witness iff the fee is greater than 0
if rules.IsEIP4762 && fee.Sign() != 0 {
st.evm.Accesses.BalanceGas(st.evm.Context.Coinbase[:], true)
st.evm.AccessEvents.BalanceGas(st.evm.Context.Coinbase[:], true)
}
}

View file

@ -331,7 +331,7 @@ func opCreateEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContex
var endowment = scope.Stack.peek()
contractAddress := crypto.CreateAddress(scope.Contract.Address(), interpreter.evm.StateDB.GetNonce(scope.Contract.Address()))
statelessGas := interpreter.evm.Accesses.ContractCreateInitGas(contractAddress.Bytes()[:], endowment.Sign() != 0)
statelessGas := interpreter.evm.AccessEvents.ContractCreateInitGas(contractAddress.Bytes()[:], endowment.Sign() != 0)
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
return nil, ErrExecutionReverted
}
@ -352,7 +352,7 @@ func opCreate2EIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte
codeAndHash := &codeAndHash{code: input}
contractAddress := crypto.CreateAddress2(scope.Contract.Address(), salt.Bytes32(), codeAndHash.Hash().Bytes())
statelessGas := interpreter.evm.Accesses.ContractCreateInitGas(contractAddress.Bytes()[:], endowment.Sign() != 0)
statelessGas := interpreter.evm.AccessEvents.ContractCreateInitGas(contractAddress.Bytes()[:], endowment.Sign() != 0)
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
return nil, ErrExecutionReverted
}
@ -379,7 +379,7 @@ func opExtCodeCopyEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeC
self: AccountRef(addr),
}
paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64())
statelessGas := interpreter.evm.Accesses.CodeChunksRangeGas(addr[:], copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false)
statelessGas := interpreter.evm.AccessEvents.CodeChunksRangeGas(addr[:], copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false)
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
scope.Contract.Gas = 0
return nil, ErrOutOfGas
@ -403,7 +403,7 @@ func opPush1EIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
// touch next chunk if PUSH1 is at the boundary. if so, *pc has
// advanced past this boundary.
contractAddr := scope.Contract.Address()
statelessGas := interpreter.evm.Accesses.CodeChunksRangeGas(contractAddr[:], *pc+1, uint64(1), uint64(len(scope.Contract.Code)), false)
statelessGas := interpreter.evm.AccessEvents.CodeChunksRangeGas(contractAddr[:], *pc+1, uint64(1), uint64(len(scope.Contract.Code)), false)
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
scope.Contract.Gas = 0
return nil, ErrOutOfGas
@ -431,7 +431,7 @@ func makePushEIP4762(size uint64, pushByteSize int) executionFunc {
if !scope.Contract.IsDeployment {
contractAddr := scope.Contract.Address()
statelessGas := interpreter.evm.Accesses.CodeChunksRangeGas(contractAddr[:], uint64(start), uint64(pushByteSize), uint64(len(scope.Contract.Code)), false)
statelessGas := interpreter.evm.AccessEvents.CodeChunksRangeGas(contractAddr[:], uint64(start), uint64(pushByteSize), uint64(len(scope.Contract.Code)), false)
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
scope.Contract.Gas = 0
return nil, ErrOutOfGas

View file

@ -86,11 +86,11 @@ type BlockContext struct {
// All fields can change between transactions.
type TxContext struct {
// Message information
Origin common.Address // Provides information for ORIGIN
GasPrice *big.Int // Provides information for GASPRICE (and is used to zero the basefee if NoBaseFee is set)
BlobHashes []common.Hash // Provides information for BLOBHASH
BlobFeeCap *big.Int // Is used to zero the blobbasefee if NoBaseFee is set
Accesses *state.AccessWitness // Capture all state accesses for this tx
Origin common.Address // Provides information for ORIGIN
GasPrice *big.Int // Provides information for GASPRICE (and is used to zero the basefee if NoBaseFee is set)
BlobHashes []common.Hash // Provides information for BLOBHASH
BlobFeeCap *big.Int // Is used to zero the blobbasefee if NoBaseFee is set
AccessEvents *state.AccessEvents // Capture all state accesses for this tx
}
// EVM is the Ethereum Virtual Machine base object and provides
@ -151,8 +151,8 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
chainConfig: chainConfig,
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),
}
if txCtx.Accesses == nil && chainConfig.IsPrague(blockCtx.BlockNumber, blockCtx.Time) {
evm.Accesses = evm.StateDB.(*state.StateDB).NewAccessWitness()
if txCtx.AccessEvents == nil && chainConfig.IsPrague(blockCtx.BlockNumber, blockCtx.Time) {
evm.AccessEvents = evm.StateDB.(*state.StateDB).NewAccessEvents()
}
evm.interpreter = NewEVMInterpreter(evm)
return evm
@ -161,8 +161,8 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
// Reset resets the EVM with a new transaction context.Reset
// This is not threadsafe and should only be done very cautiously.
func (evm *EVM) Reset(txCtx TxContext, statedb StateDB) {
if txCtx.Accesses == nil && evm.chainRules.IsPrague {
txCtx.Accesses = evm.StateDB.(*state.StateDB).NewAccessWitness()
if txCtx.AccessEvents == nil && evm.chainRules.IsPrague {
txCtx.AccessEvents = evm.StateDB.(*state.StateDB).NewAccessEvents()
}
evm.TxContext = txCtx
evm.StateDB = statedb
@ -211,7 +211,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
if !evm.StateDB.Exist(addr) {
if !isPrecompile && evm.chainRules.IsEIP4762 {
// add proof of absence to witness
wgas := evm.Accesses.AddAccount(addr.Bytes(), false)
wgas := evm.AccessEvents.AddAccount(addr.Bytes(), false)
if gas < wgas {
evm.StateDB.RevertToSnapshot(snapshot)
return nil, 0, ErrOutOfGas
@ -504,7 +504,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
// Charge the contract creation init gas in verkle mode
if evm.chainRules.IsEIP4762 {
if !contract.UseGas(evm.Accesses.ContractCreateInitGas(address.Bytes(), value.Sign() != 0), evm.Config.Tracer, tracing.GasChangeWitnessContractInit) {
if !contract.UseGas(evm.AccessEvents.ContractCreateInitGas(address.Bytes(), value.Sign() != 0), evm.Config.Tracer, tracing.GasChangeWitnessContractInit) {
err = ErrOutOfGas
}
}
@ -535,11 +535,11 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}
} else {
// Contract creation completed, touch the missing fields in the contract
if !contract.UseGas(evm.Accesses.AddAccount(address.Bytes()[:], true), evm.Config.Tracer, tracing.GasChangeWitnessContractCreation) {
if !contract.UseGas(evm.AccessEvents.AddAccount(address.Bytes()[:], true), evm.Config.Tracer, tracing.GasChangeWitnessContractCreation) {
err = ErrCodeStoreOutOfGas
}
if err == nil && len(ret) > 0 && !contract.UseGas(evm.Accesses.CodeChunksRangeGas(address.Bytes(), 0, uint64(len(ret)), uint64(len(ret)), true), evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk) {
if err == nil && len(ret) > 0 && !contract.UseGas(evm.AccessEvents.CodeChunksRangeGas(address.Bytes(), 0, uint64(len(ret)), uint64(len(ret)), true), evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk) {
err = ErrCodeStoreOutOfGas
}
}

View file

@ -404,7 +404,7 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
}
if evm.chainRules.IsEIP4762 {
if transfersValue {
gas, overflow = math.SafeAdd(gas, evm.Accesses.ValueTransferGas(contract.Address().Bytes()[:], address.Bytes()[:]))
gas, overflow = math.SafeAdd(gas, evm.AccessEvents.ValueTransferGas(contract.Address().Bytes()[:], address.Bytes()[:]))
if overflow {
return 0, ErrGasUintOverflow
}
@ -440,7 +440,7 @@ func gasCallCode(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory
address := common.Address(stack.Back(1).Bytes20())
transfersValue := !stack.Back(2).IsZero()
if transfersValue {
gas, overflow = math.SafeAdd(gas, evm.Accesses.ValueTransferGas(contract.Address().Bytes()[:], address.Bytes()[:]))
gas, overflow = math.SafeAdd(gas, evm.AccessEvents.ValueTransferGas(contract.Address().Bytes()[:], address.Bytes()[:]))
if overflow {
return 0, ErrGasUintOverflow
}

View file

@ -227,7 +227,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// if the PC ends up in a new "chunk" of verkleized code, charge the
// associated costs.
contractAddr := contract.Address()
contract.Gas -= in.evm.TxContext.Accesses.CodeChunksRangeGas(contractAddr[:], pc, 1, uint64(len(contract.Code)), false)
contract.Gas -= in.evm.TxContext.AccessEvents.CodeChunksRangeGas(contractAddr[:], pc, 1, uint64(len(contract.Code)), false)
}
// Get the operation from the jump table and validate the stack to ensure there are

View file

@ -23,7 +23,7 @@ import (
)
func gasSStore4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas := evm.Accesses.SlotGas(contract.Address().Bytes(), common.Hash(stack.peek().Bytes32()), true)
gas := evm.AccessEvents.SlotGas(contract.Address().Bytes(), common.Hash(stack.peek().Bytes32()), true)
if gas == 0 {
gas = params.WarmStorageReadCostEIP2929
}
@ -31,7 +31,7 @@ func gasSStore4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memo
}
func gasSLoad4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas := evm.Accesses.SlotGas(contract.Address().Bytes(), common.Hash(stack.peek().Bytes32()), false)
gas := evm.AccessEvents.SlotGas(contract.Address().Bytes(), common.Hash(stack.peek().Bytes32()), false)
if gas == 0 {
gas = params.WarmStorageReadCostEIP2929
}
@ -40,7 +40,7 @@ func gasSLoad4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memor
func gasBalance4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
address := stack.peek().Bytes20()
gas := evm.Accesses.BalanceGas(address[:], false)
gas := evm.AccessEvents.BalanceGas(address[:], false)
if gas == 0 {
gas = params.WarmStorageReadCostEIP2929
}
@ -52,8 +52,8 @@ func gasExtCodeSize4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
if _, isPrecompile := evm.precompile(address); isPrecompile {
return 0, nil
}
wgas := evm.Accesses.VersionGas(address[:], false)
wgas += evm.Accesses.CodeSizeGas(address[:], false)
wgas := evm.AccessEvents.VersionGas(address[:], false)
wgas += evm.AccessEvents.CodeSizeGas(address[:], false)
if wgas == 0 {
wgas = params.WarmStorageReadCostEIP2929
}
@ -65,7 +65,7 @@ func gasExtCodeHash4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
if _, isPrecompile := evm.precompile(address); isPrecompile {
return 0, nil
}
codehashgas := evm.Accesses.CodeHashGas(address[:], false)
codehashgas := evm.AccessEvents.CodeHashGas(address[:], false)
if codehashgas == 0 {
codehashgas = params.WarmStorageReadCostEIP2929
}
@ -81,7 +81,7 @@ func makeCallVariantGasEIP4762(oldCalculator gasFunc) gasFunc {
if _, isPrecompile := evm.precompile(contract.Address()); isPrecompile {
return gas, nil
}
wgas := evm.Accesses.MessageCallGas(contract.Address().Bytes())
wgas := evm.AccessEvents.MessageCallGas(contract.Address().Bytes())
if wgas == 0 {
wgas = params.WarmStorageReadCostEIP2929
}
@ -102,17 +102,17 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem
return 0, nil
}
contractAddr := contract.Address()
statelessGas := evm.Accesses.VersionGas(contractAddr[:], false)
statelessGas += evm.Accesses.CodeSizeGas(contractAddr[:], false)
statelessGas += evm.Accesses.BalanceGas(contractAddr[:], false)
statelessGas := evm.AccessEvents.VersionGas(contractAddr[:], false)
statelessGas += evm.AccessEvents.CodeSizeGas(contractAddr[:], false)
statelessGas += evm.AccessEvents.BalanceGas(contractAddr[:], false)
if contractAddr != beneficiaryAddr {
statelessGas += evm.Accesses.BalanceGas(beneficiaryAddr[:], false)
statelessGas += evm.AccessEvents.BalanceGas(beneficiaryAddr[:], false)
}
// Charge write costs if it transfers value
if evm.StateDB.GetBalance(contractAddr).Sign() != 0 {
statelessGas += evm.Accesses.BalanceGas(contractAddr[:], true)
statelessGas += evm.AccessEvents.BalanceGas(contractAddr[:], true)
if contractAddr != beneficiaryAddr {
statelessGas += evm.Accesses.BalanceGas(beneficiaryAddr[:], true)
statelessGas += evm.AccessEvents.BalanceGas(beneficiaryAddr[:], true)
}
}
return statelessGas, nil
@ -133,7 +133,7 @@ func gasCodeCopyEip4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
}
_, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(contract.Code, uint64CodeOffset, length.Uint64())
if !contract.IsDeployment {
gas += evm.Accesses.CodeChunksRangeGas(contract.Address().Bytes(), copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false)
gas += evm.AccessEvents.CodeChunksRangeGas(contract.Address().Bytes(), copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false)
}
return gas, nil
}
@ -145,8 +145,8 @@ func gasExtCodeCopyEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memo
return 0, err
}
addr := common.Address(stack.peek().Bytes20())
wgas := evm.Accesses.VersionGas(addr[:], false)
wgas += evm.Accesses.CodeSizeGas(addr[:], false)
wgas := evm.AccessEvents.VersionGas(addr[:], false)
wgas += evm.AccessEvents.CodeSizeGas(addr[:], false)
if wgas == 0 {
wgas = params.WarmStorageReadCostEIP2929
}