Skip to content

Conversation

@jwasinger
Copy link
Contributor

@jwasinger jwasinger commented Dec 18, 2025

There's no need to perform the subsequent state access on the target if we already know that we are out of gas.

This aligns the state access behavior of selfdestruct with EIP-7928

… enough gas to cover cold account access costs
evm.StateDB.AddAddressToAccessList(address)
gas = params.ColdAccountAccessCostEIP2929

if contract.Gas < gas {
Copy link
Member

@rjl493456442 rjl493456442 Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the EIP https://eips.ethereum.org/EIPS/eip-7928

BALs must include the Addresses accessed without state changes, including: Beneficiary addresses for SELFDESTRUCT

It means the beneficiary address should be tracked in the BALs regardless of the gas is sufficient should this opcode.
If we short circuit here and without executing if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
how should we explicitly track it?

@rjl493456442
Copy link
Member

rjl493456442 commented Dec 19, 2025

Our gas calculation mechanism is somewhat awkward, in my opinion.

For stateless opcodes such as arithmetic operations, gas accounting is straightforward. However, gas calculation becomes significantly more complex once state is involved, such as with CALL. In these cases, we often need to determine how much gas is available and skip unnecessary state retrieval when the remaining gas is insufficient for performance reasons.

For SELFDESTRUCT, the required gas depends on state related information, and the target address must be tracked accordingly in BALs

Note: For call-related opcodes (CALL, CALLCODE, DELEGATECALL, STATICCALL), the target address is added to the access list (BAL) only if the gas checks (including memory expansion, access cost, and transfer cost) pass. If the operation fails due to insufficient gas before any state access, the target address must not be included.

For CALL* opcodes, the target address must not be included if the opcode is not actually executed, even if state has already been resolved during gas calculation. In such cases, we must explicitly filter out the related states from the BALs.

It's very hard to fully align the requirement of EIP-7928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants