Skip to content

test_authorization_exact_state_gas_boundary()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_authorization_exact_state_gas_boundary@622620d8.

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

Test the intrinsic-gas boundary and the top-frame OOG behaviour.

Under EIP-2780 the intrinsic is execution-only, so the boundary keys off fork.transaction_intrinsic_cost_calculator()(auth_list). With gas_delta=-1 the transaction is one gas below the intrinsic and is rejected as intrinsic-gas-too-low. With gas_delta=0 the gas limit equals the intrinsic exactly, so the transaction is included but has zero gas left for the top frame: the authority's NEW_ACCOUNT state charge in set_delegation runs out of gas, the whole preparation rolls back, and the authority is never created.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "gas_delta",
    [
        pytest.param(0, id="exact_gas"),
        pytest.param(
            -1,
            id="one_short",
            marks=pytest.mark.exception_test,
        ),
    ],
)
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@pytest.mark.valid_from("EIP8037")
def test_authorization_exact_state_gas_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_delta: int,
) -> None:
    """
    Test the intrinsic-gas boundary and the top-frame OOG behaviour.

    Under EIP-2780 the intrinsic is execution-only, so the boundary keys off
    ``fork.transaction_intrinsic_cost_calculator()(auth_list)``. With
    ``gas_delta=-1`` the transaction is one gas below the intrinsic and is
    rejected as intrinsic-gas-too-low. With ``gas_delta=0`` the gas limit
    equals the intrinsic exactly, so the transaction is included but has
    zero gas left for the top frame: the authority's ``NEW_ACCOUNT`` state
    charge in ``set_delegation`` runs out of gas, the whole preparation
    rolls back, and the authority is never created.
    """
    target = pre.deploy_contract(code=Op.STOP)
    recipient = pre.deploy_contract(code=Op.STOP)

    # A fresh (nonexistent) authority so the first top-frame charge is
    # NEW_ACCOUNT, which OOGs when no gas is left after the intrinsic.
    signer = pre.fund_eoa(amount=0)
    authorization_list = [
        AuthorizationTuple(
            address=target,
            nonce=0,
            signer=signer,
            creates_account=True,
            writes_delegation=True,
        ),
    ]

    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=authorization_list,
    )

    is_rejected = gas_delta < 0
    tx = Transaction(
        to=recipient,
        gas_limit=intrinsic_cost + gas_delta,
        authorization_list=authorization_list,
        sender=pre.fund_eoa(),
        error=(
            TransactionException.INTRINSIC_GAS_TOO_LOW if is_rejected else None
        ),
    )

    # gas_delta == 0: tx included, top-frame OOG rolls back the auth, so
    # the authority leaf is never created.
    # gas_delta == -1: tx rejected before execution; authority untouched.
    post = {signer: Account.NONEXISTENT}
    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                exception=(
                    TransactionException.INTRINSIC_GAS_TOO_LOW
                    if is_rejected
                    else None
                ),
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.