Skip to content

test_bal_2935_invalid_calldata_size()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip2935.py::test_bal_2935_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_eip2935.py::test_bal_2935_invalid_calldata_size --fork Amsterdam

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

EIP-2935 requires exactly 32 bytes of calldata. 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_eip2935.py
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
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
@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_2935_invalid_calldata_size(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    calldata_size: int,
    value: int,
) -> None:
    """
    Ensure BAL correctly handles EIP-2935 queries with invalid calldata size.

    EIP-2935 requires exactly 32 bytes of calldata. 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()

    # Contract that calls history storage contract with variable-size calldata
    # and stores returned block hash in slot 0
    query_code = (
        Op.CALLDATACOPY(0, 0, calldata_size)
        + Op.CALL(
            Op.GAS,
            HISTORY_STORAGE_ADDRESS,
            Op.CALLVALUE,
            0,
            calldata_size,
            32,
            32,
        )
        + Op.SSTORE(0, Op.MLOAD(32))
    )
    oracle = pre.deploy_contract(query_code)

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

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

    # Block 1: Setup block that writes genesis block-hash via system call
    block_1 = Block(
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=block_hash_system_call_expectations(0)
        )
    )

    # Block 2: Query with invalid calldata size
    account_expectations = block_hash_system_call_expectations(1)
    # History storage contract reverts before any storage access
    account_expectations[HISTORY_STORAGE_ADDRESS].storage_reads = []
    if value > 0:
        account_expectations[HISTORY_STORAGE_ADDRESS].balance_changes = []

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

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

    block_2 = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=account_expectations
        ),
    )

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

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

    blockchain_test(
        pre=pre,
        blocks=[block_1, block_2],
        post=post_state,
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 1 fork.