Skip to content

test_bal_invalid_phantom_read_on_selfdestruct()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_phantom_read_on_selfdestruct@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_phantom_read_on_selfdestruct --fork Bogota

Test that clients reject a BAL with a phantom storage read for an account created and destroyed within the same transaction.

A contract-creation transaction's init code immediately SELFDESTRUCTs, sending its endowment to beneficiary, without ever returning runtime code. Per EIP-6780 the created account is created and destroyed within the same transaction, so it has zero net BAL changes (its balance and code never persist), but the account still legitimately appears in the BAL as an entry with empty changes. The BAL is corrupted by injecting a phantom storage read for a slot the account never touched.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
@pytest.mark.valid_from("Amsterdam")
@pytest.mark.exception_test
def test_bal_invalid_phantom_read_on_selfdestruct(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """
    Test that clients reject a BAL with a phantom storage read for an
    account created and destroyed within the same transaction.

    A contract-creation transaction's init code immediately
    SELFDESTRUCTs, sending its endowment to beneficiary, without ever
    returning runtime code. Per EIP-6780 the created account is created
    and destroyed within the same transaction, so it has zero net BAL
    changes (its balance and code never persist), but the account still
    legitimately appears in the BAL as an entry with empty changes. The
    BAL is corrupted by injecting a phantom storage read for a slot the
    account never touched.
    """
    alice = pre.fund_eoa()
    beneficiary = pre.fund_eoa(amount=0)
    endowment = 100
    phantom_slot = 0x07

    initcode = Op.SELFDESTRUCT(beneficiary)
    created = compute_create_address(address=alice)

    tx = Transaction(sender=alice, to=None, data=initcode, value=endowment)

    blockchain_test(
        pre=pre,
        # The block reverts and the post state remains unchanged.
        post=pre,
        blocks=[
            Block(
                txs=[tx],
                exception=BlockException.INVALID_BLOCK_ACCESS_LIST,
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                )
                            ],
                        ),
                        created: BalAccountExpectation.empty(),
                        beneficiary: BalAccountExpectation(
                            balance_changes=[
                                BalBalanceChange(
                                    block_access_index=1,
                                    post_balance=endowment,
                                )
                            ],
                        ),
                    }
                ).modify(insert_storage_read(created, phantom_slot)),
            )
        ],
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.