Skip to content

test_intrinsic_regular_gas_exceeds_cap()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_intrinsic_regular_gas_exceeds_cap@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_intrinsic_regular_gas_exceeds_cap --fork Amsterdam

Reject a transaction whose intrinsic regular gas exceeds the cap.

EIP-8037 enforces max(intrinsic_regular, calldata_floor) <= TX_MAX_GAS_LIMIT after the separate sufficiency check max(intrinsic_total, calldata_floor) <= tx.gas. A large access list raises the regular intrinsic over the cap while adding no state gas and keeping the calldata floor below the cap. gas_limit is set above the total intrinsic so the sufficiency check passes and the cap is the only reason the transaction is rejected; a client that compares the intrinsic against tx.gas but never against the cap would wrongly accept it.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
@pytest.mark.exception_test
@pytest.mark.valid_from("EIP8037")
def test_intrinsic_regular_gas_exceeds_cap(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Reject a transaction whose intrinsic *regular* gas exceeds the cap.

    EIP-8037 enforces ``max(intrinsic_regular, calldata_floor) <=
    TX_MAX_GAS_LIMIT`` after the separate sufficiency check
    ``max(intrinsic_total, calldata_floor) <= tx.gas``. A large access list
    raises the regular intrinsic over the cap while adding no state gas and
    keeping the calldata floor below the cap. ``gas_limit`` is set above the
    total intrinsic so the sufficiency check passes and the cap is the only
    reason the transaction is rejected; a client that compares the intrinsic
    against ``tx.gas`` but never against the cap would wrongly accept it.
    """
    cap = fork.transaction_gas_limit_cap()
    assert cap is not None
    floor_cost = fork.transaction_data_floor_cost_calculator()
    intrinsic = fork.transaction_intrinsic_cost_calculator()

    access_list = _access_list_over_regular_cap(fork, cap)
    regular = intrinsic(
        access_list=access_list,
        return_cost_deducted_prior_execution=True,
    )
    floor = floor_cost(data=b"", access_list=access_list)
    tx_gas = regular + 1_000_000

    assert max(regular, floor) > cap, "cap check must fire"
    assert regular <= tx_gas, "sufficiency check must not fire"
    assert floor <= tx_gas

    tx = Transaction(
        ty=1,
        to=pre.deploy_contract(code=Op.STOP),
        gas_limit=tx_gas,
        access_list=access_list,
        sender=pre.fund_eoa(),
        error=TransactionException.INTRINSIC_GAS_TOO_LOW,
    )
    state_test(pre=pre, post={}, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.