Skip to content

test_authorization_state_gas_scaling()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_authorization_state_gas_scaling@87aba1a3.

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_authorization_state_gas_scaling --fork Amsterdam

Test the top-frame authorization state gas scales with count.

Each authority is an existing funded EOA gaining a fresh delegation, so set_delegation charges only the top-frame AUTH_BASE per authorization (no NEW_ACCOUNT / ACCOUNT_WRITE and no refund). The receipt gas is the regular intrinsic plus num_auths * AUTH_BASE and the header gas_used is the max of the regular and state blocks.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@pytest.mark.parametrize(
    "num_auths",
    [
        pytest.param(1, id="single_auth"),
        pytest.param(3, id="three_auths"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_authorization_state_gas_scaling(
    state_test: StateTestFiller,
    pre: Alloc,
    num_auths: int,
    fork: Fork,
) -> None:
    """
    Test the top-frame authorization state gas scales with count.

    Each authority is an existing funded EOA gaining a fresh delegation,
    so ``set_delegation`` charges only the top-frame ``AUTH_BASE`` per
    authorization (no ``NEW_ACCOUNT`` / ``ACCOUNT_WRITE`` and no refund).
    The receipt gas is the regular intrinsic plus ``num_auths *
    AUTH_BASE`` and the header ``gas_used`` is the max of the regular and
    state blocks.
    """
    contract = pre.deploy_contract(code=Op.STOP)

    signers = [pre.fund_eoa() for _ in range(num_auths)]
    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=signer,
            creates_account=False,
            writes_delegation=True,
        )
        for signer in signers
    ]

    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=contract,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=cumulative_gas_used,
        ),
    )

    post = {
        signer: Account(code=Spec7702.delegation_designation(contract))
        for signer in signers
    }
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=header_gas_used),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.