diff --git a/crates/revm/revm-inspectors/src/tracing/mod.rs b/crates/revm/revm-inspectors/src/tracing/mod.rs index 0dfee063a..644b5262b 100644 --- a/crates/revm/revm-inspectors/src/tracing/mod.rs +++ b/crates/revm/revm-inspectors/src/tracing/mod.rs @@ -24,6 +24,7 @@ mod utils; use crate::tracing::{ arena::PushTraceKind, types::{CallTraceNode, StorageChange}, + utils::gas_used, }; pub use builder::{ geth::{self, GethTraceBuilder}, @@ -193,7 +194,7 @@ impl TracingInspector { /// This expects an existing trace [Self::start_trace_on_call] fn fill_trace_on_call_end( &mut self, - _data: &EVMData<'_, DB>, + data: &EVMData<'_, DB>, status: InstructionResult, gas: &Gas, output: Bytes, @@ -202,7 +203,14 @@ impl TracingInspector { let trace_idx = self.pop_trace_idx(); let trace = &mut self.traces.arena[trace_idx].trace; - trace.gas_used = gas.spend(); + if trace_idx == 0 { + // this is the root call which should get the gas used of the transaction + // refunds are applied after execution, which is when the root call ends + trace.gas_used = gas_used(data.env.cfg.spec_id, gas.spend(), gas.refunded() as u64); + } else { + trace.gas_used = gas.spend(); + } + trace.status = status; trace.success = matches!(status, return_ok!()); trace.output = output.clone(); diff --git a/crates/revm/revm-inspectors/src/tracing/utils.rs b/crates/revm/revm-inspectors/src/tracing/utils.rs index b3d41f49e..64468f825 100644 --- a/crates/revm/revm-inspectors/src/tracing/utils.rs +++ b/crates/revm/revm-inspectors/src/tracing/utils.rs @@ -23,7 +23,6 @@ pub(crate) fn convert_memory(data: &[u8]) -> Vec { /// Get the gas used, accounting for refunds #[inline] -#[allow(unused)] pub(crate) fn gas_used(spec: SpecId, spent: u64, refunded: u64) -> u64 { let refund_quotient = if SpecId::enabled(spec, SpecId::LONDON) { 5 } else { 2 }; spent - (refunded).min(spent / refund_quotient)