Skip to content

test_oversized_initcode_opcode_no_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_oversized_initcode_opcode_no_state_gas@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_oversized_initcode_opcode_no_state_gas --fork Amsterdam

Verify CREATE/CREATE2 with oversized initcode fails the size check before any state gas is charged.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
@pytest.mark.parametrize(
    "initcode_size_delta",
    [
        pytest.param(0, id="at_max"),
        pytest.param(1, id="over_max"),
    ],
)
@pytest.mark.with_all_create_opcodes()
@pytest.mark.valid_from("EIP8037")
def test_oversized_initcode_opcode_no_state_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
    initcode_size_delta: int,
) -> None:
    """
    Verify CREATE/CREATE2 with oversized initcode fails the size
    check before any state gas is charged.
    """
    max_size = fork.max_initcode_size()
    size = max_size + initcode_size_delta
    initcode = Initcode(deploy_code=Op.STOP, initcode_length=size)
    initcode_bytes = bytes(initcode)

    gas_costs = fork.gas_costs()
    create_state_gas = gas_costs.NEW_ACCOUNT

    create_call = (
        create_opcode(
            value=0,
            offset=0,
            size=Op.CALLDATASIZE,
            salt=0,
            init_code_size=len(initcode_bytes),
        )
        if create_opcode == Op.CREATE2
        else create_opcode(value=0, offset=0, size=Op.CALLDATASIZE)
    )

    factory = pre.deploy_contract(
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE) + Op.SSTORE(0, create_call)
    )

    create_address = compute_create_address(
        address=factory,
        nonce=1,
        salt=0,
        initcode=initcode,
        opcode=create_opcode,
    )

    storage = Storage()
    storage[0] = create_address if initcode_size_delta == 0 else 0

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=factory,
        data=initcode_bytes,
        state_gas_reservoir=create_state_gas,
    )

    post: dict = {factory: Account(storage=storage)}
    if initcode_size_delta == 0:
        post[create_address] = Account(code=Op.STOP)
    else:
        post[create_address] = Account.NONEXISTENT

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx])],
        post=post,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.