Skip to content

test_authorization_list_intrinsic_gas()

Documentation for tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py::TestAuthorizationListGasCost::test_authorization_list_intrinsic_gas@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py::TestAuthorizationListGasCost::test_authorization_list_intrinsic_gas --fork Amsterdam

Verify authorization list gas costs are included correctly.

Source code in tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
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
783
784
785
786
787
788
789
790
791
792
793
class TestAuthorizationListGasCost:
    """Verify authorization list gas costs are included correctly."""

    @pytest.fixture
    def sender(self, pre: Alloc) -> Address:
        """Create sender account."""
        return pre.fund_eoa()

    @pytest.fixture
    def to(self, pre: Alloc) -> Address:
        """Deploy a simple contract."""
        return pre.deploy_contract(Op.STOP)

    @pytest.mark.parametrize(
        "num_authorizations",
        [
            pytest.param(1, id="single_auth"),
            pytest.param(5, id="five_auths"),
            pytest.param(10, id="ten_auths"),
        ],
    )
    def test_authorization_list_intrinsic_gas(
        self,
        state_test: StateTestFiller,
        pre: Alloc,
        sender: Address,
        to: Address,
        fork: Fork,
        num_authorizations: int,
    ) -> None:
        """
        Verify the authorization-list intrinsic cost under EIP-2780.

        Each authorization adds exactly ``REGULAR_PER_AUTH_BASE_COST`` to
        the (regular) intrinsic; the state-dependent authorization costs
        moved to the top frame. Measured on the *raw* intrinsic (before
        the EIP-7623 calldata floor is applied) the per-authorization
        delta is exactly ``num_authorizations *
        REGULAR_PER_AUTH_BASE_COST`` -- even when the floor would
        otherwise mask it (e.g. a single authorization whose base cost
        stays below the floor). Each existing authority then pays the
        first-write ``ACCOUNT_WRITE`` (regular) and ``AUTH_BASE``
        (state) at the top frame, so with a STOP recipient the receipt
        is ``max(intrinsic_regular + num_authorizations *
        (ACCOUNT_WRITE + AUTH_BASE), floor_cost)``.
        """
        gas_costs = fork.gas_costs()

        # Existing authorities each gaining a fresh delegation. An
        # existing leaf pays the first-write ACCOUNT_WRITE and the
        # top-frame AUTH_BASE (no NEW_ACCOUNT), keeping the billing
        # clean.
        authorization_list = [
            AuthorizationTuple(
                signer=pre.fund_eoa(),
                address=Address(i + 1),
                nonce=0,
                creates_account=False,
                writes_delegation=True,
            )
            for i in range(num_authorizations)
        ]

        # Use calldata that triggers the floor cost.
        calldata = Bytes(b"\x01" * 500)

        intrinsic_cost_calculator = (
            fork.transaction_intrinsic_cost_calculator()
        )
        # Raw intrinsic (no floor max) isolates the per-authorization base
        # cost even when the calldata floor dominates the floored value.
        intrinsic_with_auth = intrinsic_cost_calculator(
            calldata=calldata,
            authorization_list_or_count=authorization_list,
            return_cost_deducted_prior_execution=True,
        )
        intrinsic_without_auth = intrinsic_cost_calculator(
            calldata=calldata,
            authorization_list_or_count=None,
            return_cost_deducted_prior_execution=True,
        )

        actual_auth_cost = intrinsic_with_auth - intrinsic_without_auth
        assert actual_auth_cost == (
            num_authorizations * gas_costs.REGULAR_PER_AUTH_BASE_COST
        ), (
            "auth intrinsic must be n * REGULAR_PER_AUTH_BASE_COST, got: "
            f"{actual_auth_cost}"
        )

        floor_cost = fork.transaction_data_floor_cost_calculator()(
            data=calldata
        )
        # Existing authorities pay the first-write ACCOUNT_WRITE
        # (regular) and AUTH_BASE (state) each at the top frame; the
        # STOP recipient does no execution, so the receipt is
        # max(regular + state, floor).
        top_frame_regular = fork.transaction_top_frame_gas_calculator()(
            authorizations=authorization_list,
        )
        top_frame_state = fork.transaction_top_frame_state_gas(
            authorizations=authorization_list,
        )
        expected_gas = max(
            intrinsic_with_auth + top_frame_regular + top_frame_state,
            floor_cost,
        )

        tx = Transaction(
            ty=4,  # Type 4 supports authorization lists
            sender=sender,
            to=to,
            data=calldata,
            gas_limit=expected_gas + 10_000,
            authorization_list=authorization_list,
            expected_receipt=TransactionReceipt(
                cumulative_gas_used=expected_gas
            ),
        )

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

