Skip to content

test_later_set_spills_after_repayment()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_later_set_spills_after_repayment@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_later_set_spills_after_repayment --fork Amsterdam

Test a later creation spills again once the credit is repaid.

After the cross-frame clear, the merge repays the credit into gas_left, so a fresh set finds the reservoir empty and spills: gas_left drops by the execution premium plus the slot's state cost across the set window. What the sender pays for it is checked in test_cross_frame_credit_funds_state_at_full_price.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
@pytest.mark.valid_from("EIP8037")
def test_later_set_spills_after_repayment(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test a later creation spills again once the credit is repaid.

    After the cross-frame clear, the merge repays the credit into
    `gas_left`, so a fresh set finds the reservoir empty and spills:
    `gas_left` drops by the execution premium plus the slot's state
    cost across the set window. What the sender pays for it is checked
    in `test_cross_frame_credit_funds_state_at_full_price`.
    """
    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)

    window_1 = FRESH_SET(SLOT_Y, 1)
    window_2 = Op.SSTORE.with_metadata(
        key_warm=True,
        original_value=0,
        current_value=1,
        new_value=1,
    )(SLOT_Y, 1)
    # The windows are byte-identical, so the excess is the fresh set's
    # execution premium plus whatever its state charge takes from
    # `gas_left`. The merge drained the credit into `gas_left`, so the
    # set spills and the excess is the premium plus the state cost.
    execution_premium = window_1.execution_cost(
        fork
    ) - window_2.execution_cost(fork)

    code = (
        Op.MSTORE(64, 0, new_memory_size=96, old_memory_size=0)
        + FRESH_SET(SLOT_X, 1)
        + Op.POP(
            Op.DELEGATECALL(
                gas=child_budget, address=clearer, address_warm=False
            )
        )
        + Op.MSTORE(0, Op.GAS)
        + window_1
        + Op.MSTORE(32, Op.GAS)
        + window_2
        + Op.MSTORE(64, Op.GAS)
        + window_cost_excess()
    )
    contract = pre.deploy_contract(code=code)

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.