Skip to content

test_top_level_opcode_oog_before_frame_end_does_not_refund_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_top_level_opcode_oog_before_frame_end_does_not_refund_state_gas@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_top_level_opcode_oog_before_frame_end_does_not_refund_state_gas --fork Amsterdam

Verify an opcode OOG before frame-end settlement does not refund unsettled state gas.

The transaction has enough gas for the SSTORE and all preceding regular work, but is one gas short of the MCOPY regular cost. The frame halts before frame-end settlement runs, so the earlier SSTORE never contributes execution state gas to refund.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
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
@pytest.mark.valid_from("EIP8037")
def test_top_level_opcode_oog_before_frame_end_does_not_refund_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify an opcode OOG before frame-end settlement does not refund
    unsettled state gas.

    The transaction has enough gas for the SSTORE and all preceding
    regular work, but is one gas short of the MCOPY regular cost. The
    frame halts before frame-end settlement runs, so the earlier SSTORE
    never contributes execution state gas to refund.
    """
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()()
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    code = Op.SSTORE(0, 1) + Op.MCOPY(
        0x1000,
        0,
        1,
        old_memory_size=0,
        new_memory_size=0x1001,
        data_size=1,
    )
    contract = pre.deploy_contract(code=code)

    # One gas short of the regular-gas portion of successful execution.
    tx_gas = intrinsic_cost + code.gas_cost(fork) - sstore_state_gas - 1

    tx = Transaction(
        to=contract,
        gas_limit=tx_gas,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=tx_gas,
        ),
    )

    state_test(pre=pre, post={contract: Account(storage={})}, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.