Skip to content

test_charge_spill_boundary()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_charge_spill_boundary@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_charge_spill_boundary --fork Amsterdam

Test the SSTORE-set state charge at its exact-fit spill boundary.

With an empty reservoir (in-cap tx) the full state charge spills into gas_left. Sized to exactly the charge the SSTORE succeeds and the block bills it as state gas; one gas short, neither pool can cover the charge and the frame runs out of gas with the slot unset.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@pytest.mark.parametrize(
    "gas_delta",
    [pytest.param(0, id="exact_fit"), pytest.param(-1, id="one_short")],
)
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@pytest.mark.valid_from("EIP8037")
def test_charge_spill_boundary(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_delta: int,
) -> None:
    """
    Test the SSTORE-set state charge at its exact-fit spill boundary.

    With an empty reservoir (in-cap tx) the full state charge spills
    into gas_left. Sized to exactly the charge the SSTORE succeeds and
    the block bills it as state gas; one gas short, neither pool can
    cover the charge and the frame runs out of gas with the slot unset.
    """
    code = Op.SSTORE(0, 1)
    contract = pre.deploy_contract(code=code)

    intrinsic = fork.transaction_intrinsic_cost_calculator()()
    regular = code.regular_cost(fork)
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    gas_limit = intrinsic + regular + sstore_state_gas + gas_delta

    tx = Transaction(
        to=contract,
        gas_limit=gas_limit,
        sender=pre.fund_eoa(),
    )

    header = Header(
        gas_used=max(intrinsic + regular, sstore_state_gas)
        if gas_delta == 0
        else gas_limit
    )
    state_test(
        pre=pre,
        post={contract: Account(storage={0: 1 if gas_delta == 0 else 0})},
        tx=tx,
        blockchain_test_header_verify=header,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.