Skip to content

test_delegation_pointer_state_gas_on_frame_failure()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_delegation_pointer_state_gas_on_frame_failure@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_delegation_pointer_state_gas_on_frame_failure --fork Amsterdam

Test a delegated frame's state charge is undone when it fails.

The storage the charge pays for belongs to the authority, not the delegated code's own account, so the rollback has to reach the authority's slot. Either failure leaves the state dimension empty.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py
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
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
@pytest.mark.parametrize(
    "failure_mode",
    [
        pytest.param("revert", id="revert"),
        pytest.param("halt", id="halt"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_delegation_pointer_state_gas_on_frame_failure(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    failure_mode: str,
) -> None:
    """
    Test a delegated frame's state charge is undone when it fails.

    The storage the charge pays for belongs to the authority, not the
    delegated code's own account, so the rollback has to reach the
    authority's slot. Either failure leaves the state dimension empty.
    """
    ending = Op.REVERT(0, 0) if failure_mode == "revert" else Op.INVALID
    code = Op.SSTORE(0, 1) + ending
    contract = pre.deploy_contract(code=code)

    delegator = pre.fund_eoa(delegation=contract)

    intrinsic_execution = fork.transaction_intrinsic_cost_calculator()(
        recipient_type=RecipientType.DELEGATION_7702,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_execution = fork.transaction_top_frame_execution_gas(
        recipient_type=RecipientType.DELEGATION_7702,
        delegation_warm=False,
    )
    gas_limit = 200_000
    # The rolled-back set leaves the state dimension empty, so the
    # header is the execution total: a halt burns the whole budget, a
    # revert returns everything the frame did not spend.
    if failure_mode == "halt":
        expected_gas_used = gas_limit
    else:
        expected_gas_used = (
            intrinsic_execution
            + top_frame_execution
            + code.execution_cost(fork)
        )

    tx = Transaction(
        to=delegator,
        gas_limit=gas_limit,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_gas_used
        ),
    )

    state_test(
        pre=pre,
        post={delegator: Account(storage={0: 0})},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.