EIP-3978 Gas refunds on revert (Gas refunds on reverts)
No call decision · Fees & gas · EIP status Stagnant · created 2021-09-16
A proposal that when a transaction or subcall reverts, the portion of the high gas cost charged for cancelled state-changing operations (SSTORE, CREATE, SELFDESTRUCT, LOG, etc.) corresponding to the modify cost be returned as a gas refund.
Why it is needed
Currently, when a transaction or a subcall within it reverts, all state changes made within it, such as storage changes, contract creation, and log emission, are cancelled. Yet the user still pays the original high gas cost as if these operations had actually taken effect. Since EIP-3298, the gas refund mechanism only works when storage is restored to its original value within the same transaction, and when a revert occurs, even the gas refunds accumulated up to that point are wiped out entirely. This creates the paradoxical situation where, instead of reverting a transaction, manually sending tokens back at the end to restore state by hand ends up being cheaper. Since reverted operations did incur real data access costs during execution but ultimately did not incur state-change costs, this proposal arose from the recognition that gas should be recalibrated to reflect only the cost actually incurred.
What changes
Today
- When a transaction or subcall reverts, all gas refunds accumulated within it are wiped out
- Reverted operations such as SSTORE, CREATE, SELFDESTRUCT, and LOG are charged the same high gas cost as if they had executed normally
- There are cases where manually restoring state at the end of a transaction is cheaper in gas than reverting
After EIP-3978
- For reverted SSTORE, LOG0-4, value-sending CALL, CREATE, CREATE2, and SELFDESTRUCT, only the access cost (100 gas, based on WARM_STORAGE_READ_COST) remains and the rest is refunded
- revert_gas_refund is tracked per call frame, and once a revert is finalized it is added to the transaction's gas refund
- The gas cost gap between reverting an operation and manually restoring state narrows
Who is affected
- Users: The effective gas cost of transactions that fail due to unmet conditions or that deliberately revert may decrease
- Wallet & app developers: Gas estimation logic for contracts using conditional execution or try-style patterns based on reverts needs to be recalculated
- Client teams: New logic must be implemented in the EVM executor to track revert_gas_refund per call frame and apply it on revert
In depth
Tracking revert_gas_refund per call frame
Each call frame has a revert_gas_refund value starting at 0. Whenever SSTORE, LOG0, LOG1, LOG2, LOG3, LOG4, CALL, CREATE, CREATE2, or SELFDESTRUCT executes, the value accumulates as call.revert_gas_refund += operation.gas - WARM_STORAGE_READ_COST. In other words, the gas that the operation would normally charge, minus the warm storage read cost, is accumulated per call frame.
Computing the transaction gas refund on revert
When a call reverts, the existing behavior clears the refund accumulated by that call via tx.gas_refund -= call.gas_refund, and in addition tx.gas_refund += call.revert_gas_refund is newly applied. In other words, instead of the cleared refund, the revert_gas_refund precomputed for the reverted operations is added to the total transaction gas refund.
Operations targeted for recalibration and their target gas
The recalibration goal stated in Motivation is to lower reverted SSTORE to the SLOAD level (100 gas), LOG0 through LOG4 to 100 gas, a value-sending CALL (positive_value_cost of 9,000 gas) to 100 gas, a CALL that both sends value and creates a new account (value_to_empty_account_cost of 25,000 gas) to 100 gas, CREATE and CREATE2 (32,000 gas) to 100 gas, and SELFDESTRUCT (5,000 or 25,000 gas) to 100 gas.
Proposal for conditional charging of the 32,000 gas for CREATE and CREATE2
Separately from the recalibration, Motivation also suggests it would be fairer to charge the fixed 32,000 gas cost of CREATE and CREATE2 only when the returned bytecode is non-empty. However, this has not been formalized into a concrete specification item.
Relationship with EIP-2929 and EIP-3298
This EIP requires EIP-2929. WARM_STORAGE_READ_COST, used in the revert_gas_refund formula, is the access cost constant defined by EIP-2929. Motivation also states that this proposal was designed on the premise that the gas refund mechanism following EIP-3298 only works for storage restoration within the same transaction and does not work on reverts.
Incomplete state and current status
The specification itself is short, but the Test Cases, Reference Implementation, and Security Considerations sections all remain TBD. The status is Stagnant, and recent call records show no discussion of this EIP or any decision on fork inclusion. Details may therefore change or the proposal may not proceed further.