Skip to content

test_mixed_validity_multi_auth_receipt_gas()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_set_code_auth_gas.py::test_mixed_validity_multi_auth_receipt_gas@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_set_code_auth_gas.py::test_mixed_validity_multi_auth_receipt_gas --fork Amsterdam

Pin the exact receipt gas of a transaction carrying one valid and one invalid authorization under the EIP-2780 top-frame charge model.

Both tuples pay the state-independent EXECUTION_PER_AUTH_BASE_COST in the intrinsic. The single valid authorization's authority leaf already exists (a funded EOA) and gains a net-new delegation indicator, so at the top frame it pays the first-write ACCOUNT_WRITE and AUTH_BASE -- no NEW_ACCOUNT and no refund. The invalid tuple is silently skipped during set_delegation and pays nothing beyond the intrinsic base.

Each invalidity kind (INVALID_NONCE, INVALID_CHAIN_ID, REPEATED_NONCE, AUTHORITY_IS_CONTRACT) yields the same one-valid-one-invalid shape, so every kind pins the same receipt gas. This is the numeric-receipt companion to test_invalid_auth_charged_intrinsic (which asserts only post state).

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_set_code_auth_gas.py
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize(
    "invalidity",
    [
        pytest.param("invalid_nonce", id="invalid_nonce"),
        pytest.param("invalid_chain_id", id="invalid_chain_id"),
        pytest.param("repeated_nonce", id="repeated_nonce"),
        pytest.param("authority_is_contract", id="authority_is_contract"),
    ],
)
@pytest.mark.pre_alloc_mutable
def test_mixed_validity_multi_auth_receipt_gas(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    fork: Fork,
    invalidity: str,
) -> None:
    """
    Pin the exact receipt gas of a transaction carrying one valid and
    one invalid authorization under the EIP-2780 top-frame charge model.

    Both tuples pay the state-independent ``EXECUTION_PER_AUTH_BASE_COST``
    in the intrinsic. The single valid authorization's authority leaf
    already exists (a funded EOA) and gains a net-new delegation
    indicator, so at the top frame it pays the first-write
    ``ACCOUNT_WRITE`` and ``AUTH_BASE`` -- no ``NEW_ACCOUNT`` and no
    refund. The invalid tuple is silently skipped during
    ``set_delegation`` and pays nothing beyond the intrinsic base.

    Each ``invalidity`` kind (``INVALID_NONCE``, ``INVALID_CHAIN_ID``,
    ``REPEATED_NONCE``, ``AUTHORITY_IS_CONTRACT``) yields the same
    one-valid-one-invalid shape, so every kind pins the same receipt
    gas. This is the numeric-receipt companion to
    ``test_invalid_auth_charged_intrinsic`` (which asserts only post
    state).
    """
    delegate = pre.deploy_contract(code=Op.STOP)

    # The single valid authorization: an existing (funded) authority
    # gaining a net-new delegation. It writes a delegation indicator
    # (AUTH_BASE at the top frame) but creates no account.
    valid_signer = pre.fund_eoa()
    valid_auth = AuthorizationTuple(
        address=delegate,
        nonce=0,
        signer=valid_signer,
        creates_account=False,
        writes_delegation=True,
    )

    # One valid tuple plus one invalid tuple of the requested kind. The
    # invalid tuple is skipped in ``set_delegation``, so it neither
    # creates an account nor writes a delegation indicator.
    authorization_list: List[AuthorizationTuple]
    post: dict = {
        valid_signer: Account(
            code=Spec7702.delegation_designation(delegate),
        ),
    }

    if invalidity == "invalid_nonce":
        authority = pre.fund_eoa()
        authorization_list = [
            valid_auth,
            AuthorizationTuple(
                address=delegate,
                nonce=99,  # wrong nonce -> skipped
                signer=authority,
                creates_account=False,
                writes_delegation=False,
                first_write=False,
            ),
        ]
        post[authority] = Account(code=b"")
    elif invalidity == "invalid_chain_id":
        authority = pre.fund_eoa()
        authorization_list = [
            valid_auth,
            AuthorizationTuple(
                address=delegate,
                nonce=0,
                chain_id=9999,  # wrong chain id -> skipped
                signer=authority,
                creates_account=False,
                writes_delegation=False,
                first_write=False,
            ),
        ]
        post[authority] = Account(code=b"")
    elif invalidity == "repeated_nonce":
        # The valid tuple consumes the signer's nonce 0; a second tuple
        # reusing nonce 0 on the same signer is skipped.
        authorization_list = [
            valid_auth,
            AuthorizationTuple(
                address=delegate,
                nonce=0,
                signer=valid_signer,
                creates_account=False,
                writes_delegation=False,
                first_write=False,
            ),
        ]
    elif invalidity == "authority_is_contract":
        # An authority that is already a (non-delegation) contract is an
        # invalid authority; its authorization is skipped and the
        # contract code is left intact.
        authority = pre.fund_eoa(code=Op.STOP)
        authorization_list = [
            valid_auth,
            AuthorizationTuple(
                address=delegate,
                nonce=0,
                signer=authority,
                creates_account=False,
                writes_delegation=False,
                first_write=False,
            ),
        ]
        post[authority] = Account(code=Op.STOP)
    else:
        raise ValueError(f"unknown invalidity: {invalidity!r}")

    n = len(authorization_list)

    # Charge model (no refunds): the intrinsic charges the per-auth base
    # for every tuple; the one valid authorization adds ``AUTH_BASE`` at
    # the top frame for its net-new delegation indicator. The skipped
    # tuple and the plain ``STOP`` recipient add nothing.
    intrinsic_execution = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=n,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_execution = fork.transaction_top_frame_gas_calculator()(
        authorizations=authorization_list,
    )
    top_frame_state = fork.transaction_top_frame_state_gas(
        authorizations=authorization_list,
    )
    cumulative_gas_used = (
        intrinsic_execution + top_frame_execution + top_frame_state
    )

    tx = Transaction(
        to=delegate,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=cumulative_gas_used,
        ),
    )

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.