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@a9abd46e.

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_mixed_with_genuine_sstore --fork Amsterdam

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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
@pytest.mark.parametrize(
    "num_cycles",
    [
        pytest.param(1, id="one_cycle"),
        pytest.param(10, 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,
) -> 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_regular = (
        intrinsic_gas + code.gas_cost(fork) - num_0_to_1 * sstore_state_gas
    )
    expected = max(tx_regular, 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(),
    )

    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 1 fork.