Skip to content

test_dispatched_frame_state_gas_still_refills_on_revert()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_dispatched_frame_state_gas_still_refills_on_revert@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py::test_dispatched_frame_state_gas_still_refills_on_revert --fork Amsterdam

State gas charged inside the dispatched call is still refilled when that call reverts, in the same transaction whose authorization state gas must stay consumed.

The authorization sets a delegation on an existing EOA (AUTH_BASE, persists across the revert). The recipient then SSTOREs a fresh slot -- charging STORAGE_SET state gas -- and reverts, rolling the slot back, so that state gas is refilled.

This brackets the rollback boundary from both sides: the current over-refill (returning the AUTH_BASE too) underpays by 35,190, while an over-correction that stops refilling frame state gas altogether would overcharge by the 97,920 STORAGE_SET.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_oog.py
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
def test_dispatched_frame_state_gas_still_refills_on_revert(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    State gas charged *inside* the dispatched call is still refilled
    when that call reverts, in the same transaction whose authorization
    state gas must stay consumed.

    The authorization sets a delegation on an existing EOA
    (``AUTH_BASE``, persists across the revert). The recipient then
    ``SSTORE``s a fresh slot -- charging ``STORAGE_SET`` state gas --
    and reverts, rolling the slot back, so that state gas is refilled.

    This brackets the rollback boundary from both sides: the current
    over-refill (returning the ``AUTH_BASE`` too) underpays by 35,190,
    while an over-correction that stops refilling frame state gas
    altogether would overcharge by the 97,920 ``STORAGE_SET``.
    """
    sender = pre.fund_eoa()

    sstore_revert_code = Op.SSTORE(
        0, 1, original_value=0, new_value=1
    ) + Op.REVERT(0, 0)
    recipient = pre.deploy_contract(code=sstore_revert_code)

    auth = build_authorization(pre, AuthorizationAction.SETS_NEW_DELEGATION)
    authorization_list = [auth.authorization]

    intrinsic_execution = _intrinsic_execution(
        fork, authorization_list, recipient_type=RecipientType.CONTRACT
    )
    auth_charges = _auth_top_frame_charges(fork, authorization_list)
    evm_execution = sstore_revert_code.execution_cost(fork)
    exec_state = sstore_revert_code.state_cost(fork)
    assert exec_state > 0, (
        "the dispatched SSTORE must carry a state-gas charge"
    )

    # The SSTORE's state gas is charged and then refilled by the
    # revert (the slot rolls back), so the sender pays only the
    # authorization charges and the execution gas.
    gas_used = intrinsic_execution + auth_charges + evm_execution

    tx = Transaction(
        sender=sender,
        to=recipient,
        value=0,
        authorization_list=authorization_list,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=gas_used,
        ),
    )

    post = {
        auth.authority: auth.applied_account,
        recipient: Account(code=sstore_revert_code, balance=0, storage={0: 0}),
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.