fix(levm): validate remaining block gas in parallel pipeline by sueun-dev · Pull Request #6342 · lambdaclass/ethrex · GitHub
Skip to content

fix(levm): validate remaining block gas in parallel pipeline#6342

Merged
ElFantasma merged 2 commits into
lambdaclass:mainfrom
sueun-dev:fix-parallel-gas-limit-check
Mar 16, 2026
Merged

fix(levm): validate remaining block gas in parallel pipeline#6342
ElFantasma merged 2 commits into
lambdaclass:mainfrom
sueun-dev:fix-parallel-gas-limit-check

Conversation

@sueun-dev

Copy link
Copy Markdown
Contributor

Summary

  • carry each transaction's gas_limit() into the BAL-backed parallel execution result set
  • enforce the same remaining block gas check used by the sequential LEVM path when building parallel receipts
  • add a regression test for a later transaction whose gas_limit exceeds the remaining block gas

Fixes #6341.

Testing

  • cargo test -p ethrex-vm

Copilot AI review requested due to automatic review settings March 8, 2026 20:52
@sueun-dev sueun-dev requested a review from a team as a code owner March 8, 2026 20:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the Amsterdam BAL-backed parallel LEVM execution pipeline with the sequential path by enforcing the “remaining block gas” constraint based on cumulative post-refund gas (EIP-7778), preventing blocks from being accepted when a later tx’s gas_limit() exceeds remaining block gas.

Changes:

  • Carry tx.gas_limit() through the parallel execution result tuple.
  • Add build_parallel_receipts(...) to sort results, run check_gas_limit(...) during receipt construction, and return (receipts, block_gas_used).
  • Add a regression test covering a later transaction whose gas_limit exceeds remaining block gas.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sueun-dev sueun-dev changed the title Validate remaining block gas in parallel LEVM pipeline fix(levm): validate remaining block gas in parallel pipeline Mar 8, 2026
@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown

@edg-l edg-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks for the PR

The CI does it but I validated the ef-tests still pass with
make -C tooling/ef_tests/blockchain test

I checked if geth does this check, but it seems they don't either, so they are probs missing this validation too.

let mut block_gas_used = 0_u64;

for (_, tx_type, tx_gas_limit, report) in results {
check_gas_limit(cumulative_gas_used, tx_gas_limit, block_gas_limit)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: this passes cumulative_gas_used (sum of gas_spent, post-refund) to check_gas_limit, but the sequential paths (lines 107 and 215) pass block_gas_used (sum of gas_used, pre-refund). Post-EIP-7778 these differ: gas_spent <= gas_used, so the parallel path becomes more lenient and could accept blocks that the sequential path rejects.

Should be:

check_gas_limit(block_gas_used, tx_gas_limit, block_gas_limit)?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I got this wrong. The sequential paths (lines 122 and 285 on main) actually use cumulative_gas_used (post-refund), not block_gas_used. PR #6309 explicitly fixed this to use post-refund gas because pre-refund gas causes false "Gas allowance exceeded" rejections on tightly-packed Amsterdam blocks with large SSTORE refunds (see the post-mortem there).

Your original code using cumulative_gas_used was correct. Commit 6b7f80 switching to block_gas_used reintroduces the bug that #6309 fixed. Please revert to cumulative_gas_used for the parallel path to match the sequential paths.

}

#[test]
fn test_build_parallel_receipts_rejects_tx_that_exceeds_remaining_block_gas() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the test uses gas_used == gas_spent for all entries, so it doesn't exercise the bug described above. Consider using different values (e.g., gas_used: 70, gas_spent: 60) to verify the check uses the pre-refund value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard this too — since the check should use cumulative_gas_used (post-refund), the test values should match that. Though having gas_used != gas_spent in the test is still useful to verify the receipt uses gas_spent for cumulative_gas_used correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much! I have been following the project for a while, so I'm really happy I could contribute!!

@ElFantasma ElFantasma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Sorry again for my mistake, and thanks for your contribution!

@ilitteri ilitteri enabled auto-merge March 11, 2026 13:46
@ilitteri

Copy link
Copy Markdown
Collaborator

Hey @sueun-dev, the PR is good to go. At ethrex, we have a commit signature verification policy that states that all commits must be verified (read here).

Please, sign the commits of this PR for it to be able to be merged.

auto-merge was automatically disabled March 11, 2026 16:36

Head branch was pushed to by a user without write access

@sueun-dev sueun-dev force-pushed the fix-parallel-gas-limit-check branch from 67660a0 to 6fcaf4c Compare March 11, 2026 16:36
@sueun-dev

Copy link
Copy Markdown
Contributor Author

@ElFantasma ElFantasma mentioned this pull request Mar 12, 2026
11 tasks
@ElFantasma ElFantasma added this pull request to the merge queue Mar 16, 2026
Merged via the queue into lambdaclass:main with commit 5e9f245 Mar 16, 2026
58 checks passed
Muzry pushed a commit to Muzry/ethrex that referenced this pull request Mar 17, 2026
…lass#6342)

## Summary
- carry each transaction's `gas_limit()` into the BAL-backed parallel
execution result set
- enforce the same remaining block gas check used by the sequential LEVM
path when building parallel receipts
- add a regression test for a later transaction whose `gas_limit`
exceeds the remaining block gas

Fixes lambdaclass#6341.

## Testing
- `cargo test -p ethrex-vm`

Co-authored-by: Sueun Cho <sueun-dev@users.noreply.github.com>
Co-authored-by: ElFantasma <estebandh@gmail.com>
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.

Parallel LEVM pipeline skips remaining block gas validation

5 participants