Skip to content

test_bal_invalid_omitted_slot_change_at_index()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_omitted_slot_change_at_index@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_omitted_slot_change_at_index --fork Amsterdam

Test that clients reject a BAL that drops a slot's earlier change while keeping its later one, misattributing the slot's first recorded change to a later transaction than the one that made it.

Two transactions each write storage slot 0 of the same contract via the transaction's call value. The BAL is corrupted by removing only the first transaction's slot_changes entry for slot 0, leaving the second transaction's entry as the slot's only recorded change.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
@pytest.mark.valid_from("Amsterdam")
@pytest.mark.exception_test
def test_bal_invalid_omitted_slot_change_at_index(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """
    Test that clients reject a BAL that drops a slot's earlier change
    while keeping its later one, misattributing the slot's first
    recorded change to a later transaction than the one that made it.

    Two transactions each write storage slot 0 of the same contract via
    the transaction's call value. The BAL is corrupted by removing only
    the first transaction's slot_changes entry for slot 0, leaving the
    second transaction's entry as the slot's only recorded change.
    """
    alice = pre.fund_eoa()
    writer = pre.deploy_contract(code=Op.SSTORE(0, Op.CALLVALUE))

    tx1 = Transaction(sender=alice, to=writer, value=1)
    tx2 = Transaction(sender=alice, to=writer, value=2)

    blockchain_test(
        pre=pre,
        # The block reverts and the post state remains unchanged.
        post=pre,
        blocks=[
            Block(
                txs=[tx1, tx2],
                # Clients that execute against the declared BAL see gas
                # diverge before the BAL comparison (e.g. geth, reth).
                exception=[
                    BlockException.INVALID_BLOCK_ACCESS_LIST,
                    BlockException.INVALID_GAS_USED,
                ],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                ),
                                BalNonceChange(
                                    block_access_index=2, post_nonce=2
                                ),
                            ],
                        ),
                        writer: BalAccountExpectation(
                            balance_changes=[
                                BalBalanceChange(
                                    block_access_index=1, post_balance=1
                                ),
                                BalBalanceChange(
                                    block_access_index=2, post_balance=3
                                ),
                            ],
                            storage_changes=[
                                BalStorageSlot(
                                    slot=0,
                                    slot_changes=[
                                        BalStorageChange(
                                            block_access_index=1,
                                            post_value=1,
                                        ),
                                        BalStorageChange(
                                            block_access_index=2,
                                            post_value=2,
                                        ),
                                    ],
                                ),
                            ],
                        ),
                    }
                ).modify(
                    remove_slot_change(writer, slot=0, block_access_index=1)
                ),
            )
        ],
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.