Skip to content

test_sequential_calls_reservoir_restored_between_reverts()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_sequential_calls_reservoir_restored_between_reverts@c74f1a67.

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

Test reservoir restored across sequential child reverts.

Parent calls child1, which uses the reservoir for an SSTORE and reverts, restoring the reservoir. It then calls child2, which reuses the restored reservoir and reverts, restoring it again. The parent then performs its own SSTORE from the restored reservoir.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
@pytest.mark.valid_from("EIP8037")
def test_sequential_calls_reservoir_restored_between_reverts(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test reservoir restored across sequential child reverts.

    Parent calls child1, which uses the reservoir for an SSTORE and
    reverts, restoring the reservoir. It then calls child2, which
    reuses the restored reservoir and reverts, restoring it again.
    The parent then performs its own SSTORE from the restored
    reservoir.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

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

    parent_storage = Storage()
    parent = pre.deploy_contract(
        code=(
            # First child: uses reservoir, reverts — reservoir restored
            Op.POP(Op.CALL(gas=500_000, address=child))
            # Second child: uses restored reservoir, reverts — restored again
            + Op.POP(Op.CALL(gas=500_000, address=child))
            # Parent SSTORE succeeds with restored reservoir
            + Op.SSTORE(parent_storage.store_next(1), 1)
        ),
    )

    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.