Skip to content

test_set_delegation_oog_rolls_back_first_auth()

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

Generate fixtures for these test cases for Amsterdam with:

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

Auth-phase rollback undoes every flavor of the surviving first authorization's mutation.

A second authorization (a creation) is starved at its opening NEW_ACCOUNT charge, so the whole authorization phase rolls back. The first authorization -- which applied in full before the OOG -- is parametrized across the action space, and the post-state confirms its mutation is fully reverted:

  • SETS_NEW_DELEGATION: the fresh delegation and nonce bump are undone (authority back to an empty EOA).
  • SETS_DIFFERENT_DELEGATION / SETS_SAME_DELEGATION: the re-point and nonce bump are undone (authority back to its original delegation).
  • CLEARS_DELEGATION: the clear and nonce bump are undone (authority's original delegation restored).

The creation-first case is covered by test_set_delegation_oog_charge_point[new_account].

Both authorities are read during validation before the halt and stay in the block access list with no recorded changes; the recipient, never loaded before the halt, must be absent.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@pytest.mark.parametrize(
    "first_action",
    [
        AuthorizationAction.SETS_NEW_DELEGATION,
        AuthorizationAction.SETS_DIFFERENT_DELEGATION,
        AuthorizationAction.SETS_SAME_DELEGATION,
        AuthorizationAction.CLEARS_DELEGATION,
    ],
    ids=lambda a: a.name.lower(),
)
def test_set_delegation_oog_rolls_back_first_auth(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    first_action: AuthorizationAction,
) -> None:
    """
    Auth-phase rollback undoes every flavor of the surviving first
    authorization's mutation.

    A second authorization (a creation) is starved at its opening
    ``NEW_ACCOUNT`` charge, so the whole authorization phase rolls back.
    The first authorization -- which applied in full before the OOG --
    is parametrized across the action space, and the post-state confirms
    its mutation is fully reverted:

    - ``SETS_NEW_DELEGATION``: the fresh delegation and nonce bump are
      undone (authority back to an empty EOA).
    - ``SETS_DIFFERENT_DELEGATION`` / ``SETS_SAME_DELEGATION``: the
      re-point and nonce bump are undone (authority back to its original
      delegation).
    - ``CLEARS_DELEGATION``: the clear and nonce bump are undone
      (authority's original delegation restored).

    The creation-first case is covered by
    ``test_set_delegation_oog_charge_point[new_account]``.

    Both authorities are read during validation before the halt and
    stay in the block access list with no recorded changes; the
    recipient, never loaded before the halt, must be absent.
    """
    gas_costs = fork.gas_costs()
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)

    first = build_authorization(pre, first_action)
    second = build_authorization(pre, AuthorizationAction.CREATES_ACCOUNT)
    authorization_list = [first.authorization, second.authorization]

    intrinsic_execution = _intrinsic_execution(
        fork, authorization_list, recipient_type=RecipientType.CONTRACT
    )
    first_auth_charges = _auth_top_frame_charges(fork, [first.authorization])

    # The first authorization applies in full; the second (a creation)
    # runs out at its opening NEW_ACCOUNT state charge, rolling back the
    # whole authorization phase.
    gas_limit = (
        intrinsic_execution + first_auth_charges + gas_costs.NEW_ACCOUNT - 1
    )

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

    post = {
        first.authority: first.original_account,
        second.authority: second.original_account,
    }

    expected_block_access_list = BlockAccessListExpectation(
        account_expectations={
            recipient: None,
            first.authority: BalAccountExpectation.empty(),
            second.authority: BalAccountExpectation.empty(),
        }
    )

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.