Skip to content

test_selfdestruct_oog_reservoir_inflation_detection()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py::test_selfdestruct_oog_reservoir_inflation_detection@5c024cbb.

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

Detect SELFDESTRUCT state gas ordering via reservoir inflation.

A child with non-zero balance does SELFDESTRUCT(dead_beneficiary) with gas tuned so the regular gas charge OOGs by 1. If state gas is incorrectly charged first, the parent's reservoir is inflated.

Single-SSTORE probe detects the inflation.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py
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
253
254
255
256
257
258
@pytest.mark.valid_from("EIP8037")
def test_selfdestruct_oog_reservoir_inflation_detection(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Detect SELFDESTRUCT state gas ordering via reservoir inflation.

    A child with non-zero balance does SELFDESTRUCT(dead_beneficiary)
    with gas tuned so the regular gas charge OOGs by 1. If state gas
    is incorrectly charged first, the parent's reservoir is inflated.

    Single-SSTORE probe detects the inflation.
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    dead_beneficiary = 0xBEEF
    child_code = Op.SELFDESTRUCT(dead_beneficiary)
    pushes_gas = gas_costs.VERY_LOW
    selfdestruct_regular_gas = (
        gas_costs.OPCODE_SELFDESTRUCT_BASE + gas_costs.COLD_ACCOUNT_ACCESS
    )
    child_gas = (
        pushes_gas + selfdestruct_regular_gas + new_account_state_gas - 1
    )
    child = pre.deploy_contract(child_code, balance=1)

    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.