Skip to content

test_auth_state_charges_survive_dispatch_halt_with_reservoir()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_auth_state_charges_survive_dispatch_halt_with_reservoir@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_halt_with_reservoir --fork Amsterdam

The state gas charged for an applied authorization stays consumed when the dispatched call exceptionally halts, observed through the state-gas reservoir.

With an ordinary gas limit the reservoir is zero and a halt consumes all of gas_left anyway, masking any wrongly-refilled state gas. Here the gas limit exceeds the EIP-7825 cap (allowed -- the cap binds only the execution dimension), so the excess forms a state-gas reservoir that covers the authorization's NEW_ACCOUNT + AUTH_BASE. The dispatched call hits INVALID, consuming all execution gas; the unused reservoir returns to the sender, but the portion consumed for the persisting delegation must not.

A regression that refills the authorization's state gas with the frame's rollback would return the full reservoir, refunding the sender 218,790 gas for state that persists.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
def test_auth_state_charges_survive_dispatch_halt_with_reservoir(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    The state gas charged for an applied authorization stays consumed
    when the dispatched call exceptionally halts, observed through the
    state-gas reservoir.

    With an ordinary gas limit the reservoir is zero and a halt
    consumes all of ``gas_left`` anyway, masking any wrongly-refilled
    state gas. Here the gas limit exceeds the EIP-7825 cap (allowed --
    the cap binds only the execution dimension), so the excess forms a
    state-gas reservoir that covers the authorization's ``NEW_ACCOUNT``
    + ``AUTH_BASE``. The dispatched call hits ``INVALID``, consuming
    all execution gas; the *unused* reservoir returns to the sender, but
    the portion consumed for the persisting delegation must not.

    A regression that refills the authorization's state gas with the
    frame's rollback would return the full reservoir, refunding the
    sender 218,790 gas for state that persists.
    """
    cap = fork.transaction_gas_limit_cap()
    assert cap is not None, "EIP-7825 cap expected on this fork"

    sender = pre.fund_eoa()

    halt_code = Op.INVALID
    recipient = pre.deploy_contract(code=halt_code)

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

    auth_state_gas = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.CONTRACT,
        authorizations=authorization_list,
    )
    assert auth_state_gas > 0, (
        "the authorization must carry a state-gas charge"
    )

    # The reservoir covers the authorization's state charges with
    # headroom, so they draw from the reservoir rather than spilling
    # into gas_left.
    reservoir = auth_state_gas + 50_000

    # The halt consumes the full execution budget (the cap); of the
    # reservoir, only the authorization's state gas is consumed -- its
    # delegation persists -- and the unused remainder returns.
    gas_used = cap + auth_state_gas

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

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.