Test SSTORE Refunds¶
Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_sstore_refunds.py@5fa5938b.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_sstore_refunds.py --fork Amsterdam
Tests for EIP-8038: State Access Gas Cost Increase.
The headline mechanism of the pinned spec version a8862ae is the
SSTORE clear-refund reversal: refund_counter is decremented by
REFUND_STORAGE_CLEAR when a slot's original value is non-zero, its
current value is zero and the new value is non-zero (a slot cleared
earlier in the same transaction is restored). The spec reverses the clear
refund "so that clearing and then restoring a slot within the same
transaction is never net-profitable", closing the x -> 0 -> x round
trip; this reversal is exercised by
test_sstore_clear_then_reset_nets_zero.
This module covers the EIP-8038 regular SSTORE refund schedule via
the transaction receipt's cumulative_gas_used:
- Clearing a slot whose original value is non-zero grants
REFUND_STORAGE_CLEAR(12480) torefund_counter(no EIP-8037 state refund, since no state was created). - Clearing then re-setting the same non-zero-original slot nets a zero
refund: the clear grant is reversed (
refund -= REFUND_STORAGE_CLEAR) exactly whenoriginal != 0 and current == 0and a non-zero value is written back. - Restoring a non-zero-original slot to its original value refunds the
write cost
STORAGE_WRITE(10000). - The applied refund is capped at
gas_used // 5(EIP-3529 quotient).
All refunds use a non-zero original so the state-creation refund owned by EIP-8037 is never involved; only the EIP-8038 regular dimension is exercised.
Test Functions Overview¶
| Name | Type | Cases (Amsterdam) | Description |
|---|---|---|---|
test_sstore_clear_grants_refund |
state_test | 1 | Clearing a non-zero-original slot grants REFUND_STORAGE_CLEAR. |
test_sstore_clear_then_reset_nets_zero |
state_test | 1 | Clearing then re-setting a non-zero-original slot nets zero refund. |
test_sstore_refund_cap_exact_equality |
state_test | 1 | The applied refund equals the EIP-3529 cap at exact equality. |
test_sstore_refund_quotient_cap |
state_test | 3 | The applied refund saturates at the EIP-3529 quotient cap. |
test_sstore_restore_nonzero_refunds_write |
state_test | 1 | Restoring a non-zero-original slot refunds the write cost. |