core/vm: burn gas on contract address collision

This commit is contained in:
Marius van der Wijden 2026-03-10 15:48:35 +01:00
parent 6c1d9e0c66
commit ed2f476da8
2 changed files with 10 additions and 1 deletions

View file

@ -603,7 +603,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
// tx_state = adjusted_intrinsic_state + exec_state_used (spec: set_delegation adjusts intrinsic)
// tx_regular = total_dimensional_used - tx_state
txState := (gas.StateGas - authRefund) + st.gasRemaining.StateGasCharged
txRegular := (msg.GasLimit - preRefundRemaining) - txState
txRegular := (msg.GasLimit - preRefundRemaining) - txState - st.evm.CollisionBurned
txRegular = max(txRegular, floorDataGas)
if err := st.gp.ReturnGasAmsterdam(returned, txRegular, txState, st.gasUsed()); err != nil {
return nil, err

View file

@ -129,6 +129,14 @@ type EVM struct {
readOnly bool // Whether to throw on stateful modifications
returnData []byte // Last CALL's return data for subsequent reuse
// CollisionBurned accumulates regular gas burned in CREATE/CREATE2 address
// collisions. The spec burns this gas (deducts from gas_left) but does NOT
// count it in regular_gas_used, so it must be excluded from txRegular in
// 2D block gas accounting.
// TODO (MariusVanDerWijden) this seems to be the best way to conform to the current
// spec, I wonder if it makes sense to change the spec.
CollisionBurned uint64
}
// NewEVM constructs an EVM instance with the supplied block context, state
@ -549,6 +557,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas GasCosts, value *
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
evm.Config.Tracer.OnGasChange(gas.RegularGas, 0, tracing.GasChangeCallFailedExecution)
}
evm.CollisionBurned += gas.RegularGas
gas.RegularGas = 0
return nil, common.Address{}, gas, ErrContractAddressCollision
}