Skip to content

test_bal_cross_tx_storage_revert_to_zero()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_cross_tx_storage_revert_to_zero@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_cross_tx_storage_revert_to_zero --fork Amsterdam

Ensure BAL captures storage changes when tx1 writes a non-zero value and tx2 reverts it back to zero. This is a regression test for the blobhash scenario where slot changes were being incorrectly filtered as net-zero across transaction boundaries.

Tx1: slot 0 = 0x0 -> 0xABCD (change at block_access_index=1) Tx2: slot 0 = 0xABCD -> 0x0 (change MUST be at block_access_index=2)

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
def test_bal_cross_tx_storage_revert_to_zero(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Ensure BAL captures storage changes when tx1 writes a non-zero value
    and tx2 reverts it back to zero. This is a regression test for the
    blobhash scenario where slot changes were being incorrectly filtered
    as net-zero across transaction boundaries.

    Tx1: slot 0 = 0x0 -> 0xABCD (change at block_access_index=1)
    Tx2: slot 0 = 0xABCD -> 0x0 (change MUST be at block_access_index=2)
    """
    alice = pre.fund_eoa()

    # Contract that writes to slot 0 based on calldata
    contract = pre.deploy_contract(code=Op.SSTORE(0, Op.CALLDATALOAD(0)))

    # Tx1: Write slot 0 = 0xABCD
    tx1 = Transaction(
        sender=alice,
        to=contract,
        data=Hash(0xABCD),
        gas_limit=100_000,
    )

    # Tx2: Write slot 0 = 0x0 (revert to zero)
    tx2 = Transaction(
        sender=alice,
        to=contract,
        data=Hash(0x0),
        gas_limit=100_000,
    )

    account_expectations = {
        alice: BalAccountExpectation(
            nonce_changes=[
                BalNonceChange(block_access_index=1, post_nonce=1),
                BalNonceChange(block_access_index=2, post_nonce=2),
            ],
        ),
        contract: BalAccountExpectation(
            storage_changes=[
                BalStorageSlot(
                    slot=0,
                    slot_changes=[
                        BalStorageChange(
                            block_access_index=1, post_value=0xABCD
                        ),
                        # CRITICAL: tx2's write to 0x0 MUST appear
                        # even though it returns slot to original value
                        BalStorageChange(block_access_index=2, post_value=0x0),
                    ],
                ),
            ],
        ),
    }

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx1, tx2],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post={
            alice: Account(nonce=2),
            contract: Account(storage={0: 0x0}),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.