Skip to content

test_sstore_restoration_then_reset()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_then_reset@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_then_reset --fork Amsterdam

Verify accounting across 0 to 1 to 0 to 1 (restore then re-set).

The refund applied at 1 to 0 returns state gas to the reservoir; the subsequent 0 to 1 re-charges state gas. Net: one charge remains, one state gas worth counted in block state gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_then_reset(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify accounting across 0 to 1 to 0 to 1 (restore then re-set).

    The refund applied at 1 to 0 returns state gas to the reservoir;
    the subsequent 0 to 1 re-charges state gas.  Net: one charge
    remains, one state gas worth counted in block state gas.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()

    code = (
        Op.SSTORE(0, 1)
        + Op.SSTORE.with_metadata(
            key_warm=True,
            original_value=0,
            current_value=1,
            new_value=0,
        )(0, 0)
        + Op.SSTORE.with_metadata(
            key_warm=True,
            original_value=0,
            current_value=0,
            new_value=1,
        )(0, 1)
    )
    tx_regular = intrinsic_gas + code.gas_cost(fork) - 2 * sstore_state_gas
    expected = max(tx_regular, sstore_state_gas)

    contract = pre.deploy_contract(code=code)
    tx = Transaction(
        to=contract,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx], header_verify=Header(gas_used=expected))],
        post={contract: Account(storage={0: 1})},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.