Skip to content

test_calldata_floor_not_discounted_by_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py::test_calldata_floor_not_discounted_by_state_gas@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py::test_calldata_floor_not_discounted_by_state_gas --fork Amsterdam

Verify state gas spending does not discount the block-level floor.

Calldata is sized so the floor sits between the transaction's execution-gas portion and its total gas used (tx_execution < floor < tx_execution + state). The sender's bill is the pre-floor total, yet the block's execution dimension must still charge the full floor: the floor is compared against the execution portion alone, so state gas cannot absorb it. An implementation that instead floors the transaction total before deducting state gas (or skips the floor entirely) would report the state dimension in the header; the correct header gas_used is the floor.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py
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
@pytest.mark.valid_from("EIP8037")
def test_calldata_floor_not_discounted_by_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify state gas spending does not discount the block-level floor.

    Calldata is sized so the floor sits between the transaction's
    execution-gas portion and its total gas used
    (``tx_execution < floor < tx_execution + state``). The sender's bill is
    the pre-floor total, yet the block's execution dimension must still
    charge the full floor: the floor is compared against the execution
    portion alone, so state gas cannot absorb it. An implementation
    that instead floors the transaction total before deducting state
    gas (or skips the floor entirely) would report the state dimension
    in the header; the correct header gas_used is the floor.
    """
    storage = Storage()
    code = Op.SSTORE(storage.store_next(1), 1, new_value=1)
    state_cost = code.state_cost(fork)
    execution_cost = code.execution_cost(fork)
    floor_cost = fork.transaction_data_floor_cost_calculator()

    # Smallest zero-byte calldata whose floor exceeds the state
    # dimension; the floor then also dominates the header.
    size = 0
    while floor_cost(data=b"\x00" * size) <= state_cost:
        size += 32
    calldata = b"\x00" * size
    floor = floor_cost(data=calldata)

    intrinsic = fork.transaction_intrinsic_cost_calculator()(
        calldata=calldata,
        return_cost_deducted_prior_execution=True,
    )
    tx_execution = intrinsic + execution_cost
    tx_total = tx_execution + state_cost
    assert tx_execution < floor < tx_total, (
        "floor must bind the execution portion but not the total"
    )

    contract = pre.deploy_contract(code=code)

    tx = Transaction(
        to=contract,
        data=calldata,
        state_gas_reservoir=state_cost,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=tx_total),
    )
    state_test(
        pre=pre,
        post={contract: Account(storage=storage)},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=floor),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.