Skip to content

test_reservoir_returned_on_revert()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_reservoir_returned_on_revert@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_reservoir_returned_on_revert --fork Amsterdam

Test state gas reservoir is returned to parent on child revert.

The child draws the whole reservoir for an SSTORE then reverts, restoring it. Repeating that leaves the parent with only one SSTORE's execution cost, so its own SSTORE has nothing to spill from and lands only if the restores went back to the reservoir.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@pytest.mark.valid_from("EIP8037")
def test_reservoir_returned_on_revert(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test state gas reservoir is returned to parent on child revert.

    The child draws the whole reservoir for an SSTORE then reverts,
    restoring it. Repeating that leaves the parent with only one
    SSTORE's execution cost, so its own SSTORE has nothing to spill
    from and lands only if the restores went back to the reservoir.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    child_code = Op.SSTORE(0, 1) + Op.REVERT(0, 0)
    child = pre.deploy_contract(code=child_code)

    parent_storage = Storage()
    final_sstore = Op.SSTORE(parent_storage.store_next(1), 1)

    child_gas = child_code.execution_cost(fork)
    parent_code = (
        WhileGas(
            body=Op.POP(
                Op.CALL(
                    gas=child_gas,
                    address=child,
                    # gas accounting
                    address_warm=True,
                    inner_call_cost=child_gas,
                )
            ),
            fork=fork,
            extra_gas=final_sstore.execution_cost(fork),
        )
        + final_sstore
    )
    parent = pre.deploy_contract(code=parent_code)

    tx = Transaction(
        to=parent,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {parent: Account(storage=parent_storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.