Skip to content

test_sstore_combinations_initial()

Documentation for tests/istanbul/eip2200_net_gas_metering/test_sstore_combinations.py::test_sstore_combinations_initial@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/istanbul/eip2200_net_gas_metering/test_sstore_combinations.py::test_sstore_combinations_initial --fork Amsterdam

Test SSTORE with four interleaved calls.

Exercises every combination of call types across four call slots, varying the update-contract's initial storage state (0, 1, or 2). Valid from Byzantium (REVERT and STATICCALL availability) so the pre-EIP-2200 storage gas rules are covered as a baseline. Consolidated replacement for the twelve legacy sstore_combinations_initial*_ParisFiller.json fillers from state_tests/stTimeConsuming/.

Source code in tests/istanbul/eip2200_net_gas_metering/test_sstore_combinations.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@pytest.mark.parametrize("initial", range(3))
@pytest.mark.parametrize("call_4, call_4_target", MIDDLE_ACTIONS)
@pytest.mark.parametrize("call_3", [Op.CALL, Op.DELEGATECALL])
@pytest.mark.parametrize("call_2, call_2_target", MIDDLE_ACTIONS)
@pytest.mark.parametrize("call_1", [Op.CALL, Op.DELEGATECALL])
def test_sstore_combinations_initial(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    initial: int,
    call_1: Op,
    call_2: Op,
    call_2_target: MidContractActions,
    call_3: Op,
    call_4: Op,
    call_4_target: MidContractActions,
) -> None:
    """
    Test SSTORE with four interleaved calls.

    Exercises every combination of call types across four call slots,
    varying the update-contract's initial storage state (0, 1, or 2).
    Valid from Byzantium (REVERT and STATICCALL availability) so the
    pre-EIP-2200 storage gas rules are covered as a baseline.
    Consolidated replacement for the twelve legacy
    ``sstore_combinations_initial*_ParisFiller.json`` fillers from
    ``state_tests/stTimeConsuming/``.
    """
    sender = pre.fund_eoa()

    def deploy_side(kind: MidContractActions) -> Address:
        if kind == MidContractActions.NOOP:
            return pre.deploy_contract(Bytecode())
        if kind == MidContractActions.SSTORE_TOGGLE:
            return pre.deploy_contract(code=SSTORE_TOGGLE_CODE)
        return pre.deploy_contract(
            code=Op.REVERT(offset=0x0, size=0x20) + Op.STOP,
        )

    side = {
        kind: deploy_side(kind)
        for kind in MidContractActions
        if kind
        in {call_2_target, call_4_target, MidContractActions.SSTORE_TOGGLE}
    }

    update_contract = pre.deploy_contract(
        code=UPDATE_CONTRACT_CODE,
        storage={0: initial, 1: initial, 2: initial} if initial > 0 else {},
    )
    sstore_toggle = side[MidContractActions.SSTORE_TOGGLE]

    call_gas = SSTORE_TOGGLE_CODE.gas_cost(fork)

    initcode = (
        Op.MSTORE(offset=0x64, value=0x0)
        + Op.POP(
            call_1(
                gas=call_gas,
                address=update_contract,
                args_size=0x20,
            )
        )
        + Op.POP(call_2(gas=call_gas, address=side[call_2_target]))
        + Op.POP(
            call_3(
                gas=call_gas,
                address=update_contract,
                args_size=0x20,
            )
        )
        + Op.POP(call_4(gas=call_gas, address=side[call_4_target]))
        + Op.CALL(gas=call_gas, address=sstore_toggle)
        + Op.STOP
    )

    tx = Transaction(
        sender=sender,
        to=None,
        data=initcode,
        value=1,
        protected=fork.supports_protected_txs(),
    )

    post = {
        sstore_toggle: Account(storage={1: 1}),
        compute_create_address(address=sender, nonce=0): Account(nonce=1),
    }

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 768 parametrized test cases across 12 forks.