Skip to content

test_cross_frame_refund_after_delegation_spill()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_cross_frame_refund_after_delegation_spill@8acae1b0.

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

Test a cross-frame refund after the sender's delegation spilled.

A set-code transaction with an empty reservoir pays its delegation from gas_left and commits that spill before the code runs. The code spills a fresh set and a delegated child clears it. The merge repays the code's spill but not the committed delegation spill, so the delegation stays billed. What the call costs gas_left is measured in test_delegation_spill_window_cost.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
@pytest.mark.valid_from("EIP8037")
def test_cross_frame_refund_after_delegation_spill(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test a cross-frame refund after the sender's delegation spilled.

    A set-code transaction with an empty reservoir pays its delegation
    from `gas_left` and commits that spill before the code runs. The
    code spills a fresh set and a delegated child clears it. The merge
    repays the code's spill but not the committed delegation spill, so
    the delegation stays billed. What the call costs `gas_left` is
    measured in `test_delegation_spill_window_cost`.
    """
    child_code = WARM_CLEAR(SLOT_X, 0)
    child = pre.deploy_contract(code=child_code)
    child_budget = budget_above_sstore_stipend(fork, child_code)

    code = FRESH_SET(SLOT_X, 1) + Op.POP(
        Op.DELEGATECALL(gas=child_budget, address=child, address_warm=False)
    )
    contract = pre.deploy_contract(code=code)

    signer, authorization_list = delegation_to(pre, contract)

    gas_used = (
        fork.transaction_intrinsic_cost_calculator()(
            authorization_list_or_count=authorization_list,
            return_cost_deducted_prior_execution=True,
        )
        + fork.transaction_top_frame_execution_gas(
            authorizations=authorization_list
        )
        + fork.transaction_top_frame_state_gas(
            authorizations=authorization_list
        )
        + code.gas_cost(fork)
        + child_code.gas_cost(fork)
        - child_code.state_refund(fork)
    )
    refund = child_code.refund(fork) - child_code.state_refund(fork)
    gas_used -= min(gas_used // fork.max_refund_quotient(), refund)

    tx = Transaction(
        to=contract,
        authorization_list=authorization_list,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=gas_used),
    )

    post = {
        contract: Account(storage={SLOT_X: 0}),
        signer: Account(code=Spec7702.delegation_designation(contract)),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.