test_authorization_list_intrinsic_gas(state_test, pre, sender, to, fork, num_authorizations)

Verify the authorization-list intrinsic cost under EIP-2780.

Each authorization adds exactly REGULAR_PER_AUTH_BASE_COST to the (regular) intrinsic; the state-dependent authorization costs moved to the top frame. Measured on the raw intrinsic (before the EIP-7623 calldata floor is applied) the per-authorization delta is exactly num_authorizations * REGULAR_PER_AUTH_BASE_COST -- even when the floor would otherwise mask it (e.g. a single authorization whose base cost stays below the floor). Each existing authority then pays the first-write ACCOUNT_WRITE (regular) and AUTH_BASE (state) at the top frame, so with a STOP recipient the receipt is max(intrinsic_regular + num_authorizations * (ACCOUNT_WRITE + AUTH_BASE), floor_cost).

Source code in tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
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
783
784
785
786
787
788
789
790
791
792
793
@pytest.mark.parametrize(
    "num_authorizations",
    [
        pytest.param(1, id="single_auth"),
        pytest.param(5, id="five_auths"),
        pytest.param(10, id="ten_auths"),
    ],
)
def test_authorization_list_intrinsic_gas(
    self,
    state_test: StateTestFiller,
    pre: Alloc,
    sender: Address,
    to: Address,
    fork: Fork,
    num_authorizations: int,
) -> None:
    """
    Verify the authorization-list intrinsic cost under EIP-2780.

    Each authorization adds exactly ``REGULAR_PER_AUTH_BASE_COST`` to
    the (regular) intrinsic; the state-dependent authorization costs
    moved to the top frame. Measured on the *raw* intrinsic (before
    the EIP-7623 calldata floor is applied) the per-authorization
    delta is exactly ``num_authorizations *
    REGULAR_PER_AUTH_BASE_COST`` -- even when the floor would
    otherwise mask it (e.g. a single authorization whose base cost
    stays below the floor). Each existing authority then pays the
    first-write ``ACCOUNT_WRITE`` (regular) and ``AUTH_BASE``
    (state) at the top frame, so with a STOP recipient the receipt
    is ``max(intrinsic_regular + num_authorizations *
    (ACCOUNT_WRITE + AUTH_BASE), floor_cost)``.
    """
    gas_costs = fork.gas_costs()

    # Existing authorities each gaining a fresh delegation. An
    # existing leaf pays the first-write ACCOUNT_WRITE and the
    # top-frame AUTH_BASE (no NEW_ACCOUNT), keeping the billing
    # clean.
    authorization_list = [
        AuthorizationTuple(
            signer=pre.fund_eoa(),
            address=Address(i + 1),
            nonce=0,
            creates_account=False,
            writes_delegation=True,
        )
        for i in range(num_authorizations)
    ]

    # Use calldata that triggers the floor cost.
    calldata = Bytes(b"\x01" * 500)

    intrinsic_cost_calculator = (
        fork.transaction_intrinsic_cost_calculator()
    )
    # Raw intrinsic (no floor max) isolates the per-authorization base
    # cost even when the calldata floor dominates the floored value.
    intrinsic_with_auth = intrinsic_cost_calculator(
        calldata=calldata,
        authorization_list_or_count=authorization_list,
        return_cost_deducted_prior_execution=True,
    )
    intrinsic_without_auth = intrinsic_cost_calculator(
        calldata=calldata,
        authorization_list_or_count=None,
        return_cost_deducted_prior_execution=True,
    )

    actual_auth_cost = intrinsic_with_auth - intrinsic_without_auth
    assert actual_auth_cost == (
        num_authorizations * gas_costs.REGULAR_PER_AUTH_BASE_COST
    ), (
        "auth intrinsic must be n * REGULAR_PER_AUTH_BASE_COST, got: "
        f"{actual_auth_cost}"
    )

    floor_cost = fork.transaction_data_floor_cost_calculator()(
        data=calldata
    )
    # Existing authorities pay the first-write ACCOUNT_WRITE
    # (regular) and AUTH_BASE (state) each at the top frame; the
    # STOP recipient does no execution, so the receipt is
    # max(regular + state, floor).
    top_frame_regular = fork.transaction_top_frame_gas_calculator()(
        authorizations=authorization_list,
    )
    top_frame_state = fork.transaction_top_frame_state_gas(
        authorizations=authorization_list,
    )
    expected_gas = max(
        intrinsic_with_auth + top_frame_regular + top_frame_state,
        floor_cost,
    )

    tx = Transaction(
        ty=4,  # Type 4 supports authorization lists
        sender=sender,
        to=to,
        data=calldata,
        gas_limit=expected_gas + 10_000,
        authorization_list=authorization_list,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_gas
        ),
    )

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

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.