Skip to content

fix(evm): return BlockValidationError on block gas-pool overflow - #236

Open
panos-xyz wants to merge 1 commit into
mainfrom
fix/gas-pool-validation-error
Open

panos-xyz wants to merge 1 commit into
mainfrom
fix/gas-pool-validation-error

Conversation

@panos-xyz

@panos-xyz panos-xyz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes gas-pool overflow error classification in MorphBlockExecutor::execute_transaction_without_commit (crates/evm/src/block/mod.rs):

  • Replaces BlockExecutionError::msg(...) (which constructs BlockExecutionError::Internal(InternalBlockExecutionError::Other(...))) with BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas { transaction_gas_limit: recovered.tx().gas_limit(), block_available_gas }.into(), matching upstream alloy-evm's EthBlockExecutor.
  • Ensures downstream consumers treat block gas-pool overflows as recoverable block/transaction validation errors rather than fatal internal execution errors:
    • Engine/tree block validation classifies the block as invalid rather than surfacing an internal execution failure.
    • morph-payload-builder handles supplied transactions through its BlockExecutionError::Validation arm (InvalidSuppliedTransaction) and pool transactions by skipping/marking the transaction invalid rather than aborting block building with EvmExecutionError.
  • Audited all remaining BlockExecutionError::msg / BlockExecutionError::other occurrences across the repository (crates/evm/src/block/mod.rs:131, 134, 159, 202); all remaining ones are genuine internal invariants or database read failures.
  • Adds 3 unit tests in crates/evm/src/block/mod.rs asserting err.as_validation().is_some() and exact TransactionGasLimitMoreThanAvailableBlockGas fields for:
    1. Single transaction exceeding the block gas limit
    2. Second transaction exceeding remaining gas pool after an earlier regular transaction
    3. Second transaction exceeding remaining gas pool after an L1 message (verifying full gas_limit pool reservation)

Verification

  • cargo fmt --all -- --check: passed
  • cargo clippy -p morph-evm -p morph-payload-builder -p morph-node --all-targets -- -D warnings: passed (0 warnings)
  • cargo test -p morph-evm: 24 passed
  • cargo test -p morph-payload-builder: 39 passed
  • cargo test -p morph-node --features test-utils --test it -- block_building consensus engine invalid_payload_recovery: 46 passed

Summary by CodeRabbit

  • Bug Fixes
    • Transactions that exceed the block’s available gas now receive a specific validation error that includes the transaction’s gas limit and the gas remaining.
    • Gas availability is correctly accounted for after regular transactions and L1 messages, using an L1 message’s full gas limit when calculating what remains.

Replace BlockExecutionError::msg(...) with
BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas in
MorphBlockExecutor::execute_transaction_without_commit so a transaction
exceeding the remaining block gas pool is classified as a Validation error
(matching upstream EthBlockExecutor) rather than an Internal execution error.

This ensures:
- Engine/tree validation rejects malformed blocks cleanly as invalid rather
  than surfacing a fatal internal execution error.
- Payload builder supplied/pool transaction execution handles gas-pool
  overflow through its BlockExecutionError::Validation arms instead of
  aborting with a fatal EvmExecutionError.

Adds unit tests covering single-tx overflow, overflow after a regular tx,
and overflow after an L1 message reserving its full gas_limit.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The block executor now returns a structured validation error when a transaction’s gas limit exceeds the remaining block gas. Tests cover the initial gas pool and the pool remaining after regular and L1-message transactions.

Changes: Block gas validation

Layer / File(s) Summary
Structured gas-pool validation
crates/evm/src/block/mod.rs
The executor reports the transaction gas limit and remaining block gas in TransactionGasLimitMoreThanAvailableBlockGas when a transaction exceeds the available pool.
Gas-pool validation tests
crates/evm/src/block/mod.rs
Test cases check an initial 50,000-gas pool, a pool reduced by a regular transaction, and an L1 message that reserves its full gas limit.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: dylancai9, curryxbo

Merge Risk: Minimal · up to e4b81

Block gas-pool overflows are now reported as validation errors rather than internal execution errors, so overflowing blocks are classified as invalid. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: block gas-pool overflow now returns BlockValidationError instead of an internal execution error. The raw summary confirms the gas-limit check now returns TransactionGa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: block gas-pool overflow now returns BlockValidationError instead of an internal execution error. The raw summary confirms the gas-limit check now returns TransactionGasLimitMoreThanAvailableBlockGas, and the PR objectives match. The title is short, specific, and follows the conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5093aa3a-d0b3-4db5-9044-62c8743c866a
Commits

Reviewing files that changed from the base of the PR and between e01b16a and e4b8130.

Files selected for processing: 1

  • crates/evm/src/block/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

#[test]
fn single_tx_exceeding_block_gas_limit_returns_validation_error() {
let mut executor = test_executor(50_000);
let tx = eip1559_tx(0, 50_001);
#[test]
fn second_tx_exceeding_remaining_gas_pool_after_regular_tx_returns_validation_error() {
let mut executor = test_executor(50_000);
let tx0 = eip1559_tx(0, 21_000);
.expect("first tx must succeed");
assert_eq!(gas_out.tx_gas_used(), 21_000);

let tx1 = eip1559_tx(1, 30_000);
.expect("L1 message must succeed");
assert_eq!(gas_out.tx_gas_used(), 21_000);

let tx1 = eip1559_tx(0, 21_000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants