Skip to content

test_block_gas_used_state_dominates()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_gas_used_state_dominates@8acae1b0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_gas_used_state_dominates --fork Amsterdam

Verify block.gas_used = block_state_gas when state > execution.

Each tx performs zero-to-nonzero SSTOREs. Since state gas per SSTORE exceeds execution gas, block_state_gas exceeds block_execution_gas and becomes the header gas_used.

The spillover variant provides reservoir for only one SSTORE per tx; the remaining state gas spills into gas_left. Block-level accounting must still separate the two dimensions.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@pytest.mark.parametrize(
    "num_txs,num_sstores",
    [
        pytest.param(5, 1, id="single_sstore"),
        pytest.param(20, 1, id="single_sstore_many_txs"),
        pytest.param(2, 3, id="multi_sstore_spillover"),
        pytest.param(10, 5, id="multi_sstore_many_txs"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_block_gas_used_state_dominates(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    num_txs: int,
    num_sstores: int,
) -> None:
    """
    Verify block.gas_used = block_state_gas when state > execution.

    Each tx performs zero-to-nonzero SSTOREs. Since state gas per
    SSTORE exceeds execution gas, block_state_gas exceeds
    block_execution_gas and becomes the header gas_used.

    The spillover variant provides reservoir for only one SSTORE
    per tx; the remaining state gas spills into gas_left.
    Block-level accounting must still separate the two dimensions.
    """
    tx_execution, tx_state = sstore_tx_gas(fork, num_sstores)
    block_execution = num_txs * tx_execution
    block_state = num_txs * tx_state
    assert block_state > block_execution

    txs, post = sstore_txs(
        pre,
        fork,
        num_txs,
        num_sstores=num_sstores,
    )
    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=txs,
                header_verify=Header(gas_used=block_state),
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.