Skip to content

Comments

feat(revme): validate block gas used in blockchain tests#3416

Merged
rakita merged 15 commits intomainfrom
block-gas-validation
Feb 23, 2026
Merged

feat(revme): validate block gas used in blockchain tests#3416
rakita merged 15 commits intomainfrom
block-gas-validation

Conversation

@rakita
Copy link
Member

@rakita rakita commented Feb 10, 2026

Summary

  • Track cumulative gas used across all transactions in each block during blockchain test execution
  • Validate cumulative gas against expected gas_used from block headers
  • Use EIP-7778 logic for Amsterdam+ (block gas = max(spent, floor_gas), excluding refunds) and standard used() for earlier specs

Test plan

  • Run blockchain tests to verify gas validation passes for existing test vectors
  • Confirm new BlockGasUsedMismatch error surfaces correctly on mismatches

rakita added 10 commits February 9, 2026 15:37
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.
// 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())
Copy link
Member Author

Choose a reason for hiding this comment

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

EIP-7778 diff

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2026

Merging this PR will not alter performance

✅ 176 untouched benchmarks


Comparing block-gas-validation (a441a5c) with main (de746c6)

Open in CodSpeed

rakita and others added 2 commits February 12, 2026 02:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan

* fix: correct grammar in handler.rs comment
Base automatically changed from expose-gas to main February 12, 2026 13:20
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I dont have a better naming suggestion for ResultGas but maybe @klkvr has

all of this makes sense, smol bikeshed re the conversion fn

Comment on lines 11 to 20
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't this the same as like Gas::finalize|freeze unsure if this needs to be a standalone function?

@rakita rakita merged commit fea169f into main Feb 23, 2026
31 checks passed
@github-actions github-actions bot mentioned this pull request Feb 23, 2026
@rakita rakita deleted the block-gas-validation branch February 24, 2026 10:11
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.

4 participants