From 8c2e2c5e3ca60a4798427d9463c1a7f2216a2172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Duchesneau?= Date: Wed, 11 Nov 2026 11:25:11 -0500 Subject: [PATCH 1/2] Report no transfer for root calls halted before running On Amsterdam, evm2 runs the root frame hooks for a transaction whose runtime gas phase ran out of gas, so the inspector took the value of that call as transferred and rolled back. It never moved. --- crates/firehose/src/inspector.rs | 43 ++++++++++- .../firehose/src/inspector/tests/balance.rs | 75 ++++++++++++++++++- 2 files changed, 113 insertions(+), 5 deletions(-) diff --git a/crates/firehose/src/inspector.rs b/crates/firehose/src/inspector.rs index bbc8abf5a47..e236b96ad46 100644 --- a/crates/firehose/src/inspector.rs +++ b/crates/firehose/src/inspector.rs @@ -1,9 +1,10 @@ use alloy_primitives::{Address, Bytes, Log as AlloyLog, B256, KECCAK256_EMPTY, U256}; use evm2::{ + bytecode::Bytecode, evm::{AccountInfo, DynDatabase as _, JournalEntry, SYSTEM_MAX_SSTORES_PER_CALL}, interpreter::{InstrStop, Interpreter, Message, MessageKind, MessageResult, Word}, version::GasId, - Evm, EvmTypes, Inspector, + Evm, EvmFeatures, EvmTypes, Inspector, }; use firehose_tracer::{ pb::sf::ethereum::r#type::v2::balance_change::Reason, @@ -184,7 +185,9 @@ struct InspectorState { /// Value transfer `(from, to, value)` of the current non-self call, captured at call enter /// and cleared once the scan emitted it. If it survives to `call_end`, the call failed and /// evm2 rolled the transfer back before any hook saw it (a precompile that failed); Geth - /// records the transfer that happened before the revert, so `call_end` re-emits it. + /// records the transfer that happened before the revert, so `call_end` re-emits it. A root + /// call halted by the runtime gas phase never transferred, see + /// [`halted_in_runtime_gas_phase`]. pending_value_transfer: Option<(Address, Address, U256)>, /// Contracts that executed SELFDESTRUCT this transaction. A candidate whose frame reverted @@ -704,9 +707,11 @@ impl> InspectorState { } // A transfer still pending was rolled back before any hook could see it. It happened - // unless the call aborted before transferring. + // unless the call aborted before transferring, or the transaction's runtime gas phase + // halted its root call. if let Some((from, to, value)) = self.pending_value_transfer.take() && - !matches!(result.stop, InstrStop::OutOfFunds | InstrStop::CallTooDeep) + !matches!(result.stop, InstrStop::OutOfFunds | InstrStop::CallTooDeep) && + !(depth == 0 && halted_in_runtime_gas_phase(host, message, result.stop)) { let from_balance = account_info(host, &from).balance; let to_balance = account_info(host, &to).balance; @@ -1002,6 +1007,36 @@ fn frame_depth(host: &Evm<'_, T>, message: &Message) -> i32 { i32::from(message.depth) - i32::from(host.initial_call_depth()) } +/// Whether the EIP-2780 runtime gas phase halted `message`, a transaction's root call that sends +/// value and stopped with `stop`. The phase runs out of gas before the value moves, and evm2 still +/// runs the root frame's hooks without saying it never ran. +/// +/// Must stay in sync with the out-of-gas halts of evm2's `ethereum::prepare_initial_frame`: the +/// new-account state gas of value sent to an empty recipient, and the delegation access gas of an +/// EIP-7702 delegated recipient. +fn halted_in_runtime_gas_phase( + host: &mut Evm<'_, T>, + message: &Message, + stop: InstrStop, +) -> bool { + if !matches!(stop, InstrStop::OutOfGas) || !host.feature(EvmFeatures::EIP2780) { + return false; + } + // The recipient reads as the runtime gas phase saw it: a halt never touched it, and a call that + // ran out of gas later rolled its transfer back. + let recipient = account_info(host, &message.call_target); + // A call to an empty account runs no code, and a precompile that runs out of gas stops with + // `PrecompileOOG`, so only the new-account charge stops it with `OutOfGas`. + if recipient.is_empty() { + return true; + } + // A resolved delegation runs the delegate's code, the halted frame keeps the recipient as its + // code address. + message.code_address == message.call_target && + Bytecode::new_raw_checked(load_code(host, &recipient)) + .is_ok_and(|code| code.is_eip7702()) +} + /// The memory range the KECCAK256 about to run hashes, when its preimage is small enough to /// record. The offset and size are still on the stack; the range is read back in `step_end`. fn keccak256_range(interp: &Interpreter<'_, '_, T>) -> Option<(usize, usize)> { diff --git a/crates/firehose/src/inspector/tests/balance.rs b/crates/firehose/src/inspector/tests/balance.rs index 64919e7477c..e12430047ef 100644 --- a/crates/firehose/src/inspector/tests/balance.rs +++ b/crates/firehose/src/inspector/tests/balance.rs @@ -6,7 +6,7 @@ use super::{scenario::*, support::*}; use crate::{inspector::*, PreTxAdjust}; use alloy_eips::eip7702::SignedAuthorization; use alloy_rlp::Decodable; -use evm2::{ethereum::LazyAuthorization, SpecId}; +use evm2::{bytecode::Bytecode, ethereum::LazyAuthorization, SpecId, Version}; use firehose_tracer::pb; /// Block beneficiary of the priced transactions below. @@ -472,3 +472,76 @@ fn root_balance_reason_override_is_single_shot() { .collect(); assert_eq!(root_reasons, [Reason::IncreaseMint, Reason::GasBuy]); } + +/// The `Transfer` balance changes of `trx`, all calls together, as `(address, old, new)`. +fn transfers(trx: &pb::sf::ethereum::r#type::v2::TransactionTrace) -> Vec<(Address, U256, U256)> { + trx.calls + .iter() + .flat_map(|call| &call.balance_changes) + .filter(|change| change.reason == Reason::Transfer as i32) + .map(|change| { + (Address::from_slice(&change.address), big(&change.old_value), big(&change.new_value)) + }) + .collect() +} + +/// An Amsterdam transaction sending value to an empty account without the gas for its EIP-2780 +/// new-account charge runs out of gas before the value moves, so it reports no transfer. +#[test] +fn root_call_halted_on_new_account_gas_reports_no_transfer() { + let block = drive_txs( + SpecId::AMSTERDAM, + &[(SENDER, balance_account(SENDER_BALANCE))], + &[DriveTx::call(RECIPIENT, 3).with_gas(24_000)], + ); + let trx = &block.transaction_traces[0]; + + assert!(trx.calls[0].status_failed, "the root call runs out of gas"); + assert_eq!(trx.gas_used, 24_000); + assert_eq!(transfers(trx), []); +} + +/// An Amsterdam transaction sending value to an EIP-7702 delegated account without the gas to +/// access the delegate runs out of gas before the value moves, so it reports no transfer. +#[test] +fn root_call_halted_on_delegation_access_gas_reports_no_transfer() { + let block = drive_txs( + SpecId::AMSTERDAM, + &[ + (SENDER, balance_account(SENDER_BALANCE)), + (RECIPIENT, AccountInfo::default().with_code(Bytecode::new_eip7702(DELEGATE))), + ], + &[DriveTx::call(RECIPIENT, 3).with_gas(21_050)], + ); + let trx = &block.transaction_traces[0]; + + assert!(trx.calls[0].status_failed, "the root call runs out of gas"); + assert_eq!(trx.gas_used, 21_050); + assert_eq!(transfers(trx), []); +} + +/// An Amsterdam transaction that pays the new-account charge of an empty precompile, then runs +/// out of gas in the precompile, moved its value before the rollback, so it reports the +/// transfer as go-ethereum does. +#[test] +fn root_call_to_precompile_out_of_gas_reports_the_transfer() { + const ECRECOVER: Address = Address::with_last_byte(1); + + let new_account_gas = Version::new(SpecId::AMSTERDAM).gas_params.new_account_state_gas(); + let block = drive_txs( + SpecId::AMSTERDAM, + &[(SENDER, balance_account(SENDER_BALANCE))], + &[DriveTx::call(ECRECOVER, 3).with_gas(21_000 + new_account_gas + 100)], + ); + let trx = &block.transaction_traces[0]; + assert!(trx.calls[0].status_failed, "ecrecover runs out of gas"); + + let sender_balance = U256::from(SENDER_BALANCE); + assert_eq!( + transfers(trx), + [ + (SENDER, sender_balance, sender_balance - U256::from(3)), + (ECRECOVER, U256::ZERO, U256::from(3)), + ] + ); +} From d8409a7b76dc4d68c62da6692166e161252e55f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Duchesneau?= Date: Wed, 11 Nov 2026 11:25:12 -0500 Subject: [PATCH 2/2] Add reth-v2.11.0-fh3.1-1 changelog entry --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d584c3ac1b..084cfdabe6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ This changelog covers Firehose-specific changes only. For upstream reth changes, The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## reth-v2.11.0-fh3.1-1 + +### Fixed + +- On Amsterdam, a transaction whose root call sends value and runs out of gas in its runtime gas + phase no longer reports a `REASON_TRANSFER` debit of the sender and credit of the recipient. + The value never moves, and go-ethereum reports no transfer. This happens when the recipient is + empty and the transaction cannot pay its new-account state gas, or when the recipient is an + EIP-7702 delegated account and the transaction cannot pay to access the delegate. + `reth-v2.11.0-fh3.1` reported the transfer. + ## reth-v2.9.0-fh3.1-not-a-real-version-alpha.2 Tests the release made by sfreleaser, no Firehose changes.