diff --git a/core/state_transition.go b/core/state_transition.go index 1e39dee6569e..19e52d8e0c71 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -304,7 +304,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { if st.gas < gas { return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gas, gas) } - if st.evm.Accesses != nil { + if st.evm.ChainConfig().IsCancun(st.evm.Context.BlockNumber) { if msg.To() != nil { toBalance := trieUtils.GetTreeKeyBalance(msg.To().Bytes()) pre := st.state.GetBalance(*msg.To()) diff --git a/core/vm/evm.go b/core/vm/evm.go index c8ecc89ce5aa..41a7062ba81f 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -243,7 +243,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas if len(code) == 0 { ret, err = nil, nil // gas is unchanged } else { - if evm.Accesses != nil { + if evm.chainConfig.IsCancun(evm.Context.BlockNumber) { // Touch the account data var data [32]byte evm.Accesses.TouchAddress(utils.GetTreeKeyVersion(addr.Bytes()), data[:]) diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index 72873c84a1dd..89ed80e63b62 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -97,7 +97,7 @@ var ( func gasExtCodeSize(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { usedGas := uint64(0) slot := stack.Back(0) - if evm.Accesses != nil { + if evm.chainConfig.IsCancun(evm.Context.BlockNumber) { index := trieUtils.GetTreeKeyCodeSize(slot.Bytes()) usedGas += evm.TxContext.Accesses.TouchAddressAndChargeGas(index, nil) } @@ -107,7 +107,7 @@ func gasExtCodeSize(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem func gasCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { var statelessGas uint64 - if evm.Accesses != nil { + if evm.chainConfig.IsCancun(evm.Context.BlockNumber) { var ( codeOffset = stack.Back(1) length = stack.Back(2) @@ -129,7 +129,7 @@ func gasCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory func gasExtCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { var statelessGas uint64 - if evm.Accesses != nil { + if evm.chainConfig.IsCancun(evm.Context.BlockNumber) { var ( codeOffset = stack.Back(2) length = stack.Back(3) @@ -158,7 +158,7 @@ func gasExtCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem func gasSLoad(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { usedGas := uint64(0) - if evm.Accesses != nil { + if evm.chainConfig.IsCancun(evm.Context.BlockNumber) { where := stack.Back(0) addr := contract.Address() index := trieUtils.GetTreeKeyStorageSlot(addr[:], where) @@ -408,7 +408,7 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize transfersValue = !stack.Back(2).IsZero() address = common.Address(stack.Back(1).Bytes20()) ) - if evm.Accesses != nil { + if evm.chainConfig.IsCancun(evm.Context.BlockNumber) { // Charge witness costs for i := trieUtils.VersionLeafKey; i <= trieUtils.CodeSizeLeafKey; i++ { index := trieUtils.GetTreeKeyAccountLeaf(address[:], byte(i)) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 9767c25c2f27..abfa890274d8 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -343,7 +343,7 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { slot := scope.Stack.peek() cs := uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())) - if interpreter.evm.Accesses != nil { + if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) { index := trieUtils.GetTreeKeyCodeSize(slot.Bytes()) statelessGas := interpreter.evm.Accesses.TouchAddressAndChargeGas(index, uint256.NewInt(cs).Bytes()) scope.Contract.UseGas(statelessGas) @@ -371,7 +371,7 @@ func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([ } paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(scope.Contract.Code, uint64CodeOffset, length.Uint64()) - if interpreter.evm.Accesses != nil { + if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) { touchEachChunksAndChargeGas(copyOffset, nonPaddedCopyLength, scope.Contract.Address().Bytes()[:], scope.Contract.Code, scope.Contract, interpreter.evm.Accesses) } scope.Memory.Set(memOffset.Uint64(), uint64(len(paddedCodeCopy)), paddedCodeCopy) @@ -466,7 +466,7 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) uint64CodeOffset = 0xffffffffffffffff } addr := common.Address(a.Bytes20()) - if interpreter.evm.Accesses != nil { + if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) { code := interpreter.evm.StateDB.GetCode(addr) paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64()) cb := codeBitmap(code) @@ -604,7 +604,7 @@ func opSload(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by val := interpreter.evm.StateDB.GetState(scope.Contract.Address(), hash) loc.SetBytes(val.Bytes()) - if interpreter.evm.Accesses != nil { + if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) { index := trieUtils.GetTreeKeyStorageSlot(scope.Contract.Address().Bytes(), loc) interpreter.evm.Accesses.TouchAddressAndChargeGas(index, val.Bytes()) } @@ -933,7 +933,7 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by if *pc < codeLen { scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc]))) - if interpreter.evm.Accesses != nil && *pc%31 == 0 { + if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) && *pc%31 == 0 { // touch next chunk if PUSH1 is at the boundary. if so, *pc has // advanced past this boundary. @@ -975,7 +975,7 @@ func makePush(size uint64, pushByteSize int) executionFunc { endMin = startMin + pushByteSize } - if interpreter.evm.Accesses != nil { + if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) { statelessGas := touchEachChunksAndChargeGas(uint64(startMin), uint64(pushByteSize), scope.Contract.Address().Bytes()[:], scope.Contract.Code, scope.Contract, interpreter.evm.Accesses) scope.Contract.UseGas(statelessGas) } diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 25dfd684ff1a..98a3aa56d115 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -191,7 +191,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( logged, pcCopy, gasCopy = false, pc, contract.Gas } - if in.evm.TxContext.Accesses != nil && !contract.IsDeployment { + if in.evm.ChainConfig().IsCancun(in.evm.Context.BlockNumber) && !contract.IsDeployment { // if the PC ends up in a new "page" of verkleized code, charge the // associated witness costs. contract.Gas -= touchEachChunksAndChargeGas(pc, 1, contract.Address().Bytes()[:], contract.Code, contract, in.evm.TxContext.Accesses)