Skip to content

Commit

Permalink
Fix Self-destruct Disorder (#170)
Browse files Browse the repository at this point in the history
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 #162
  • Loading branch information
ZzPoLariszZ authored Jul 23, 2024
1 parent cbf9452 commit 403164c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());

Expand Down

0 comments on commit 403164c

Please sign in to comment.