Skip to content

test_calldata_floor_with_authorizations()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py::test_calldata_floor_with_authorizations@8acae1b0.

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_with_authorizations --fork Amsterdam

A data-heavy type-4 transaction whose calldata floor exceeds the full authorization total: the intrinsic plus the authorization's top-frame execution and state charges.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@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,
        ),
    ],
)
def test_calldata_floor_with_authorizations(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    outcome: str,
) -> None:
    """
    A data-heavy type-4 transaction whose calldata floor exceeds the
    full authorization total: the intrinsic plus the authorization's
    top-frame execution and state charges.
    """
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)
    scenario = build_authorization(
        pre, AuthorizationAction.SETS_NEW_DELEGATION
    )
    authorization_list = [scenario.authorization]

    intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
    floor_calc = fork.transaction_data_floor_cost_calculator()
    top_frame_gas = fork.transaction_top_frame_execution_gas(
        recipient_type=RecipientType.CONTRACT,
        authorizations=authorization_list,
    )
    top_frame_state_gas = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.CONTRACT,
        authorizations=authorization_list,
    )

    def total(byte_count: int) -> int:
        return (
            intrinsic_calc(
                calldata=b"\x00" * byte_count,
                recipient_type=RecipientType.CONTRACT,
                authorization_list_or_count=authorization_list,
                return_cost_deducted_prior_execution=True,
            )
            + top_frame_gas
            + top_frame_state_gas
        )

    def floor(byte_count: int) -> int:
        return floor_calc(
            data=b"\x00" * byte_count,
            recipient_type=RecipientType.CONTRACT,
        )

    threshold = find_floor_cost_threshold(
        floor_data_gas_cost_calculator=floor,
        intrinsic_gas_cost_calculator=total,
    )
    byte_count = threshold + 1
    calldata = Bytes(b"\x00" * byte_count)
    calldata_floor = floor(byte_count)
    assert calldata_floor > total(byte_count), (
        "the calldata floor must dominate the full authorization total"
    )

    post: dict[Address, Account | None]
    if outcome == "below_floor":
        tx = Transaction(
            sender=sender,
            to=recipient,
            data=calldata,
            authorization_list=authorization_list,
            gas_limit=calldata_floor - 1,
            error=TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
        )
        post = {scenario.authority: scenario.original_account}
    else:
        tx = Transaction(
            sender=sender,
            to=recipient,
            data=calldata,
            authorization_list=authorization_list,
            gas_limit=calldata_floor,
            expected_receipt=TransactionReceipt(
                cumulative_gas_used=calldata_floor,
            ),
        )
        post = {
            sender: Account(nonce=1),
            scenario.authority: scenario.applied_account,
        }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.