Skip to content

test_sstore_zero_to_nonzero()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_zero_to_nonzero@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_zero_to_nonzero --fork Bogota

Test SSTORE zero-to-nonzero charges state gas.

Writing a nonzero value to a previously-zero slot charges STATE_BYTES_PER_STORAGE_SET * cost_per_state_byte of state gas in addition to execution gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.valid_from("EIP8037")
def test_sstore_zero_to_nonzero(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test SSTORE zero-to-nonzero charges state gas.

    Writing a nonzero value to a previously-zero slot charges
    STATE_BYTES_PER_STORAGE_SET * cost_per_state_byte of state gas
    in addition to execution gas.
    """
    storage = Storage()
    code = Op.SSTORE(storage.store_next(1), 1)
    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=0,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=tx_execution + state_gas
        ),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.