Skip to content

test_create_oog_reservoir_inflation_detection()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py::test_create_oog_reservoir_inflation_detection@2119b382.

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

Detect CREATE/CREATE2 state-gas ordering via parent-reservoir inflation. Two OOG boundaries are exercised: oog_on_create_base (empty initcode) and oog_on_init_code_word_cost (32-byte initcode).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
@pytest.mark.parametrize(
    "oog_step",
    [
        pytest.param("create_base", id="oog_on_create_base"),
        pytest.param("init_code_word_cost", id="oog_on_init_code_word_cost"),
    ],
)
@pytest.mark.with_all_create_opcodes()
@pytest.mark.valid_from("EIP8037")
def test_create_oog_reservoir_inflation_detection(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
    oog_step: str,
) -> None:
    """
    Detect CREATE/CREATE2 state-gas ordering via parent-reservoir
    inflation. Two OOG boundaries are exercised: `oog_on_create_base`
    (empty initcode) and `oog_on_init_code_word_cost` (32-byte
    initcode).
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    if oog_step == "create_base":
        initcode_size = 0
        setup_gas = 0
        init_code_word_cost = 0
    else:
        initcode_size = WORD_SIZE
        setup_gas = (
            Op.MSTORE.popped_stack_items * gas_costs.VERY_LOW
            + gas_costs.OPCODE_MSTORE_BASE
            + gas_costs.MEMORY_PER_WORD
        )
        init_code_word_cost = gas_costs.CODE_INIT_PER_WORD

    if create_opcode == Op.CREATE:
        create_op = create_opcode(value=0, offset=0, size=initcode_size)
    else:
        create_op = create_opcode(
            value=0, offset=0, size=initcode_size, salt=0
        )
    pushes_gas = create_opcode.popped_stack_items * gas_costs.VERY_LOW

    if oog_step == "create_base":
        child_code = create_op
    else:
        child_code = Op.MSTORE(0, 0) + create_op

    create_regular_gas = gas_costs.OPCODE_CREATE_BASE + init_code_word_cost
    child_gas = (
        setup_gas + pushes_gas + create_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 4 parametrized test cases across 1 fork.