diff --git a/core/state/access_witness.go b/core/state/access_witness.go index 4a0c29111995..0be2f5a3a9d7 100644 --- a/core/state/access_witness.go +++ b/core/state/access_witness.go @@ -142,9 +142,14 @@ func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) { } } -func (aw *AccessWitness) TouchTxExistingAndComputeGas(targetAddr []byte, sendsValue bool) { - aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, sendsValue, nil) - aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.CodeHashLeafKey, false, nil) +func (aw *AccessWitness) TouchTxTarget(targetAddr []byte) { + aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, true, nil) + // Note that we do a write-event in CodeHash without distinguishing if the tx target account + // exists or not. Pre-7702, there's no situation in which an existing codeHash can be mutated, thus + // doing a write-event shouldn't cause an observable difference in gas usage. + // TODO(7702): re-check this in the spec and implementation to be sure is a correct solution after + // EIP-7702 is implemented. + aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.CodeHashLeafKey, true, nil) } func (aw *AccessWitness) TouchSlotAndChargeGas(addr []byte, slot common.Hash, isWrite bool, useGasFn UseGasFn, warmCostCharging bool) bool { diff --git a/core/state_transition.go b/core/state_transition.go index 45a736d5e189..75d5c29573ce 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -396,7 +396,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.evm.Accesses.TouchTxOriginAndComputeGas(originAddr.Bytes()) if msg.To != nil { - st.evm.Accesses.TouchTxExistingAndComputeGas(targetAddr.Bytes(), msg.Value.Sign() != 0) + st.evm.Accesses.TouchTxTarget(targetAddr.Bytes()) // ensure the code size ends up in the access witness st.evm.StateDB.GetCodeSize(*targetAddr) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 3a20e8c4f998..912b9c583eeb 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -352,7 +352,8 @@ func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) address := slot.Bytes20() cs := uint64(interpreter.evm.StateDB.GetCodeSize(address)) if interpreter.evm.chainRules.IsVerkle { - if _, isPrecompile := interpreter.evm.precompile(address); isPrecompile { + isSystemContract := interpreter.evm.isSystemContract(address) + if _, isPrecompile := interpreter.evm.precompile(address); isPrecompile || isSystemContract { if !scope.Contract.UseGas(params.WarmStorageReadCostEIP2929) { return nil, ErrOutOfGas } @@ -407,7 +408,8 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) if interpreter.evm.chainRules.IsVerkle { addr := common.Address(a.Bytes20()) - if _, isPrecompile := interpreter.evm.precompile(addr); isPrecompile { + isSystemContract := interpreter.evm.isSystemContract(addr) + if _, isPrecompile := interpreter.evm.precompile(addr); isPrecompile || isSystemContract { if !scope.Contract.UseGas(params.WarmStorageReadCostEIP2929) { return nil, ErrOutOfGas }