From 403164cb47af6ae618863fa9280a5de938949372 Mon Sep 17 00:00:00 2001 From: ZzPoLariszZ <39354078+ZzPoLariszZ@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:44:55 +0100 Subject: [PATCH] Fix Self-destruct Disorder (#170) The `suicide`/`selfdestruct` trace should not be immediately after the parent trace but after all of the parent's subtraces. This can be fixed by ordering the `traces` using the attribute `trace_address` inside. closes https://github.com/paradigmxyz/revm-inspectors/issues/162 --- src/tracing/builder/parity.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tracing/builder/parity.rs b/src/tracing/builder/parity.rs index fc03882e..56fe4fd3 100644 --- a/src/tracing/builder/parity.rs +++ b/src/tracing/builder/parity.rs @@ -226,6 +226,8 @@ impl ParityTraceBuilder { if trace_types.contains(&TraceType::VmTrace) { Some(self.vm_trace()) } else { None }; let mut traces = Vec::with_capacity(if with_traces { self.nodes.len() } else { 0 }); + // Boolean marker to track if sorting for selfdestruct is needed + let mut sorting_selfdestruct = false; for node in self.iter_traceable_nodes() { let trace_address = self.trace_address(node.idx); @@ -250,11 +252,17 @@ impl ParityTraceBuilder { if let Some(trace) = node.parity_selfdestruct_trace(addr) { traces.push(trace); + sorting_selfdestruct = true; } } } } + // Sort the traces only if a selfdestruct trace was encountered + if sorting_selfdestruct { + traces.sort_by(|a, b| a.trace_address.cmp(&b.trace_address)); + } + let traces = with_traces.then_some(traces); let diff = with_diff.then_some(StateDiff::default());