Skip to content

test_sstore_restoration_refund()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_refund@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_refund --fork Amsterdam

Test SSTORE zero-to-nonzero-to-zero restoration refunds state gas.

When a slot is written from zero to nonzero and then restored to zero in the same transaction, the state gas charge (STATE_BYTES_PER_STORAGE_SET * cost_per_state_byte) is refunded via refund_counter along with the regular gas write cost.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
@EIPChecklist.GasRefundsChanges.Test.RefundCalculation()
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_refund(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test SSTORE zero-to-nonzero-to-zero restoration refunds state gas.

    When a slot is written from zero to nonzero and then restored to
    zero in the same transaction, the state gas charge
    (STATE_BYTES_PER_STORAGE_SET * cost_per_state_byte) is refunded
    via refund_counter along with the regular gas write cost.
    """
    contract = pre.deploy_contract(
        code=(Op.SSTORE(0, 1) + Op.SSTORE(0, 0)),
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

    # Slot 0 restored to zero — state gas refunded
    post = {contract: Account(storage={0: 0})}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.