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

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
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
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
@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,
        gas_limit=2_000_000,
    )

    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.