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@9c2813ee.

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
657
658
659
660
661
662
663
664
665
666
667
668
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
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 authorization list gas costs are included in intrinsic gas.

        Each authorization in the list adds a fixed gas cost to the
        intrinsic gas. This should be accounted for before comparing
        with floor cost.
        """
        # Create authorization list
        authorization_list = [
            AuthorizationTuple(
                signer=pre.fund_eoa(0),
                address=Address(i + 1),
            )
            for i in range(num_authorizations)
        ]

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

        # Calculate costs
        intrinsic_cost_calculator = (
            fork.transaction_intrinsic_cost_calculator()
        )
        intrinsic_cost_with_auth = intrinsic_cost_calculator(
            calldata=calldata,
            contract_creation=False,
            access_list=None,
            authorization_list_or_count=authorization_list,
        )

        intrinsic_cost_without_auth = intrinsic_cost_calculator(
            calldata=calldata,
            contract_creation=False,
            access_list=None,
            authorization_list_or_count=None,
        )

        floor_cost_calculator = fork.transaction_data_floor_cost_calculator()
        floor_cost = floor_cost_calculator(data=calldata)

        # Each authorization adds calldata cost for the authorization tuple
        # plus G_AUTHORIZATION gas cost. The difference we see should be
        # primarily from the authorization gas but may include calldata costs
        # for encoding the authorization list.
        actual_auth_cost = (
            intrinsic_cost_with_auth - intrinsic_cost_without_auth
        )
        # Just verify that there is a positive cost increase
        assert actual_auth_cost > 0, (
            f"Authorization should add gas cost, got: {actual_auth_cost}"
        )

        # The transaction should pay max(intrinsic_with_auth, floor_cost)
        expected_gas = max(intrinsic_cost_with_auth, floor_cost)

        tx = Transaction(
            ty=4,  # Type 4 supports authorization lists
            sender=sender,
            to=to,
            data=calldata,
            gas_limit=expected_gas,
            authorization_list=authorization_list,
        )

        tx.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 authorization list gas costs are included in intrinsic gas.

Each authorization in the list adds a fixed gas cost to the intrinsic gas. This should be accounted for before comparing with floor cost.

Source code in tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py
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
@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 authorization list gas costs are included in intrinsic gas.

    Each authorization in the list adds a fixed gas cost to the
    intrinsic gas. This should be accounted for before comparing
    with floor cost.
    """
    # Create authorization list
    authorization_list = [
        AuthorizationTuple(
            signer=pre.fund_eoa(0),
            address=Address(i + 1),
        )
        for i in range(num_authorizations)
    ]

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

    # Calculate costs
    intrinsic_cost_calculator = (
        fork.transaction_intrinsic_cost_calculator()
    )
    intrinsic_cost_with_auth = intrinsic_cost_calculator(
        calldata=calldata,
        contract_creation=False,
        access_list=None,
        authorization_list_or_count=authorization_list,
    )

    intrinsic_cost_without_auth = intrinsic_cost_calculator(
        calldata=calldata,
        contract_creation=False,
        access_list=None,
        authorization_list_or_count=None,
    )

    floor_cost_calculator = fork.transaction_data_floor_cost_calculator()
    floor_cost = floor_cost_calculator(data=calldata)

    # Each authorization adds calldata cost for the authorization tuple
    # plus G_AUTHORIZATION gas cost. The difference we see should be
    # primarily from the authorization gas but may include calldata costs
    # for encoding the authorization list.
    actual_auth_cost = (
        intrinsic_cost_with_auth - intrinsic_cost_without_auth
    )
    # Just verify that there is a positive cost increase
    assert actual_auth_cost > 0, (
        f"Authorization should add gas cost, got: {actual_auth_cost}"
    )

    # The transaction should pay max(intrinsic_with_auth, floor_cost)
    expected_gas = max(intrinsic_cost_with_auth, floor_cost)

    tx = Transaction(
        ty=4,  # Type 4 supports authorization lists
        sender=sender,
        to=to,
        data=calldata,
        gas_limit=expected_gas,
        authorization_list=authorization_list,
    )

    tx.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.