Verify the per-tx state check at the strict-greater-than boundary.
tx1 consumes tx1_state via cold SSTOREs. tx2 is sized so that
its worst-case state contribution tx.gas equals state_available
(delta=0, accepted because the check is strict >) or exceeds it
by 1 (delta=1, rejected with GAS_ALLOWANCE_EXCEEDED).
The regular check is asserted to pass so rejection on delta=1 is
pinned to the state dimension.
Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333 | @pytest.mark.parametrize(
"delta",
[
pytest.param(0, id="exact_fit"),
pytest.param(1, id="exceeded", marks=pytest.mark.exception_test),
],
)
@pytest.mark.valid_from("EIP8037")
def test_block_state_gas_limit_boundary(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
fork: Fork,
delta: int,
) -> None:
"""
Verify the per-tx state check at the strict-greater-than boundary.
tx1 consumes `tx1_state` via cold SSTOREs. tx2 is sized so that
its worst-case state contribution `tx.gas` equals `state_available`
(delta=0, accepted because the check is strict `>`) or exceeds it
by 1 (delta=1, rejected with `GAS_ALLOWANCE_EXCEEDED`).
The regular check is asserted to pass so rejection on delta=1 is
pinned to the state dimension.
"""
gas_limit_cap = fork.transaction_gas_limit_cap()
assert gas_limit_cap is not None
block_gas_limit = 100_000_000
intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
num_sstores = 50
tx1_code = Bytecode()
for i in range(num_sstores):
tx1_code = tx1_code + Op.SSTORE(i, 1)
tx1_contract = pre.deploy_contract(code=tx1_code)
tx1_state = tx1_code.state_cost(fork)
tx1_regular = intrinsic_cost() + tx1_code.gas_cost(fork) - tx1_state
tx1_gas = gas_limit_cap + tx1_state
# tx2: worst-case state contribution = tx.gas (strict EIP rule).
# Plain call, so intrinsic_state is zero.
state_available = block_gas_limit - tx1_state
tx2_gas = state_available + delta
# Pin the rejection (when delta > 0) to the state check: the
# regular check must not fire.
regular_available = block_gas_limit - tx1_regular
assert min(gas_limit_cap, tx2_gas) < regular_available, (
"tx2 would fail the regular check instead of the state check"
)
tx2_error = (
TransactionException.GAS_ALLOWANCE_EXCEEDED if delta > 0 else None
)
block_exception = tx2_error
tx1 = Transaction(
to=tx1_contract,
gas_limit=tx1_gas,
sender=pre.fund_eoa(),
)
tx2 = Transaction(
to=pre.deploy_contract(code=Op.STOP),
gas_limit=tx2_gas,
sender=pre.fund_eoa(),
error=tx2_error,
)
blockchain_test(
genesis_environment=Environment(gas_limit=block_gas_limit),
pre=pre,
blocks=[
Block(
txs=[tx1, tx2],
gas_limit=block_gas_limit,
exception=block_exception,
)
],
post={},
)
|