Skip to content

test_cross_frame_refund_repays_spill_at_a_call()

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

Test a call merging a refund repays the spill.

A holder contract owns the cleared slot, so every dispatch reaches it the same way. The clearing window costs a full state charge less than the no-op window: the refund repays the spill at the merge.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
@pytest.mark.with_all_call_opcodes(
    # A static child cannot write, so it can never refund.
    selector=lambda call_opcode: call_opcode != Op.STATICCALL
)
@pytest.mark.valid_from("EIP8037")
def test_cross_frame_refund_repays_spill_at_a_call(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    call_opcode: Opcode,
) -> None:
    """
    Test a call merging a refund repays the spill.

    A holder contract owns the cleared slot, so every dispatch reaches
    it the same way. The clearing window costs a full state charge less
    than the no-op window: the refund repays the spill at the merge.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    holder = deploy_slot_holder(pre)
    set_slot = Op.POP(Op.CALL(address=holder, args_size=1))
    clearer = pre.deploy_contract(code=Op.CALL(address=holder))
    window = Op.POP(call_opcode(address=clearer))
    contract = pre.deploy_contract(
        code=clearing_probe_code(set_slot, [window] * 3)
    )

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

    post = {
        holder: Account(storage={SLOT_X: 0}),
        contract: Account(
            storage={
                SLOT_MARKER: 1,
                SLOT_INCREASED: 1,
                SLOT_RESULT: -sstore_state_gas,
            }
        ),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.