From 3462394cb55bc4b7669e2e2ccd3d50d2521c9fcd Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Fri, 10 Jul 2026 16:39:54 +0800 Subject: [PATCH] core: remove unused creation flag --- core/state_transition.go | 6 +++--- core/vm/evm.go | 22 +++++++++------------- core/vm/instructions.go | 4 ++-- core/vm/runtime/runtime.go | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 0a1a72fcd1..1cce3a38cd 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -800,12 +800,12 @@ func (st *stateTransition) executeCreate(rules params.Rules, value *uint256.Int) } // The first frame is entered with the gas remaining after the runtime // charges. - ret, _, result, creation, vmerr := st.evm.Create(msg.From, msg.Data, st.gasRemaining.ForwardAll(), value) + ret, _, result, vmerr := st.evm.Create(msg.From, msg.Data, st.gasRemaining.ForwardAll(), value) st.gasRemaining.Absorb(result) - // If the contract creation failed (e.g. the initcode reverted), + // If the contract creation failed (e.g. the initcode reverted or halted), // refill the account-creation state gas charged at runtime. - if rules.IsAmsterdam && chargedCreation && !creation { + if rules.IsAmsterdam && chargedCreation && vmerr != nil { st.gasRemaining.RefundState(params.AccountCreationSize * st.evm.Context.CostPerStateByte) } // If the top-most frame halted, drain the leftover regular gas rather diff --git a/core/vm/evm.go b/core/vm/evm.go index 72d22f10e8..49660b19bd 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -520,7 +520,7 @@ func (evm *EVM) chargeAccountCreation(scope *ScopeContext, contractAddr common.A } // create creates a new contract using code as deployment code. -func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value *uint256.Int, address common.Address, typ OpCode) (ret []byte, createAddress common.Address, result GasBudget, creation bool, err error) { +func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value *uint256.Int, address common.Address, typ OpCode) (ret []byte, createAddress common.Address, result GasBudget, err error) { // Since Amsterdam, the precheck has been folded into the parent frame // due to account-creation determination, so skip the duplicate check here. if !evm.chainRules.IsAmsterdam { @@ -533,7 +533,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value }(gas) } if err != nil { - return nil, common.Address{}, gas, false, err + return nil, common.Address{}, gas, err } // Increment the caller's nonce after passing all validations evm.StateDB.SetNonce(caller, evm.StateDB.GetNonce(caller)+1, tracing.NonceChangeContractCreator) @@ -543,7 +543,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value statelessGas := evm.AccessEvents.ContractCreatePreCheckGas(address, gas.RegularGas) prior, ok := gas.Charge(GasCosts{RegularGas: statelessGas}) if !ok { - return nil, common.Address{}, gas.ExitHalt(), false, ErrOutOfGas + return nil, common.Address{}, gas.ExitHalt(), ErrOutOfGas } if evm.Config.Tracer.HasGasHook() { evm.Config.Tracer.EmitGasChange(prior.AsTracing(), gas.AsTracing(), tracing.GasChangeWitnessContractCollisionCheck) @@ -570,7 +570,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value } // EIP-8037 collision rule: the state reservoir is fully preserved on // address collision while regular gas is burnt. - return nil, common.Address{}, halt, false, ErrContractAddressCollision + return nil, common.Address{}, halt, ErrContractAddressCollision } // Create a new account on the state only if the object was not present. // It might be possible the contract code is deployed to a pre-existent @@ -579,10 +579,6 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value if !evm.StateDB.Exist(address) { evm.StateDB.CreateAccount(address) } - // Explicitly check the creation with EIP-161-emptiness, for pre-funded - // destination (non-zero balance) the creation is skipped. - creation = evm.StateDB.Empty(address) - // CreateContract means that regardless of whether the account previously existed // in the state trie or not, it _now_ becomes created as a _contract_ account. // This is performed _prior_ to executing the initcode, since the initcode @@ -596,7 +592,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value if evm.chainRules.IsEIP4762 { consumed, wanted := evm.AccessEvents.ContractCreateInitGas(address, gas.RegularGas) if consumed < wanted { - return nil, common.Address{}, gas.ExitHalt(), false, ErrOutOfGas + return nil, common.Address{}, gas.ExitHalt(), ErrOutOfGas } prior, _ := gas.Charge(GasCosts{RegularGas: consumed}) if evm.Config.Tracer.HasGasHook() { @@ -627,11 +623,11 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasBudget, value evm.Config.Tracer.EmitGasChange(contract.Gas.AsTracing(), exit.AsTracing(), tracing.GasChangeCallFailedExecution) } } - return ret, address, exit, false, err + return ret, address, exit, err } // Either success, or pre-Homestead ErrCodeStoreOutOfGas (gas preserved). // Both packaged as a success-form GasBudget. - return ret, address, contract.Gas.ExitSuccess(), creation, err + return ret, address, contract.Gas.ExitSuccess(), err } // initNewContract runs a new contract's creation code, performs checks on the @@ -687,7 +683,7 @@ func (evm *EVM) initNewContract(contract *Contract, address common.Address) ([]b } // Create creates a new contract using code as deployment code. -func (evm *EVM) Create(caller common.Address, code []byte, gas GasBudget, value *uint256.Int) (ret []byte, contractAddr common.Address, result GasBudget, creation bool, err error) { +func (evm *EVM) Create(caller common.Address, code []byte, gas GasBudget, value *uint256.Int) (ret []byte, contractAddr common.Address, result GasBudget, err error) { contractAddr = crypto.CreateAddress(caller, evm.StateDB.GetNonce(caller)) return evm.create(caller, code, gas, value, contractAddr, CREATE) } @@ -696,7 +692,7 @@ func (evm *EVM) Create(caller common.Address, code []byte, gas GasBudget, value // // The different between Create2 with Create is Create2 uses keccak256(0xff ++ msg.sender ++ salt ++ keccak256(init_code))[12:] // instead of the usual sender-and-nonce-hash as the address where the contract is initialized at. -func (evm *EVM) Create2(caller common.Address, code []byte, gas GasBudget, endowment *uint256.Int, salt *uint256.Int) (ret []byte, contractAddr common.Address, result GasBudget, creation bool, err error) { +func (evm *EVM) Create2(caller common.Address, code []byte, gas GasBudget, endowment *uint256.Int, salt *uint256.Int) (ret []byte, contractAddr common.Address, result GasBudget, err error) { inithash := crypto.Keccak256Hash(code) contractAddr = crypto.CreateAddress2(caller, salt.Bytes32(), inithash[:]) return evm.create(caller, code, gas, endowment, contractAddr, CREATE2) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 7b7ea48774..c635432fbf 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -651,7 +651,7 @@ func opCreate(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { stackvalue := size child := scope.Contract.forwardGas(forward, evm.Config.Tracer, tracing.GasChangeCallContractCreation) - res, addr, result, _, suberr := evm.create(scope.Contract.Address(), input, child, &value, contractAddr, CREATE) + res, addr, result, suberr := evm.create(scope.Contract.Address(), input, child, &value, contractAddr, CREATE) // Push item on the stack based on the returned error. If the ruleset is // homestead we must check for CodeStoreOutOfGasError (homestead only @@ -702,7 +702,7 @@ func opCreate2(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { // reuse size int for stackvalue stackvalue := size child := scope.Contract.forwardGas(forward, evm.Config.Tracer, tracing.GasChangeCallContractCreation2) - res, addr, result, _, suberr := evm.create(scope.Contract.Address(), input, child, &endowment, contractAddr, CREATE2) + res, addr, result, suberr := evm.create(scope.Contract.Address(), input, child, &endowment, contractAddr, CREATE2) // Push item on the stack based on the returned error. if suberr != nil { stackvalue.Clear() diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 8dfa0fb740..f7554fbfd8 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -187,7 +187,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) { limit = min(cfg.GasLimit, params.MaxTxGas) } // Call the code with the given configuration. - code, address, result, _, err := vmenv.Create( + code, address, result, err := vmenv.Create( cfg.Origin, input, vm.NewGasBudget(limit, cfg.GasLimit-limit),