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@622620d8.

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 execution work, but is one gas short of the MCOPY execution 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
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
@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
    execution work, but is one gas short of the MCOPY execution 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 execution-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.