Skip to content

test_auth_base_net_new_only()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_auth_base_net_new_only@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_auth_base_net_new_only --fork Amsterdam

AUTH_BASE is charged only when a net-new delegation is set: the authority held no delegation before the transaction, none was set for it earlier in the transaction, and the current authorization sets one. It is charged at most once per authority per transaction and is never credited back.

  • pre_tx_delegated_re_set: a pre-delegated authority is re-pointed; the indicator bytes already exist, so no AUTH_BASE. The re-point is still the transaction's first write to the authority, so ACCOUNT_WRITE applies.
  • pre_tx_delegated_clear_then_set: a pre-delegated authority is cleared and then re-delegated in the same transaction. The authority held a delegation before the transaction, so neither authorization pays AUTH_BASE (and ACCOUNT_WRITE applies once, at the clear -- the first write).
  • multiple_sets: an empty-code EOA is delegated and then re-pointed. Only the first set is net-new: one AUTH_BASE, and one ACCOUNT_WRITE for the first write.
  • set_clear_cycles: an empty-code EOA is set, cleared, set, and cleared again. The first set charges AUTH_BASE; the clears credit nothing back and the second set is not net-new (a delegation was already set in this transaction). Exactly one AUTH_BASE and one ACCOUNT_WRITE are paid even though the authority ends the transaction with no delegation.
Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
@pytest.mark.parametrize(
    "scenario",
    [
        "pre_tx_delegated_re_set",
        "pre_tx_delegated_clear_then_set",
        "multiple_sets",
        "set_clear_cycles",
    ],
)
def test_auth_base_net_new_only(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    scenario: str,
) -> None:
    """
    ``AUTH_BASE`` is charged only when a net-new delegation is set: the
    authority held no delegation before the transaction, none was set
    for it earlier in the transaction, and the current authorization
    sets one. It is charged at most once per authority per transaction
    and is never credited back.

    - ``pre_tx_delegated_re_set``: a pre-delegated authority is
      re-pointed; the indicator bytes already exist, so no
      ``AUTH_BASE``. The re-point is still the transaction's first
      write to the authority, so ``ACCOUNT_WRITE`` applies.
    - ``pre_tx_delegated_clear_then_set``: a pre-delegated authority is
      cleared and then re-delegated in the same transaction. The
      authority held a delegation before the transaction, so neither
      authorization pays ``AUTH_BASE`` (and ``ACCOUNT_WRITE`` applies
      once, at the clear -- the first write).
    - ``multiple_sets``: an empty-code EOA is delegated and then
      re-pointed. Only the first set is net-new: one ``AUTH_BASE``, and
      one ``ACCOUNT_WRITE`` for the first write.
    - ``set_clear_cycles``: an empty-code EOA is set, cleared, set, and
      cleared again. The first set charges ``AUTH_BASE``; the clears
      credit nothing back and the second set is not net-new (a
      delegation was already set in this transaction). Exactly one
      ``AUTH_BASE`` and one ``ACCOUNT_WRITE`` are paid even though the
      authority ends the transaction with no delegation.
    """
    authority_initial_balance = 100
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)

    target_a = pre.deploy_contract(code=Op.STOP)
    target_b = pre.deploy_contract(code=Op.STOP)

    expected_code: bytes
    if scenario == "pre_tx_delegated_re_set":
        old_target = pre.deploy_contract(code=Op.STOP)
        authority = pre.fund_eoa(
            amount=authority_initial_balance, delegation=old_target
        )
        auth_specs = [target_a]
        first_nonce = 1
        expected_code = Spec7702.delegation_designation(target_a)
        # Delegated before the transaction, so the re-point is not
        # net-new: no AUTH_BASE.
        net_new = [False]
    elif scenario == "pre_tx_delegated_clear_then_set":
        old_target = pre.deploy_contract(code=Op.STOP)
        authority = pre.fund_eoa(
            amount=authority_initial_balance, delegation=old_target
        )
        auth_specs = [NULL_ADDRESS, target_a]
        first_nonce = 1
        expected_code = Spec7702.delegation_designation(target_a)
        # Delegated before the transaction, so neither the clear nor
        # the re-set is net-new.
        net_new = [False, False]
    elif scenario == "multiple_sets":
        authority = pre.fund_eoa(amount=authority_initial_balance)
        auth_specs = [target_a, target_b]
        first_nonce = 0
        expected_code = Spec7702.delegation_designation(target_b)
        # Only the first set is net-new; the re-point is not.
        net_new = [True, False]
    else:  # set_clear_cycles
        authority = pre.fund_eoa(amount=authority_initial_balance)
        auth_specs = [target_a, NULL_ADDRESS, target_b, NULL_ADDRESS]
        first_nonce = 0
        expected_code = b""
        # Only the first set is net-new; the clears credit nothing and
        # the second set is not net-new (already set in this tx).
        net_new = [True, False, False, False]

    authorization_list = [
        AuthorizationTuple(
            address=address,
            nonce=first_nonce + offset,
            signer=authority,
            creates_account=False,
            writes_delegation=net_new[offset],
            # Only the first authorization writes the authority's leaf;
            # later ones on the same authority are not first writes.
            first_write=(offset == 0),
        )
        for offset, address in enumerate(auth_specs)
    ]

    total_gas_cost = authorization_transaction_cost(fork, authorization_list)

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

    post = {
        authority: Account(
            nonce=first_nonce + len(auth_specs),
            balance=authority_initial_balance,
            code=expected_code,
        ),
    }

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.