Skip to content

test_bal_sstore_static_context()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_sstore_static_context@2119b382.

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_sstore_static_context --fork Amsterdam

SSTORE in static context must not leak storage reads into BAL.

Contract A STATICCALLs Contract B which attempts SSTORE. Contract B IS in BAL (accessed via STATICCALL) but MUST NOT have storage_reads — the static check must fire before any implicit SLOAD.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
@pytest.mark.parametrize(
    "original_value", [0, 0x42], ids=["zero_original", "nonzero_original"]
)
def test_bal_sstore_static_context(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    original_value: int,
) -> None:
    """
    SSTORE in static context must not leak storage reads into BAL.

    Contract A STATICCALLs Contract B which attempts SSTORE. Contract B
    IS in BAL (accessed via STATICCALL) but MUST NOT have storage_reads
    — the static check must fire before any implicit SLOAD.
    """
    alice = pre.fund_eoa()

    contract_b = pre.deploy_contract(
        code=Op.SSTORE(0, 5),
        storage={0: original_value} if original_value else {},
    )

    contract_a = pre.deploy_contract(
        code=Op.SSTORE(0, Op.STATICCALL(gas=1_000_000, address=contract_b))
        + Op.SSTORE(1, 1),  # proves execution continued
        storage={0: 0xDEAD},  # non-zero so STATICCALL result (0) is detectable
    )

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

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                )
                            ],
                        ),
                        contract_a: BalAccountExpectation(
                            storage_changes=[
                                BalStorageSlot(
                                    slot=0x00,
                                    slot_changes=[
                                        # STATICCALL returns 0 (inner SSTORE
                                        # failed in static context)
                                        BalStorageChange(
                                            block_access_index=1, post_value=0
                                        ),
                                    ],
                                ),
                                BalStorageSlot(
                                    slot=0x01,
                                    slot_changes=[
                                        BalStorageChange(
                                            block_access_index=1, post_value=1
                                        ),
                                    ],
                                ),
                            ],
                        ),
                        # Contract B is in BAL (accessed via STATICCALL)
                        # but MUST NOT have any state touches
                        contract_b: BalAccountExpectation.empty(),
                    }
                ),
            )
        ],
        post={
            contract_a: Account(storage={0: 0, 1: 1}),
            contract_b: Account(
                storage={0: original_value} if original_value else {}
            ),
        },
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.