Skip to content

test_bal_7702_recipient_excluded_on_authorization_oog()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_recipient_excluded_on_authorization_oog@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_recipient_excluded_on_authorization_oog --fork Amsterdam

Ensure tx.to enters the BAL only when authorization processing completes.

The single authorization is starved at its opening NEW_ACCOUNT charge, halting the transaction before the top-frame dispatch loads the recipient: the recipient must be absent from the BAL, while the authority -- read during authorization validation -- stays in it with no recorded changes.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
@pytest.mark.parametrize(
    "outcome",
    [
        pytest.param("oog", id="oog_at_authorization_charge"),
        pytest.param("success", id="success"),
    ],
)
def test_bal_7702_recipient_excluded_on_authorization_oog(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    outcome: str,
) -> None:
    """
    Ensure ``tx.to`` enters the BAL only when authorization processing
    completes.

    The single authorization is starved at its opening ``NEW_ACCOUNT``
    charge, halting the transaction before the top-frame dispatch loads
    the recipient: the recipient must be absent from the BAL, while the
    authority -- read during authorization validation -- stays in it
    with no recorded changes.
    """
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)

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

    intrinsic_execution = fork.transaction_intrinsic_cost_calculator()(
        recipient_type=RecipientType.CONTRACT,
        authorization_list_or_count=authorization_list,
        return_cost_deducted_prior_execution=True,
    )

    recipient_expectation: BalAccountExpectation | None
    expected_authority: Account | None
    if outcome == "oog":
        # The authorization runs out at its opening NEW_ACCOUNT state
        # charge, drawn from gas_left under the zero state reservoir.
        gas_limit = intrinsic_execution + fork.gas_costs().NEW_ACCOUNT - 1
        recipient_expectation = None
        authority_expectation = BalAccountExpectation.empty()
        expected_authority = auth.original_account
    else:
        top_frame_execution = fork.transaction_top_frame_gas_calculator()(
            recipient_type=RecipientType.CONTRACT,
            authorizations=authorization_list,
        )
        top_frame_state = fork.transaction_top_frame_state_gas(
            recipient_type=RecipientType.CONTRACT,
            authorizations=authorization_list,
        )
        gas_limit = intrinsic_execution + top_frame_execution + top_frame_state
        recipient_expectation = BalAccountExpectation.empty()
        authority_expectation = BalAccountExpectation(
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
            code_changes=[
                BalCodeChange(
                    block_access_index=1,
                    new_code=auth.applied_account.code,
                )
            ],
        )
        expected_authority = auth.applied_account

    tx = Transaction(
        sender=sender,
        to=recipient,
        authorization_list=authorization_list,
        gas_limit=gas_limit,
    )

    state_test(
        pre=pre,
        tx=tx,
        post={sender: Account(nonce=1), auth.authority: expected_authority},
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                recipient: recipient_expectation,
                auth.authority: authority_expectation,
            }
        ),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.