Skip to content

test_auth_state_charges_survive_dispatch_revert()

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

Generate fixtures for these test cases for Amsterdam with:

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

The state gas charged for an applied authorization stays consumed when the dispatched call reverts, because the delegation persists.

A single authorization is applied in full, then the recipient (a plain contract) reverts immediately. Per EIP-7702 the applied delegation survives the revert, so the state it created -- the authority's account leaf (NEW_ACCOUNT) and delegation indicator (AUTH_BASE) -- remains, and the state gas that paid for it must remain consumed. Only the dispatched frame's unused budget is returned.

A regression that refills the authorization's state gas with the frame's rollback would refund the sender 218,790 (NEW_ACCOUNT + AUTH_BASE) or 35,190 (AUTH_BASE) gas for state that persists; the receipt's exact gas used pins this.

The same persistence must show in the block access list: the authority carries its nonce bump and delegation-code write even though the dispatched frame reverted, while the recipient appears with no recorded changes.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
@pytest.mark.parametrize(
    "auth_action",
    [
        AuthorizationAction.CREATES_ACCOUNT,
        AuthorizationAction.SETS_NEW_DELEGATION,
    ],
    ids=lambda a: a.name.lower(),
)
def test_auth_state_charges_survive_dispatch_revert(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    auth_action: AuthorizationAction,
) -> None:
    """
    The state gas charged for an applied authorization stays consumed
    when the dispatched call reverts, because the delegation persists.

    A single authorization is applied in full, then the recipient (a
    plain contract) reverts immediately. Per EIP-7702 the applied
    delegation survives the revert, so the state it created -- the
    authority's account leaf (``NEW_ACCOUNT``) and delegation indicator
    (``AUTH_BASE``) -- remains, and the state gas that paid for it must
    remain consumed. Only the dispatched frame's unused budget is
    returned.

    A regression that refills the authorization's state gas with the
    frame's rollback would refund the sender 218,790
    (``NEW_ACCOUNT + AUTH_BASE``) or 35,190 (``AUTH_BASE``) gas for
    state that persists; the receipt's exact gas used pins this.

    The same persistence must show in the block access list: the
    authority carries its nonce bump and delegation-code write even
    though the dispatched frame reverted, while the recipient appears
    with no recorded changes.
    """
    sender = pre.fund_eoa()

    revert_code = Op.REVERT(0, 0)
    recipient = pre.deploy_contract(code=revert_code)

    auth = build_authorization(pre, auth_action)
    authorization_list = [auth.authorization]

    intrinsic_execution = _intrinsic_execution(
        fork, authorization_list, recipient_type=RecipientType.CONTRACT
    )
    auth_charges = _auth_top_frame_charges(fork, authorization_list)
    revert_exec_gas = revert_code.gas_cost(fork)

    # The authorization's execution and state charges and the two PUSH
    # opcodes feeding the REVERT stay paid; only the unused execution
    # budget returns.
    gas_used = intrinsic_execution + auth_charges + revert_exec_gas

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

    post = {
        auth.authority: auth.applied_account,
        recipient: Account(code=revert_code, balance=0),
    }

    expected_block_access_list = BlockAccessListExpectation(
        account_expectations={
            auth.authority: _applied_delegation_bal(auth),
            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.