Skip to content

Commit 4b22798

Browse files
committed
feat(spec-specs): 7) add state gas dimension to per-tx inclusion check
1 parent 3a980ac commit 4b22798

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

  • src/ethereum/forks/amsterdam

src/ethereum/forks/amsterdam/fork.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ def check_transaction(
488488
block_output: vm.BlockOutput,
489489
tx: Transaction,
490490
tx_state: TransactionState,
491+
intrinsic_regular_gas: Uint,
492+
intrinsic_state_gas: Uint,
491493
) -> Tuple[Address, Uint, Tuple[VersionedHash, ...], U64]:
492494
"""
493495
Check if the transaction is includable in the block.
@@ -502,6 +504,10 @@ def check_transaction(
502504
The transaction.
503505
tx_state :
504506
The transaction state tracker.
507+
intrinsic_regular_gas :
508+
The transaction's intrinsic regular gas.
509+
intrinsic_state_gas :
510+
The transaction's intrinsic state gas.
505511
506512
Returns
507513
-------
@@ -549,16 +555,24 @@ def check_transaction(
549555
is empty.
550556
551557
"""
552-
# Regular gas is capped at TX_MAX_GAS_LIMIT per EIP-7825.
553-
# State gas is not checked per-tx; block-end validation enforces
554-
# max(block_regular_gas_used, block_state_gas_used) <= gas_limit.
558+
# Both regular and state gas are validated before execution.
555559
regular_gas_available = (
556560
block_env.block_gas_limit - block_output.block_gas_used
557561
)
562+
state_gas_available = (
563+
block_env.block_gas_limit - block_output.block_state_gas_used
564+
)
558565
blob_gas_available = MAX_BLOB_GAS_PER_BLOCK - block_output.blob_gas_used
559566

560-
if min(TX_MAX_GAS_LIMIT, tx.gas) > regular_gas_available:
561-
raise GasUsedExceedsLimitError("regular gas used exceeds limit")
567+
regular_gas_contribution = min(
568+
TX_MAX_GAS_LIMIT, tx.gas - intrinsic_state_gas
569+
)
570+
if regular_gas_contribution > regular_gas_available:
571+
raise GasUsedExceedsLimitError("regular gas exceeds limit")
572+
573+
state_gas_contribution = tx.gas - intrinsic_regular_gas
574+
if state_gas_contribution > state_gas_available:
575+
raise GasUsedExceedsLimitError("state gas exceeds limit")
562576

563577
tx_blob_gas_used = calculate_total_blob_gas(tx)
564578
if tx_blob_gas_used > blob_gas_available:
@@ -991,6 +1005,8 @@ def process_transaction(
9911005
block_output=block_output,
9921006
tx=tx,
9931007
tx_state=tx_state,
1008+
intrinsic_regular_gas=intrinsic.regular,
1009+
intrinsic_state_gas=intrinsic.state,
9941010
)
9951011

9961012
sender_account = get_account(tx_state, sender)

0 commit comments

Comments
 (0)