Skip to content

test_self_sponsored_authorization()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_self_sponsored_authorization@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_self_sponsored_authorization --fork Amsterdam

Test a self-sponsored authorization where the sender is the authority.

The transaction consumes the sender's nonce (0 -> 1) before set_delegation runs, so the authorization must carry nonce=1 to match. set_delegation then applies the delegation and bumps the nonce again (1 -> 2). The sender's leaf already exists (no NEW_ACCOUNT) and was already written at inclusion -- priced into TX_BASE -- so the delegation write is not the transaction's first write to it (no ACCOUNT_WRITE); only the top-frame AUTH_BASE is charged, with no refund.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
@pytest.mark.valid_from("EIP8037")
def test_self_sponsored_authorization(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test a self-sponsored authorization where the sender is the authority.

    The transaction consumes the sender's nonce (0 -> 1) before
    ``set_delegation`` runs, so the authorization must carry ``nonce=1``
    to match. ``set_delegation`` then applies the delegation and bumps the
    nonce again (1 -> 2). The sender's leaf already exists (no
    ``NEW_ACCOUNT``) and was already written at inclusion -- priced into
    ``TX_BASE`` -- so the delegation write is not the transaction's
    first write to it (no ``ACCOUNT_WRITE``); only the top-frame
    ``AUTH_BASE`` is charged, with no refund.
    """
    delegate = pre.deploy_contract(code=Op.STOP)
    recipient = pre.deploy_contract(code=Op.STOP)

    # Sender is also the authority (self-sponsored). The tx bumps the
    # sender nonce to 1 before set_delegation, so the auth uses nonce=1.
    sender = pre.fund_eoa()
    authorization_list = [
        AuthorizationTuple(
            address=delegate,
            nonce=1,
            signer=sender,
            creates_account=False,
            writes_delegation=True,
            # The sender's leaf is written at inclusion, so this is not
            # the transaction's first write to it.
            first_write=False,
        ),
    ]

    intrinsic_regular, top_frame_regular, top_frame_state = _auth_gas(
        fork, authorization_list
    )
    cumulative_gas_used, header_gas_used = _receipt_and_header(
        intrinsic_regular, top_frame_regular, top_frame_state
    )

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

    post = {
        sender: Account(
            nonce=2,
            code=Spec7702.delegation_designation(delegate),
        ),
    }
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=header_gas_used),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.