diff --git a/core/vm/eips.go b/core/vm/eips.go index 616cd478b4..55a98d5b2a 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -345,11 +345,10 @@ func opExtCodeCopyEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeC self: AccountRef(addr), } paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64()) - if !contract.IsSystemCall { - scope.Contract.UseGas(consumed, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) - if consumed < wanted { - return nil, ErrOutOfGas - } + consumed, wanted := interpreter.evm.AccessEvents.CodeChunksRangeGas(addr, copyOffset, nonPaddedCopyLength, uint64(len(contract.Code)), false, scope.Contract.Gas) + scope.Contract.UseGas(consumed, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) + if consumed < wanted { + return nil, ErrOutOfGas } scope.Memory.Set(memOffset.Uint64(), length.Uint64(), paddedCodeCopy) diff --git a/core/vm/evm.go b/core/vm/evm.go index 265c224400..11716305b4 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -45,6 +45,16 @@ func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) { return p, ok } +func (evm *EVM) isSystemContract(addr common.Address) bool { + switch addr { + case params.BeaconRootsAddress, params.HistoryStorageAddress, params.WithdrawalQueueAddress, + params.ConsolidationQueueAddress, params.SystemAddress: + return true + default: + return false + } +} + // BlockContext provides the EVM with auxiliary information. Once provided // it shouldn't be modified. type BlockContext struct { diff --git a/core/vm/operations_verkle.go b/core/vm/operations_verkle.go index 429abf20cc..065db4f81e 100644 --- a/core/vm/operations_verkle.go +++ b/core/vm/operations_verkle.go @@ -33,9 +33,6 @@ 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) { - if contract.IsSystemCall { - return 0, nil - } address := stack.peek().Bytes20() return evm.AccessEvents.BasicDataGas(address, false, contract.Gas, true), nil } @@ -45,16 +42,10 @@ func gasExtCodeSize4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, if _, isPrecompile := evm.precompile(address); isPrecompile { return 0, nil } - if contract.IsSystemCall { - return 0, nil - } return evm.AccessEvents.BasicDataGas(address, false, contract.Gas, true), nil } func gasExtCodeHash4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { - if contract.IsSystemCall { - return 0, nil - } address := stack.peek().Bytes20() if _, isPrecompile := evm.precompile(address); isPrecompile { return 0, nil @@ -124,7 +115,7 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem if contract.IsSystemCall { return 0, nil } - ontractAddr := contract.Address() + contractAddr := contract.Address() wanted := evm.AccessEvents.BasicDataGas(contractAddr, false, contract.Gas, false) if wanted > contract.Gas { return wanted, nil @@ -173,7 +164,6 @@ func gasCodeCopyEip4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, if err != nil { return 0, err } - _, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(contract.Code, uint64CodeOffset, length.Uint64()) if !contract.IsDeployment && !contract.IsSystemCall { var ( codeOffset = stack.Back(1) @@ -198,9 +188,8 @@ func gasExtCodeCopyEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memo return 0, err } addr := common.Address(stack.peek().Bytes20()) - isSystemContract := evm.isSystemContract(addr) _, isPrecompile := evm.precompile(addr) - if isPrecompile || contract.isSystemCall { + if isPrecompile || evm.isSystemContract(addr) { var overflow bool if gas, overflow = math.SafeAdd(gas, params.WarmStorageReadCostEIP2929); overflow { return 0, ErrGasUintOverflow