Skip to content

test_sstore_restoration_block_state_gas_zero()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_block_state_gas_zero@5c024cbb.

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

Verify 0 to x to 0 cycles contribute zero to block state gas.

Net state growth is zero. State gas goes directly to state_gas_reservoir rather than refund_counter, so block state gas is not inflated by the charges.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
@pytest.mark.parametrize(
    "num_cycles",
    [
        pytest.param(1, id="single_cycle"),
        pytest.param(50, id="fifty_cycles"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_block_state_gas_zero(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    num_cycles: int,
) -> None:
    """
    Verify 0 to x to 0 cycles contribute zero to block state gas.

    Net state growth is zero. State gas goes directly to
    `state_gas_reservoir` rather than `refund_counter`, so block
    state gas is not inflated by the charges.
    """
    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)
    tx_regular = (
        intrinsic_gas + code.gas_cost(fork) - num_cycles * sstore_state_gas
    )

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

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.