Skip to content

test_mixed_auths_header_gas_used_reflects_existing_refunds()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_mixed_auths_header_gas_used_reflects_existing_refunds@c74f1a67.

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

Verify the block header gas_used deducts only the existing-authority auth refunds across a mix of existing and new account authorizations.

Each existing authority contributes REFUND_AUTH_PER_EXISTING_ACCOUNT to state_refund; new authorities contribute none. Header gas_used is max(intrinsic_regular, intrinsic_state - num_existing * refund).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
@pytest.mark.parametrize(
    "num_existing,num_new",
    [
        pytest.param(1, 1, id="one_existing_one_new"),
        pytest.param(2, 2, id="two_existing_two_new"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_mixed_auths_header_gas_used_reflects_existing_refunds(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    num_existing: int,
    num_new: int,
) -> None:
    """
    Verify the block header gas_used deducts only the existing-authority
    auth refunds across a mix of existing and new account
    authorizations.

    Each existing authority contributes
    `REFUND_AUTH_PER_EXISTING_ACCOUNT` to `state_refund`; new
    authorities contribute none. Header gas_used is
    `max(intrinsic_regular, intrinsic_state - num_existing * refund)`.
    """
    num_auths = num_existing + num_new
    intrinsic_state_gas = fork.transaction_intrinsic_state_gas(
        authorization_count=num_auths,
    )
    total_intrinsic = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=num_auths,
    )
    intrinsic_regular = total_intrinsic - intrinsic_state_gas
    auth_refund = (
        fork.gas_costs().REFUND_AUTH_PER_EXISTING_ACCOUNT * num_existing
    )

    contract = pre.deploy_contract(code=Op.STOP)

    authorization_list = []
    for _ in range(num_existing):
        authorization_list.append(
            AuthorizationTuple(
                address=contract,
                nonce=0,
                signer=pre.fund_eoa(),
            )
        )
    for _ in range(num_new):
        authorization_list.append(
            AuthorizationTuple(
                address=contract,
                nonce=0,
                signer=pre.fund_eoa(amount=0),
            )
        )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=intrinsic_state_gas,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
    )

    expected_gas_used = max(
        intrinsic_regular,
        intrinsic_state_gas - auth_refund,
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.