Skip to content

test_bal_create_early_failure()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_create_early_failure@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_create_early_failure --fork Amsterdam

Test BAL with CREATE/CREATE2 failure due to insufficient endowment.

Factory (balance=50) attempts CREATE/CREATE2(value=100). Fails before nonce increment (before track_address). Distinct from collision where address IS accessed.

Expected BAL: - Alice: nonce_changes - Factory: storage_changes slot 0 (0xDEAD→0), NO nonce_changes - Contract address: MUST NOT appear (never accessed)

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
@pytest.mark.with_all_create_opcodes
def test_bal_create_early_failure(
    pre: Alloc, blockchain_test: BlockchainTestFiller, create_opcode: Op
) -> None:
    """
    Test BAL with CREATE/CREATE2 failure due to insufficient endowment.

    Factory (balance=50) attempts CREATE/CREATE2(value=100).
    Fails before nonce increment (before track_address).
    Distinct from collision where address IS accessed.

    Expected BAL:
    - Alice: nonce_changes
    - Factory: storage_changes slot 0 (0xDEAD→0), NO nonce_changes
    - Contract address: MUST NOT appear (never accessed)
    """
    alice = pre.fund_eoa()

    factory_balance = 50
    endowment = 100

    init_code = Initcode(deploy_code=Op.STOP)
    init_code_bytes = bytes(init_code)

    factory_code = (
        Op.MSTORE(0, Op.PUSH32(init_code_bytes))
        + Op.SSTORE(
            0x00,
            create_opcode(
                value=endowment,
                offset=32 - len(init_code_bytes),
                size=len(init_code_bytes),
            ),
        )
        + Op.STOP
    )

    factory = pre.deploy_contract(
        code=factory_code,
        balance=factory_balance,
        storage={0x00: 0xDEAD},
    )

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

    tx = Transaction(sender=alice, to=factory)

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                factory: BalAccountExpectation(
                    nonce_changes=[],
                    storage_changes=[
                        BalStorageSlot(
                            slot=0x00,
                            slot_changes=[
                                BalStorageChange(
                                    block_access_index=1, post_value=0
                                )
                            ],
                        )
                    ],
                ),
                would_be_contract_address: None,
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            factory: Account(
                nonce=1, balance=factory_balance, storage={0x00: 0}
            ),
            would_be_contract_address: Account.NONEXISTENT,
        },
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.