Skip to content

test_bal_4788_invalid_calldata_size()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4788.py::test_bal_4788_invalid_calldata_size@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4788.py::test_bal_4788_invalid_calldata_size --fork Amsterdam

Ensure BAL correctly handles EIP-4788 queries with invalid calldata size.

EIP-4788 requires exactly 32 bytes of calldata (a timestamp). Any other size causes immediate revert before any storage access occurs.

Test scenarios with and without value transfer: 1. Empty calldata (0 bytes): Reverts immediately 2. Too short (31 bytes): Reverts before storage access 3. Too long (33 bytes): Reverts before storage access

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4788.py
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
@pytest.mark.parametrize(
    "calldata_size",
    [
        pytest.param(0, id="empty_calldata"),
        pytest.param(31, id="calldata_too_short"),
        pytest.param(33, id="calldata_too_long"),
    ],
)
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="no_value"),
        pytest.param(100, id="with_value"),
    ],
)
def test_bal_4788_invalid_calldata_size(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    calldata_size: int,
    value: int,
) -> None:
    """
    Ensure BAL correctly handles EIP-4788 queries with invalid calldata size.

    EIP-4788 requires exactly 32 bytes of calldata (a timestamp). Any other
    size causes immediate revert before any storage access occurs.

    Test scenarios with and without value transfer:
    1. Empty calldata (0 bytes): Reverts immediately
    2. Too short (31 bytes): Reverts before storage access
    3. Too long (33 bytes): Reverts before storage access
    """
    alice = pre.fund_eoa()

    block_timestamp = 12
    beacon_root = Hash(0xABCDEF)

    # Contract that calls beacon roots contract with variable-size calldata
    # and stores returned beacon root in slot 0
    query_code = (
        Op.CALLDATACOPY(0, 0, calldata_size)
        + Op.CALL(
            Spec.BEACON_ROOTS_CALL_GAS,
            BEACON_ROOTS_ADDRESS,
            Op.CALLVALUE,
            0,
            calldata_size,
            32,
            32,
        )
        + Op.SSTORE(0, Op.MLOAD(32))
    )
    query_contract = pre.deploy_contract(query_code)

    # Pad calldata to requested size
    calldata = b"\x00" * calldata_size

    tx = Transaction(
        sender=alice,
        to=query_contract,
        data=calldata,
        value=value,
        gas_limit=fork.transaction_gas_limit_cap(),
    )

    account_expectations = beacon_root_system_call_expectations(
        block_timestamp, beacon_root
    )
    # Beacon roots contract reverts before any storage access
    account_expectations[BEACON_ROOTS_ADDRESS].storage_reads = []
    if value > 0:
        account_expectations[BEACON_ROOTS_ADDRESS].balance_changes = []

    account_expectations[alice] = BalAccountExpectation(
        nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
    )

    account_expectations[query_contract] = BalAccountExpectation(
        # SSTORE(0, 0) is a no-op write, becomes implicit read
        storage_reads=[0],
        storage_changes=[],
        # Value stays in query contract when call reverts
        balance_changes=[
            BalBalanceChange(block_access_index=1, post_balance=value)
        ]
        if value > 0
        else [],
    )

    block = Block(
        txs=[tx],
        parent_beacon_block_root=beacon_root,
        timestamp=block_timestamp,
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=account_expectations
        ),
    )

    post_state: dict[Address, Account] = {
        alice: Account(nonce=1),
        query_contract: Account(storage={0: 0}),
    }

    if value > 0:
        post_state[query_contract] = Account(storage={0: 0}, balance=value)

    blockchain_test(
        pre=pre,
        blocks=[block],
        post=post_state,
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 1 fork.