Skip to content

test_creation_tx_regular_check_uses_full_tx_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_creation_tx_regular_check_uses_full_tx_gas@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_creation_tx_regular_check_uses_full_tx_gas --fork Amsterdam

Verify the regular check uses the full tx.gas (no subtraction).

The EIP regular check is min(TX_MAX, tx.gas) > regular_available. Under EIP-2780 a creation tx has intrinsic.state == 0 (the created account's NEW_ACCOUNT moved to the top frame), so its intrinsic is regular-only. This test sizes a creation tx whose full tx.gas exceeds the remaining regular budget by one — it must be rejected. A formula that instead used the execution gas (tx.gas - intrinsic_regular) would have wrongly accepted.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
@pytest.mark.exception_test
@pytest.mark.valid_from("EIP8037")
def test_creation_tx_regular_check_uses_full_tx_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify the regular check uses the full `tx.gas` (no subtraction).

    The EIP regular check is `min(TX_MAX, tx.gas) > regular_available`.
    Under EIP-2780 a creation tx has `intrinsic.state == 0` (the created
    account's `NEW_ACCOUNT` moved to the top frame), so its intrinsic is
    regular-only. This test sizes a creation tx whose full `tx.gas`
    exceeds the remaining regular budget by one — it must be rejected. A
    formula that instead used the execution gas
    (`tx.gas - intrinsic_regular`) would have wrongly accepted.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    # The creation intrinsic is regular-only and cpsb-free
    # (GAS_TX_BASE + REGULAR_GAS_CREATE + init_code_cost), giving a stable
    # `block_gas_limit` independent of cpsb.
    intrinsic_regular = fork.transaction_intrinsic_cost_calculator()(
        contract_creation=True
    )

    # Tight boundary: after the filler consumes gas_limit_cap, exactly
    # `intrinsic_regular + 1` regular gas remains in the block.
    block_gas_limit = gas_limit_cap + intrinsic_regular + 1

    # Ask for one more than the remaining regular budget: min(TX_MAX,
    # tx.gas) == tx.gas exceeds `remaining_regular` by one, so the strict
    # check rejects. The tx still carries more than its own intrinsic, so
    # it is a valid creation tx on its own — only the block-level regular
    # check fails.
    remaining_regular = block_gas_limit - gas_limit_cap
    create_tx_gas = remaining_regular + 1

    # Filler consumes the full regular cap (OOG on INVALID).
    filler = pre.deploy_contract(code=Op.INVALID)

    assert create_tx_gas <= gas_limit_cap, (
        "min(TX_MAX, tx.gas) must be tx.gas for this boundary"
    )
    assert create_tx_gas > intrinsic_regular, (
        "tx must carry more than its own intrinsic"
    )
    assert min(gas_limit_cap, create_tx_gas) > remaining_regular, (
        "strict formula must reject: full tx.gas exceeds remaining regular"
    )
    assert create_tx_gas - intrinsic_regular <= remaining_regular, (
        "a formula using execution gas would have accepted"
    )

    filler_tx = Transaction(
        to=filler,
        gas_limit=gas_limit_cap,
        sender=pre.fund_eoa(),
    )
    create_tx = Transaction(
        to=None,
        gas_limit=create_tx_gas,
        sender=pre.fund_eoa(),
        error=TransactionException.GAS_ALLOWANCE_EXCEEDED,
    )

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=[filler_tx, create_tx],
                gas_limit=block_gas_limit,
                exception=TransactionException.GAS_ALLOWANCE_EXCEEDED,
            )
        ],
        post={},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.