From da3bc64fb423a4d02cd61b14756e23aab13498c6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 31 Jul 2023 15:01:58 +0200 Subject: [PATCH] fix: prevent child call out of bounds (#3920) --- crates/revm/revm-inspectors/src/tracing/mod.rs | 1 - crates/revm/revm-inspectors/src/tracing/types.rs | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/revm/revm-inspectors/src/tracing/mod.rs b/crates/revm/revm-inspectors/src/tracing/mod.rs index fe6c5b8609..de8a3b3b24 100644 --- a/crates/revm/revm-inspectors/src/tracing/mod.rs +++ b/crates/revm/revm-inspectors/src/tracing/mod.rs @@ -395,7 +395,6 @@ where if self.config.record_steps { self.gas_inspector.step_end(interp, data, is_static, eval); self.fill_step_on_step_end(interp, data, eval); - return eval } InstructionResult::Continue } diff --git a/crates/revm/revm-inspectors/src/tracing/types.rs b/crates/revm/revm-inspectors/src/tracing/types.rs index a7cb9ef4ae..83c720dd28 100644 --- a/crates/revm/revm-inspectors/src/tracing/types.rs +++ b/crates/revm/revm-inspectors/src/tracing/types.rs @@ -267,9 +267,12 @@ impl CallTraceNode { opcode::CALL | opcode::STATICCALL | opcode::CALLCODE => { - let call_id = self.children[child_id]; - item.call_child_id = Some(call_id); - child_id += 1; + // The opcode of this step is a call but it's possible that this step resulted + // in a revert or out of gas error in which case there's no actual child call executed and recorded: + if let Some(call_id) = self.children.get(child_id).copied() { + item.call_child_id = Some(call_id); + child_id += 1; + } } _ => {} } @@ -532,7 +535,9 @@ pub(crate) struct CallTraceStep { pub(crate) gas_cost: u64, /// Change of the contract state after step execution (effect of the SLOAD/SSTORE instructions) pub(crate) storage_change: Option, - /// Final status of the call + /// Final status of the step + /// + /// This is set after the step was executed. pub(crate) status: InstructionResult, }