Skip to content

test_fixed_gas_probe_after_clearing_frame()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_fixed_gas_probe_after_clearing_frame@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_fixed_gas_probe_after_clearing_frame --fork Amsterdam

Test a fixed-gas probe after a successful or reverted clear.

A successful child repays the caller's spill, leaving no reservoir for the probe. A reverted child rolls back both the clear and its credit. The probe cannot pay its state charge in either case; the caller's slot distinguishes the committed clear from the rollback.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
@pytest.mark.parametrize(
    "clearing_frame_ending",
    [
        pytest.param("stop", id="child_succeeds"),
        pytest.param("revert", id="child_reverts"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_fixed_gas_probe_after_clearing_frame(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    clearing_frame_ending: str,
) -> None:
    """
    Test a fixed-gas probe after a successful or reverted clear.

    A successful child repays the caller's spill, leaving no reservoir
    for the probe. A reverted child rolls back both the clear and its
    credit. The probe cannot pay its state charge in either case; the
    caller's slot distinguishes the committed clear from the rollback.
    """
    credit_survives = clearing_frame_ending == "stop"

    clear = Op.SSTORE.with_metadata(
        key_warm=True, original_value=0, current_value=1, new_value=0
    )(SLOT_X, 0)
    clearer_code = clear + (Op.STOP if credit_survives else Op.REVERT(0, 0))
    clearer = pre.deploy_contract(code=clearer_code)

    probe_storage = Storage()
    probe_code = Op.SSTORE(probe_storage.store_next(0, "probe_ran"), 1)
    probe = pre.deploy_contract(probe_code)
    probe_stipend = probe_code.execution_cost(fork)

    entry = pre.deploy_contract(
        code=(
            Op.SSTORE(SLOT_X, 1)
            + Op.POP(Op.DELEGATECALL(gas=Op.GAS, address=clearer))
            + Op.POP(Op.CALL(gas=probe_stipend, address=probe))
        )
    )

    tx = Transaction(
        to=entry,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

    post = {
        entry: Account(storage={SLOT_X: 0 if credit_survives else 1}),
        probe: Account(storage=probe_storage),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.