@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(10, 5, id="multi_sstore_many_txs"),
],
)
@pytest.mark.valid_from("EIP8037")
def test_block_2d_gas_boundary_exact_fit(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
fork: Fork,
num_txs: int,
num_sstores: int,
) -> None:
"""
Verify a block is valid when state gas dominates execution gas.
Clients that sum execution + state will reject this valid block.
"""
tx_execution, tx_state = sstore_tx_gas(fork, num_sstores)
# No reservoir below the cap: a tx pays both dimensions out of its
# own limit, and this is exactly what it spends.
tx_limit = tx_execution + tx_state
block_execution, block_state = tx_execution * num_txs, tx_state * num_txs
total_cost = block_execution + block_state
header_gas_used = max(block_execution, block_state)
# The largest limit that still traps a client billing the header as
# sum(execution, state) instead of max(execution, state): such a
# client rejects the block for outgrowing its own gas limit, and
# misses the header either way.
block_gas_limit = total_cost - 1
assert header_gas_used <= block_gas_limit, "the block must be valid"
env = Environment(gas_limit=block_gas_limit)
txs, post = sstore_txs(
pre,
fork,
num_txs,
num_sstores=num_sstores,
tx_gas_limit=tx_limit,
)
blockchain_test(
genesis_environment=env,
pre=pre,
blocks=[
Block(
txs=txs,
gas_limit=block_gas_limit,
header_verify=Header(gas_used=header_gas_used),
)
],
post=post,
)