Skip to content

test_delegatecall_reservoir_passing()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_delegatecall_reservoir_passing@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_delegatecall_reservoir_passing --fork Amsterdam

Test DELEGATECALL passes full reservoir to child.

DELEGATECALL runs child code in the caller's storage context. The child's SSTORE writes to the parent's storage using state gas from the reservoir, emptying it. A probe handed only its SSTORE's execution cost then fails, proving the draw was real.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
@pytest.mark.valid_from("EIP8037")
def test_delegatecall_reservoir_passing(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test DELEGATECALL passes full reservoir to child.

    DELEGATECALL runs child code in the caller's storage context.
    The child's SSTORE writes to the parent's storage using state gas
    from the reservoir, emptying it. A probe handed only its SSTORE's
    execution cost then fails, proving the draw was real.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    parent_storage = Storage()
    # Library code runs in parent's context — slot is reserved on
    # parent_storage so the post check uses the same source of truth.
    library_code = Op.SSTORE(parent_storage.store_next(1), 1)
    library = pre.deploy_contract(code=library_code)

    probe_code = Op.SSTORE(0, 1)
    probe = pre.deploy_contract(code=probe_code)
    probe_gas = probe_code.execution_cost(fork)

    probe_slot = parent_storage.store_next(0, "probe_fails")
    parent_code = Op.POP(
        Op.DELEGATECALL(gas=library_code.execution_cost(fork), address=library)
    ) + Op.SSTORE(
        probe_slot,
        Op.CALL(gas=probe_gas, address=probe),
        # gas accounting
        original_value=1,
        current_value=1,
        new_value=0,
        key_warm=False,
    )
    parent = pre.deploy_contract(code=parent_code, storage={probe_slot: 1})

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

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.