Skip to content

test_sstore_restoration_mixed_with_genuine_sstore()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_mixed_with_genuine_sstore@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_mixed_with_genuine_sstore --fork Bogota

Verify restoration cycles plus a genuine 0 to x SSTORE.

num_cycles of 0 to x to 0 refund; one genuine 0 to x on slot 99 persists, contributing exactly one sstore_state_gas to block state gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
@pytest.mark.parametrize(
    "num_cycles,state_dominates",
    [
        pytest.param(1, True, id="one_cycle"),
        pytest.param(10, False, id="ten_cycles"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_mixed_with_genuine_sstore(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    num_cycles: int,
    state_dominates: bool,
) -> None:
    """
    Verify restoration cycles plus a genuine 0 to x SSTORE.

    `num_cycles` of 0 to x to 0 refund; one genuine 0 to x on slot 99
    persists, contributing exactly one `sstore_state_gas` to block
    state gas.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()

    code = Bytecode()
    for i in range(num_cycles):
        code += Op.SSTORE(i, 1) + Op.SSTORE.with_metadata(
            key_warm=True,
            original_value=0,
            current_value=1,
            new_value=0,
        )(i, 0)
    code += Op.SSTORE(99, 1)

    num_0_to_1 = num_cycles + 1
    tx_execution = intrinsic_gas + code.execution_cost(fork)
    assert (sstore_state_gas > tx_execution) == state_dominates
    expected = max(tx_execution, sstore_state_gas)

    contract = pre.deploy_contract(code=code)
    tx = Transaction(
        to=contract,
        state_gas_reservoir=num_0_to_1 * sstore_state_gas,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=sender_gas_used(
                fork, tx_execution + sstore_state_gas, code
            )
        ),
    )

    post_storage = dict.fromkeys(range(num_cycles), 0)
    post_storage[99] = 1
    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx], header_verify=Header(gas_used=expected))],
        post={contract: Account(storage=post_storage)},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.