Skip to content

test_sstore_restoration_intermediate_values()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_restoration_intermediate_values@c74f1a67.

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

Verify restoration refund triggers for 0 to x to y to 0.

The refund condition is original_value == new_value == 0, independent of intermediate values. One state gas charge at the first 0 to x; no charge for nonzero-to-nonzero; refund to reservoir at y to 0. Net block state gas is zero.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
@pytest.mark.valid_from("EIP8037")
def test_sstore_restoration_intermediate_values(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify restoration refund triggers for 0 to x to y to 0.

    The refund condition is `original_value == new_value == 0`,
    independent of intermediate values. One state gas charge at the
    first 0 to x; no charge for nonzero-to-nonzero; refund to reservoir
    at y to 0.  Net block state gas is zero.
    """
    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=2,
        )(0, 2)
        + Op.SSTORE.with_metadata(
            key_warm=True,
            original_value=0,
            current_value=2,
            new_value=0,
        )(0, 0)
    )
    tx_regular = intrinsic_gas + code.gas_cost(fork) - 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=tx_regular))],
        post={contract: Account(storage={0: 0})},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.