Skip to content

test_delegation_persists_on_execution_oog()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_delegation_persists_on_execution_oog@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_delegation_persists_on_execution_oog --fork Amsterdam

Once the top-frame preparation completes, an out-of-gas in the dispatched call does NOT roll the applied delegations back.

Two valid authorizations on third-party authorities are paid in full and the recipient (a plain contract, so it adds no top-frame charge) is dispatched with only enough execution budget for a single opcode. The recipient runs that opcode and then runs out of gas on the next, so the frame halts during execution and consumes the full gas_limit.

The execution snapshot is taken after preparation, so the applied delegations survive the halt -- matching the EIP-7702 "dispatch reverts, delegation remains" rule -- while the recipient is unchanged.

With value set, the transfer to the recipient happens inside the execution snapshot, so the halt that keeps the delegations in place reverses the transfer: the recipient stays at balance zero and the sender pays only the gas.

The block access list mirrors this split: both authorities carry their persisted nonce bump and delegation-code write, while the recipient -- accessed for dispatch but whose (reverted) value transfer leaves no net change -- appears with no recorded changes.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py
 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
1008
1009
1010
1011
1012
1013
1014
1015
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
@pytest.mark.parametrize(
    "value",
    [pytest.param(0, id="no_value"), pytest.param(1, id="with_value")],
)
def test_delegation_persists_on_execution_oog(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    value: int,
) -> None:
    """
    Once the top-frame preparation completes, an out-of-gas in the
    dispatched call does NOT roll the applied delegations back.

    Two valid authorizations on third-party authorities are paid in
    full and the recipient (a plain contract, so it adds no top-frame
    charge) is dispatched with only enough execution budget for a single
    opcode. The recipient runs that opcode and then runs out of gas on
    the next, so the frame halts during execution and consumes the full
    ``gas_limit``.

    The execution snapshot is taken after preparation, so the applied
    delegations survive the halt -- matching the EIP-7702 "dispatch
    reverts, delegation remains" rule -- while the recipient is
    unchanged.

    With ``value`` set, the transfer to the recipient happens inside
    the execution snapshot, so the halt that keeps the delegations in
    place reverses the transfer: the recipient stays at balance zero
    and the sender pays only the gas.

    The block access list mirrors this split: both authorities carry
    their persisted nonce bump and delegation-code write, while the
    recipient -- accessed for dispatch but whose (reverted) value
    transfer leaves no net change -- appears with no recorded changes.
    """
    sender = pre.fund_eoa()

    auth_a = build_authorization(pre, AuthorizationAction.CREATES_ACCOUNT)
    auth_b = build_authorization(pre, AuthorizationAction.SETS_NEW_DELEGATION)
    authorization_list = [auth_a.authorization, auth_b.authorization]
    auth_charges = _auth_top_frame_charges(fork, authorization_list)

    intrinsic_execution = _intrinsic_execution(
        fork,
        authorization_list,
        recipient_type=RecipientType.CONTRACT,
        sends_value=bool(value),
    )

    # Two VERYLOW pushes: the budget covers one, so the frame enters
    # execution and then runs out on the second, consuming all gas.
    recipient_code = Op.PUSH1(0) + Op.PUSH1(0)
    one_opcode = Op.PUSH1(0).gas_cost(fork)
    gas_limit = intrinsic_execution + auth_charges + one_opcode

    recipient = pre.deploy_contract(code=recipient_code)

    tx = Transaction(
        sender=sender,
        to=recipient,
        value=value,
        authorization_list=authorization_list,
        gas_limit=gas_limit,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=gas_limit,
        ),
    )

    post = {
        auth_a.authority: auth_a.applied_account,
        auth_b.authority: auth_b.applied_account,
        recipient: Account(code=recipient_code, balance=0),
    }

    expected_block_access_list = BlockAccessListExpectation(
        account_expectations={
            auth_a.authority: _applied_delegation_bal(auth_a),
            auth_b.authority: _applied_delegation_bal(auth_b),
            recipient: BalAccountExpectation.empty(),
        }
    )

    state_test(
        pre=pre,
        tx=tx,
        post=post,
        expected_block_access_list=expected_block_access_list,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.