Skip to content

test_sstore_state_gas_drawn_from_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_state_gas_drawn_from_reservoir@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_state_gas_drawn_from_reservoir --fork Amsterdam

Test SSTORE state gas drawn from reservoir before gas_left.

Provide enough gas above TX_MAX_GAS_LIMIT to fully cover the SSTORE state gas from the reservoir, leaving gas_left untouched by the state gas charge.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
@pytest.mark.valid_from("EIP8037")
def test_sstore_state_gas_drawn_from_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test SSTORE state gas drawn from reservoir before gas_left.

    Provide enough gas above TX_MAX_GAS_LIMIT to fully cover the
    SSTORE state gas from the reservoir, leaving gas_left untouched
    by the state gas charge.
    """
    measured = Op.SSTORE(1, 1)
    measured_execution = measured.execution_cost(fork)
    sstore_state_gas = measured.state_cost(fork)

    # The recording SSTORE is itself a zero-to-nonzero set; its state
    # gas spills into gas_left because the measured set drained the
    # reservoir first.
    code = CodeGasMeasure(code=measured, sstore_key=0)
    state_gas = code.state_cost(fork)
    tx_execution = (
        fork.transaction_intrinsic_cost_calculator()()
        + code.execution_cost(fork)
    )
    assert state_gas > tx_execution, "state dimension must set the header"

    contract = pre.deploy_contract(code=code)

    tx = Transaction(
        to=contract,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=tx_execution + state_gas
        ),
    )

    state_test(
        pre=pre,
        post={contract: Account(storage={0: measured_execution, 1: 1})},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=state_gas),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.