Skip to content

test_calldata_floor_contract_creation()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py::test_calldata_floor_contract_creation@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py::test_calldata_floor_contract_creation --fork Amsterdam

A contract creation whose calldata floor exceeds the creation intrinsic plus the created account's NEW_ACCOUNT state charge.

The init code is all zeros: it executes a free STOP, deploys empty code, and prices every byte as one floor token.

  • floor_binds: gas_used pins to the floor, which anchors on the creation execution base (TX_BASE + CREATE_ACCESS) but excludes the created account's NEW_ACCOUNT state charge and the init-code word cost -- both masked by the binding floor -- while the deploy (and any moved wei) still lands. The receipt pins the floor exactly.
  • below_floor: a gas limit one short of the floor still covers the creation intrinsic, so the rejection is pinned to the floor, with INTRINSIC_GAS_BELOW_FLOOR_GAS_COST.
Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
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
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
    "outcome",
    [
        pytest.param("floor_binds", id="floor_binds"),
        pytest.param(
            "below_floor",
            id="below_floor_rejected",
            marks=pytest.mark.exception_test,
        ),
    ],
)
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_calldata_floor_contract_creation(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    outcome: str,
    value: int,
) -> None:
    """
    A contract creation whose calldata floor exceeds the creation
    intrinsic plus the created account's ``NEW_ACCOUNT`` state charge.

    The init code is all zeros: it executes a free ``STOP``, deploys
    empty code, and prices every byte as one floor token.

    - ``floor_binds``: ``gas_used`` pins to the floor, which anchors
      on the creation execution base (``TX_BASE + CREATE_ACCESS``)
      but excludes the created account's ``NEW_ACCOUNT`` *state* charge
      and the init-code word cost -- both masked by the binding floor --
      while the deploy (and any moved wei) still lands.
      The receipt pins the floor exactly.
    - ``below_floor``: a gas limit one short of the floor still covers
      the creation intrinsic, so the rejection is pinned to the floor,
      with ``INTRINSIC_GAS_BELOW_FLOOR_GAS_COST``.
    """
    sender = pre.fund_eoa()
    created = compute_create_address(address=sender, nonce=sender.nonce)

    init_code = _floor_dominating_initcode(fork)
    calldata_floor = fork.transaction_data_floor_cost_calculator()(
        data=init_code,
        contract_creation=True,
        sends_value=bool(value),
    )

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        calldata=init_code,
        contract_creation=True,
        sends_value=bool(value),
        return_cost_deducted_prior_execution=True,
    )
    assert intrinsic_gas < calldata_floor, (
        "the calldata floor must dominate the creation intrinsic"
    )

    post: dict[Address, Account | None] = {}
    if outcome == "below_floor":
        # One gas short of the floor still covers the creation
        # intrinsic, so the floor is the only thing that can reject it;
        # the post state is empty and there is no receipt to assert
        # against (transaction rejected, never included).
        gas_limit = calldata_floor - 1
        tx = Transaction(
            sender=sender,
            to=None,
            value=value,
            data=init_code,
            gas_limit=gas_limit,
            error=TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
        )
    else:
        # ``floor_binds``: headroom above the floor; the receipt pins
        # ``gas_used`` to exactly the floor, so the ``NEW_ACCOUNT``
        # state charge is masked while the deploy still happens.
        tx = Transaction(
            sender=sender,
            to=None,
            value=value,
            data=init_code,
            gas_limit=calldata_floor,
            expected_receipt=TransactionReceipt(
                cumulative_gas_used=calldata_floor,
            ),
        )
        post = {
            sender: Account(nonce=1),
            created: Account(nonce=1, balance=value, code=b""),
        }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.