Skip to content

test_delegation_spill_window_cost()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_delegation_spill_window_cost@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_delegation_spill_window_cost --fork Amsterdam

Test the clearing call repays only the code's uncommitted spill.

The same shape as test_cross_frame_refund_after_delegation_spill, with the call bracketed by two GAS reads. The refund repays the code's spill but cannot reach the committed delegation spill, so the window costs one state charge less than the call and child's execution. What the sender pays is checked there.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
@pytest.mark.valid_from("EIP8037")
def test_delegation_spill_window_cost(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test the clearing call repays only the code's uncommitted spill.

    The same shape as `test_cross_frame_refund_after_delegation_spill`,
    with the call bracketed by two `GAS` reads. The refund repays the
    code's spill but cannot reach the committed delegation spill, so
    the window costs one state charge less than the call and child's
    execution. What the sender pays is checked there.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    child_code = WARM_CLEAR(SLOT_X, 0)
    child = pre.deploy_contract(code=child_code)
    child_budget = budget_above_sstore_stipend(fork, child_code)

    call = Op.POP(
        Op.DELEGATECALL(gas=child_budget, address=child, address_warm=False)
    )
    code = (
        Op.MSTORE(32, 0, new_memory_size=64, old_memory_size=0)
        + FRESH_SET(SLOT_X, 1)
        + Op.MSTORE(0, Op.GAS)
        + call
        + Op.MSTORE(32, Op.GAS)
        + FRESH_SET(SLOT_RESULT, Op.SUB(Op.MLOAD(0), Op.MLOAD(32)))
    )
    contract = pre.deploy_contract(code=code)

    signer, authorization_list = delegation_to(pre, contract)

    # The window runs from one GAS read to the next: the store of the
    # first read, the call and the second read.
    call_cost = (
        Op.MSTORE(0, Op.GAS).gas_cost(fork)
        + call.execution_cost(fork)
        + child_code.execution_cost(fork)
    )

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

    post = {
        contract: Account(
            storage={
                SLOT_X: 0,
                SLOT_RESULT: call_cost - sstore_state_gas,
            }
        ),
        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.