EIP-7778 Block gas accounting excluding refunds (Block Gas Accounting without Refunds)

No call decision · Fees & gas · EIP status Last Call · created 2024-10-01

Excludes the gas refund received when clearing storage from the block gas limit calculation. The transaction cost and refund paid by the user remain the same as now, while the block comes to respect the limit based on actual computation performed.

Why it is needed

Currently, performing an action such as resetting a storage slot to zero gives back some gas as a refund. However, this refund not only reduces the user's transaction cost but is also subtracted when counting the block gas limit. As a result, the amount of computation actually performed diverges from the gas usage recorded for the block. In an example given in the source text, block 20878522 recorded net usage of 28.5 MGas, but with a refund of 4.01 MGas, the actual total usage was 32.51 MGas, exceeding the block gas limit by 2.51 MGas. Exploiting this gap allows more computation to be packed into a single block than the limit was intended to allow. The source text points out that this can result in network instability from oversized blocks, a denial-of-service (DoS) vector, and computational load exceeding the intended limit.

What changes

Today

After EIP-7778

Who is affected

In depth

User gas settlement unchanged

The calculation of the user's gas portion does not change. Performing a refund-eligible action, such as resetting a storage slot to zero, still yields a refund as before. Transaction gas is settled as gas_spent = max(tx_gas_used - gas_refund, calldata_floor_gas_cost), the greater of gas used minus refund and the calldata floor gas cost. Since the economics of an individual transaction remain unchanged, the incentive to save cost by cleaning up state is also preserved.

Excluding refunds from block gas accounting

Refunds are not subtracted when checking the block gas limit. Block gas usage accumulates as block.gas_used += max(tx_gas_used, calldata_floor_gas_cost), where the calldata floor cost reflects EIP-7623's calldata floor. However, not all discounts disappear. Storage discounts that reflect genuinely reduced computation, such as the discount for re-touching an already-warm storage slot or for restoring a value to its original state, still apply to the block aggregation. Only refunds given back after the computation has already been performed are excluded.

Design rationale: aligning the limit with actual computation

The block gas limit exists to cap the computational load per block. However, the gas refund was introduced to reward actions that clean up state, not to allow exceeding the computation limit. Excluding refunds from block aggregation lets the block gas limit properly constrain the actual computational load, while leaving the user-side refund unchanged preserves the incentive for efficient state management. Only the aggregation method for the block-level constraint changes; the economics for individual users do not change.

A hard-fork change

This change is not backward compatible and requires a hard fork. The experience for users and developers sending individual transactions remains the same. Block producers, on the other hand, must adjust their transaction selection algorithm to match the new gas accounting rule, since the same list of transactions will now aggregate to a larger block gas figure that does not subtract refunds, changing the criteria for filling a block. Clients must also be updated to check the limit against the value, including the refund, when validating blocks.

Test cases presented in the source text

The source text presents three sets of tests. First, it checks that when SSTORE resets storage to zero, the user receives the refund while the block aggregation uses the full cost, and that blocks with many storage-clearing operations still respect the gas limit. Second, it builds blocks while varying the proportion of refund-eligible operations, checking edge cases to confirm that the refund mechanism cannot be used to exceed the limit. Third, it separately verifies that the transaction cost paid by the user remains unchanged and that the block aggregation correctly excludes the refund.

Security effect

This eliminates the denial-of-service attack path that uses refunds to exceed a block's computation limit. Because computation is bounded by a stricter limit, block processing time also becomes more predictable. It also prevents block producers from including transactions whose combined computation exceeds the intended limit. As the motivation section's example shows, today a block can appear to be within the limit while its actual computation exceeds it; once this proposal is applied, such a block becomes invalid outright.

Standardization Status

This proposal is in the Core category of the Standards Track and its status is Last Call. The Last Call deadline is listed as 2026-11-01. Since it is not yet finalized, details may still change. The core developer call notes referenced for this explainer contain no decision to include this EIP in a specific fork. The proposal was authored by Ben Adams and Toni Wahrstätter and was created on 2024-10-01.

Original EIP · ← EIPs