feat(revme): validate block gas used in blockchain tests#3416
Merged
Conversation
Replace loose `gas_used` and `gas_refunded` fields in all three `ExecutionResult` variants with a single `gas: ResultGas` struct that exposes richer gas accounting: `gas_used`, `gas_refunded`, `gas_spent` (pre-refund), and `floor_gas` (EIP-7623).
Remove the redundant `gas_used` field from `ResultGas` since it can always be derived as `gas_spent - gas_refunded`. The struct now stores only three independent values (gas_spent, gas_refunded, floor_gas) and exposes `gas_used()` as a method.
- Rename fields to align with Gas struct methods: gas_spent → spent, gas_refunded → refunded, gas_used() → used() Eliminates redundant gas.gas_spent pattern (now gas.spent) - Add #[serde(rename)] to preserve JSON key stability - Add Display impl for ResultGas (conditionally shows refunded/floor) - Simplify ExecutionResult Display to delegate to ResultGas Display - Improve documentation with source mapping table - Add tests for ResultGas Display and used() method
Add `limit` field to `ResultGas` so it contains all gas information without requiring external context. Also add `remaining()` derived method (limit - spent) to complement `used()` (spent - refunded). ResultGas now mirrors the full Gas struct snapshot: - limit: transaction gas limit - spent: gas consumed before refund - refunded: gas refund amount - floor_gas: EIP-7623 floor gas - used(): spent - refunded (derived) - remaining(): limit - spent (derived)
…cution` Add intrinsic_gas field to ResultGas so it carries the initial tx overhead gas. Change post_execution to return ResultGas directly, and have execution_result receive a pre-built ResultGas instead of InitialAndFloorGas.
- Make all ResultGas fields private - Add getter methods: limit(), spent(), refunded(), floor_gas(), intrinsic_gas() - Add builder methods: with_limit(), with_spent(), with_refunded(), with_floor_gas(), with_intrinsic_gas() - Add setter methods: set_limit(), set_spent(), set_refunded(), set_floor_gas(), set_intrinsic_gas() - Add derived methods: final_used(), inner_refunded(), final_refunded()
- Rewrite struct doc table to reference getter methods instead of fields - Fix used() doc formula to include floor_gas: max(spent - refunded, floor_gas) - Fix incomplete refunded field doc, point to final_refunded() - Remove stale final_used() reference, remove refunded() getter (replaced by inner_refunded)
Add cumulative gas tracking per block and validate against the expected gas_used from block headers. Uses EIP-7778 logic for Amsterdam+ where block gas excludes refunds (spent vs floor_gas), falling back to the standard used() calculation for earlier specs.
rakita
commented
Feb 10, 2026
| // For pre-Amsterdam, block gas = used() = max(spent - refunded, floor_gas). | ||
| let gas = result.result.gas(); | ||
| cumulative_gas_used += if spec_id.is_enabled_in(SpecId::AMSTERDAM) { | ||
| gas.spent().max(gas.floor_gas()) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan * fix: correct grammar in handler.rs comment
mattsse
reviewed
Feb 23, 2026
Comment on lines
11
to
20
Collaborator
There was a problem hiding this comment.
isn't this the same as like Gas::finalize|freeze unsure if this needs to be a standalone function?
klkvr
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gas_usedfrom block headersused()for earlier specsTest plan
BlockGasUsedMismatcherror surfaces correctly on mismatches