From c7904288d7c9770e31ce8ad37e57e3b46da60838 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 11 Jul 2023 17:04:39 +0200 Subject: [PATCH] fix: use tx gas limit for root trace --- .../revm/revm-inspectors/src/tracing/mod.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/revm/revm-inspectors/src/tracing/mod.rs b/crates/revm/revm-inspectors/src/tracing/mod.rs index b064e0dd692c..bf3e746c90f9 100644 --- a/crates/revm/revm-inspectors/src/tracing/mod.rs +++ b/crates/revm/revm-inspectors/src/tracing/mod.rs @@ -146,15 +146,15 @@ impl TracingInspector { /// /// Invoked on [Inspector::call]. #[allow(clippy::too_many_arguments)] - fn start_trace_on_call( + fn start_trace_on_call( &mut self, - depth: usize, + data: &EVMData<'_, DB>, address: Address, - data: Bytes, + input_data: Bytes, value: U256, kind: CallKind, caller: Address, - gas_limit: u64, + mut gas_limit: u64, maybe_precompile: Option, ) { // This will only be true if the inspector is configured to exclude precompiles and the call @@ -166,14 +166,20 @@ impl TracingInspector { PushTraceKind::PushAndAttachToParent }; + if self.trace_stack.is_empty() { + // this is the root call which should get the original gas limit of the transaction, + // because initialization costs are already subtracted from gas_limit + gas_limit = data.env.tx.gas_limit; + } + self.trace_stack.push(self.traces.push_trace( 0, push_kind, CallTrace { - depth, + depth: data.journaled_state.depth() as usize, address, kind, - data, + data: input_data, value, status: InstructionResult::Continue, caller, @@ -421,7 +427,7 @@ where self.config.exclude_precompile_calls.then(|| self.is_precompile_call(data, &to, value)); self.start_trace_on_call( - data.journaled_state.depth() as usize, + data, to, inputs.input.clone(), value, @@ -460,7 +466,7 @@ where let _ = data.journaled_state.load_account(inputs.caller, data.db); let nonce = data.journaled_state.account(inputs.caller).info.nonce; self.start_trace_on_call( - data.journaled_state.depth() as usize, + data, get_create_address(inputs, nonce), inputs.init_code.clone(), inputs.value,