Skip to content

test_warm_after_failed_create_over_max_code_size()

Documentation for tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py::test_warm_after_failed_create_over_max_code_size@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py::test_warm_after_failed_create_over_max_code_size --fork Amsterdam

Verify the would-be contract address is warm after a CREATE that fails because the returned deploy code exceeds max_code_size.

Unlike pre-validation aborts (insufficient balance, nonce overflow), the address is added to the access list during initcode execution, so the post-RETURN size check rejecting deployment must leave the address warm.

Source code in tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
@pytest.mark.parametrize(
    "create_opcode",
    [
        pytest.param(Op.CREATE, id="CREATE"),
        pytest.param(Op.CREATE2, id="CREATE2"),
    ],
)
def test_warm_after_failed_create_over_max_code_size(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
) -> None:
    """
    Verify the would-be contract address is warm after a CREATE that fails
    because the returned deploy code exceeds max_code_size.

    Unlike pre-validation aborts (insufficient balance, nonce overflow), the
    address is added to the access list during initcode execution, so the
    post-RETURN size check rejecting deployment must leave the address warm.
    """
    initcode = Op.RETURN(offset=0, size=fork.max_code_size() + 1)
    initcode_bytes = bytes(initcode)
    if create_opcode == Op.CREATE2:
        salt = CREATE2_SALT
        create_call = create_opcode(
            value=0,
            offset=0,
            size=len(initcode_bytes),
            salt=salt,
        )
    else:
        salt = 0
        create_call = create_opcode(
            value=0, offset=0, size=len(initcode_bytes)
        )

    creator_code = Op.MSTORE(
        0, Op.PUSH32(initcode_bytes.ljust(32, b"\0"))
    ) + Op.SSTORE(0, create_call)

    creator_address = pre.deploy_contract(creator_code, storage={0: 1})

    contract_address = compute_create_address(
        address=creator_address,
        nonce=1,
        salt=salt,
        initcode=initcode_bytes,
        opcode=create_opcode,
    )

    warm_balance = Op.BALANCE(contract_address, address_warm=True)
    checker_address = pre.deploy_contract(
        CodeGasMeasure(
            code=warm_balance,
            extra_stack_items=1,
            sstore_key=1,
        )
    )

    entry_address = pre.deploy_contract(
        Op.CALL(gas=Op.GAS, address=creator_address)
        + Op.CALL(gas=Op.GAS, address=checker_address)
        + Op.STOP
    )

    tx = Transaction(
        to=entry_address,
        gas_limit=fork.transaction_gas_limit_cap(),
        sender=pre.fund_eoa(),
    )

    post = {
        creator_address: Account(storage={0: 0}),
        checker_address: Account(storage={1: warm_balance.gas_cost(fork)}),
        contract_address: Account.NONEXISTENT,
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.