Skip to content

test_block_2d_inclusion_execution_gate_full_gas_reservation()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_2d_inclusion_execution_gate_full_gas_reservation@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_2d_inclusion_execution_gate_full_gas_reservation --fork Bogota

Pin the flat execution-gas inclusion gate on a contract creation.

EIP-8037 measures min(TX_MAX_GAS_LIMIT, tx.gas) against execution_gas_available in full, with no credit for the NEW_ACCOUNT state gas the creation charges at its top frame. Filler STOP txs spend execution gas only, so the state budget stays full and only the execution gate can reject the creation.

Its gas_limit is the leftover execution budget plus over_by, where None means the state charge itself. A client crediting that charge would accept over_by=1 with slack and over_by=None exactly under strict >; the flat gate rejects both. over_by=0 is the control, valid either way.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
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
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "over_by",
    [
        pytest.param(0, id="exact_fit"),
        pytest.param(1, id="one_above", marks=pytest.mark.exception_test),
        pytest.param(
            None,
            id="state_charge_above",
            marks=pytest.mark.exception_test,
        ),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_block_2d_inclusion_execution_gate_full_gas_reservation(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    over_by: int | None,
) -> None:
    """
    Pin the flat execution-gas inclusion gate on a contract creation.

    EIP-8037 measures ``min(TX_MAX_GAS_LIMIT, tx.gas)`` against
    ``execution_gas_available`` in full, with no credit for the
    ``NEW_ACCOUNT`` state gas the creation charges at its top frame.
    Filler STOP txs spend execution gas only, so the state budget
    stays full and only the execution gate can reject the creation.

    Its ``gas_limit`` is the leftover execution budget plus
    ``over_by``, where ``None`` means the state charge itself. A
    client crediting that charge would accept ``over_by=1`` with
    slack and ``over_by=None`` exactly under strict ``>``; the flat
    gate rejects both. ``over_by=0`` is the control, valid either way.
    """
    init_code = bytes(Op.STOP)
    intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
    intrinsic_gas = intrinsic_calc()

    create_execution = intrinsic_calc(
        calldata=init_code,
        contract_creation=True,
    )
    create_state_charge = fork.transaction_top_frame_state_gas(
        contract_creation=True
    )

    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    delta = create_state_charge if over_by is None else over_by

    # The CREATE tx draws its state charge from gas_left, so it needs
    # both dimensions' gas within the leftover execution budget.
    create_gas = create_execution + create_state_charge
    num_fillers = create_state_charge // intrinsic_gas + 1
    filler_execution = num_fillers * intrinsic_gas
    block_gas_limit = max(
        filler_execution + create_gas,
        fork.minimum_block_gas_limit(),
    )
    execution_available = block_gas_limit - filler_execution
    tx_gas_limit = execution_available + delta

    assert execution_available >= create_gas
    assert tx_gas_limit <= gas_limit_cap and tx_gas_limit <= block_gas_limit

    assert tx_gas_limit - create_state_charge <= execution_available
    assert (tx_gas_limit > execution_available) == (delta > 0)

    error = TransactionException.GAS_ALLOWANCE_EXCEEDED if delta else None
    create_sender = pre.fund_eoa()
    create_tx = Transaction(
        to=None,
        data=init_code,
        gas_limit=tx_gas_limit,
        sender=create_sender,
        error=error,
    )

    post: dict = {}
    header_verify: Header | None = None
    if not delta:
        post = {
            compute_create_address(address=create_sender, nonce=0): Account(
                nonce=1
            ),
        }
        header_verify = Header(
            gas_used=max(
                filler_execution + create_execution,
                create_state_charge,
            ),
        )

    blockchain_test(
        genesis_environment=Environment(gas_limit=block_gas_limit),
        pre=pre,
        blocks=[
            Block(
                txs=stop_txs(pre, fork, num_fillers) + [create_tx],
                gas_limit=block_gas_limit,
                exception=error,
                header_verify=header_verify,
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 2 forks.