Skip to content

test_cross_frame_credit_funds_state_at_full_price()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_cross_frame_credit_funds_state_at_full_price@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_cross_frame_credit_funds_state_at_full_price --fork Amsterdam

Test the sender pays full price for state after a cross-frame refund.

A fresh set spills, a delegated child clears it, and the merge repays the refund into gas_left. A second fresh set then survives and is billed at the full state price, so routing a refund through another frame buys no discount on state that persists. What the later set costs gas_left is measured in test_later_set_spills_after_repayment.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
@pytest.mark.valid_from("EIP8037")
def test_cross_frame_credit_funds_state_at_full_price(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test the sender pays full price for state after a cross-frame refund.

    A fresh set spills, a delegated child clears it, and the merge
    repays the refund into `gas_left`. A second fresh set then survives
    and is billed at the full state price, so routing a refund through
    another frame buys no discount on state that persists. What the
    later set costs `gas_left` is measured in
    `test_later_set_spills_after_repayment`.
    """
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()()
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    clearer_code = WARM_CLEAR(SLOT_X, 0)
    clearer = pre.deploy_contract(code=clearer_code)
    child_budget = budget_above_sstore_stipend(fork, clearer_code)

    code = (
        FRESH_SET(SLOT_X, 1)
        + Op.POP(
            Op.DELEGATECALL(
                gas=child_budget, address=clearer, address_warm=False
            )
        )
        + FRESH_SET(SLOT_Y, 1)
    )
    contract = pre.deploy_contract(code=code)

    # Slot Y survives, fully priced. The cleared slot cancels out of
    # the settlement sum.
    before_refund = (
        intrinsic_cost
        + code.execution_cost(fork)
        + clearer_code.execution_cost(fork)
        + sstore_state_gas
    )
    restore_refund = clearer_code.refund(fork) - sstore_state_gas
    expected_gas_used = before_refund - min(
        before_refund // fork.max_refund_quotient(), restore_refund
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_gas_used
        ),
    )

    post = {contract: Account(storage={SLOT_X: 0, SLOT_Y: 1})}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.