Skip to content

test_call_oog_reservoir_inflation_detection()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py::test_call_oog_reservoir_inflation_detection@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py::test_call_oog_reservoir_inflation_detection --fork Amsterdam

Detect CALL state gas ordering via reservoir inflation.

A child does CALL(value=1) to a dead address with gas tuned so the regular gas charge OOGs by 1. If state gas (new account) is incorrectly charged first, the parent's reservoir is inflated.

A single-SSTORE probe detects the inflation: with correct reservoir (0) it OOGs; with inflated reservoir it succeeds.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@pytest.mark.valid_from("EIP8037")
def test_call_oog_reservoir_inflation_detection(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Detect CALL state gas ordering via reservoir inflation.

    A child does CALL(value=1) to a dead address with gas tuned so
    the regular gas charge OOGs by 1. If state gas (new account) is
    incorrectly charged first, the parent's reservoir is inflated.

    A single-SSTORE probe detects the inflation: with correct reservoir
    (0) it OOGs; with inflated reservoir it succeeds.
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    dead_address = 0xDEAD
    child_code = Op.CALL(
        gas=0,
        address=dead_address,
        value=1,
        args_offset=0,
        args_size=0,
        ret_offset=0,
        ret_size=0,
    )
    pushes_gas = 7 * gas_costs.VERY_LOW
    call_regular_gas = gas_costs.COLD_ACCOUNT_ACCESS + gas_costs.CALL_VALUE
    child_gas = pushes_gas + call_regular_gas + new_account_state_gas - 1
    child = pre.deploy_contract(child_code)

    probe = pre.deploy_contract(Op.SSTORE(0, 1))
    probe_gas = _single_sstore_probe_gas(fork)

    caller_storage = Storage()
    caller = pre.deploy_contract(
        Op.POP(Op.CALL(gas=child_gas, address=child))
        + Op.SSTORE(
            caller_storage.store_next(0, "probe_must_fail"),
            Op.CALL(gas=probe_gas, address=probe),
        )
    )

    sender = pre.fund_eoa()
    tx = Transaction(
        sender=sender,
        to=caller,
        state_gas_reservoir=0,
    )

    post = {caller: Account(storage=caller_storage)}
    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.