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@26332146.

Generate fixtures for these test cases for Amsterdam with:

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

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
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
@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 1 fork.