Skip to content

Commit ef62fdb

Browse files
authored
fix(evm): always decode EVM reverts (#8419)
1 parent 1bfbaff commit ef62fdb

File tree

1 file changed

+36
-33
lines changed
  • crates/evm/traces/src/decoder

1 file changed

+36
-33
lines changed

crates/evm/traces/src/decoder/mod.rs

+36-33
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ impl CallTraceDecoder {
350350
return DecodedCallTrace {
351351
label,
352352
call_data: Some(DecodedCallData { signature: "create2".to_string(), args: vec![] }),
353-
return_data: (!trace.status.is_ok())
354-
.then(|| self.revert_decoder.decode(&trace.output, Some(trace.status))),
353+
return_data: self.default_return_data(trace),
355354
};
356355
}
357356

@@ -372,7 +371,11 @@ impl CallTraceDecoder {
372371
}
373372
};
374373
let [func, ..] = &functions[..] else {
375-
return DecodedCallTrace { label, call_data: None, return_data: None };
374+
return DecodedCallTrace {
375+
label,
376+
call_data: None,
377+
return_data: self.default_return_data(trace),
378+
};
376379
};
377380

378381
DecodedCallTrace {
@@ -388,11 +391,7 @@ impl CallTraceDecoder {
388391
DecodedCallTrace {
389392
label,
390393
call_data: Some(DecodedCallData { signature, args }),
391-
return_data: if !trace.success {
392-
Some(self.revert_decoder.decode(&trace.output, Some(trace.status)))
393-
} else {
394-
None
395-
},
394+
return_data: self.default_return_data(trace),
396395
}
397396
}
398397
}
@@ -410,7 +409,7 @@ impl CallTraceDecoder {
410409

411410
if args.is_none() {
412411
if let Ok(v) = func.abi_decode_input(&trace.data[SELECTOR_LEN..], false) {
413-
args = Some(v.iter().map(|value| self.apply_label(value)).collect());
412+
args = Some(v.iter().map(|value| self.format_value(value)).collect());
414413
}
415414
}
416415
}
@@ -523,34 +522,32 @@ impl CallTraceDecoder {
523522

524523
/// Decodes a function's output into the given trace.
525524
fn decode_function_output(&self, trace: &CallTrace, funcs: &[Function]) -> Option<String> {
526-
let data = &trace.output;
527-
if trace.success {
528-
if trace.address == CHEATCODE_ADDRESS {
529-
if let Some(decoded) =
530-
funcs.iter().find_map(|func| self.decode_cheatcode_outputs(func))
531-
{
532-
return Some(decoded);
533-
}
534-
}
525+
if !trace.success {
526+
return self.default_return_data(trace);
527+
}
535528

536-
if let Some(values) =
537-
funcs.iter().find_map(|func| func.abi_decode_output(data, false).ok())
529+
if trace.address == CHEATCODE_ADDRESS {
530+
if let Some(decoded) = funcs.iter().find_map(|func| self.decode_cheatcode_outputs(func))
538531
{
539-
// Functions coming from an external database do not have any outputs specified,
540-
// and will lead to returning an empty list of values.
541-
if values.is_empty() {
542-
return None;
543-
}
532+
return Some(decoded);
533+
}
534+
}
544535

545-
return Some(
546-
values.iter().map(|value| self.apply_label(value)).format(", ").to_string(),
547-
);
536+
if let Some(values) =
537+
funcs.iter().find_map(|func| func.abi_decode_output(&trace.output, false).ok())
538+
{
539+
// Functions coming from an external database do not have any outputs specified,
540+
// and will lead to returning an empty list of values.
541+
if values.is_empty() {
542+
return None;
548543
}
549544

550-
None
551-
} else {
552-
Some(self.revert_decoder.decode(data, Some(trace.status)))
545+
return Some(
546+
values.iter().map(|value| self.format_value(value)).format(", ").to_string(),
547+
);
553548
}
549+
550+
None
554551
}
555552

556553
/// Custom decoding for cheatcode outputs.
@@ -566,6 +563,11 @@ impl CallTraceDecoder {
566563
.map(Into::into)
567564
}
568565

566+
/// The default decoded return data for a trace.
567+
fn default_return_data(&self, trace: &CallTrace) -> Option<String> {
568+
(!trace.success).then(|| self.revert_decoder.decode(&trace.output, Some(trace.status)))
569+
}
570+
569571
/// Decodes an event.
570572
pub async fn decode_event(&self, log: &LogData) -> DecodedCallLog {
571573
let &[t0, ..] = log.topics() else { return DecodedCallLog { name: None, params: None } };
@@ -594,7 +596,7 @@ impl CallTraceDecoder {
594596
.map(|(param, input)| {
595597
// undo patched names
596598
let name = input.name.clone();
597-
(name, self.apply_label(&param))
599+
(name, self.format_value(&param))
598600
})
599601
.collect(),
600602
),
@@ -628,7 +630,8 @@ impl CallTraceDecoder {
628630
identifier.write().await.identify_functions(funcs_it).await;
629631
}
630632

631-
fn apply_label(&self, value: &DynSolValue) -> String {
633+
/// Pretty-prints a value.
634+
fn format_value(&self, value: &DynSolValue) -> String {
632635
if let DynSolValue::Address(addr) = value {
633636
if let Some(label) = self.labels.get(addr) {
634637
return format!("{label}: [{addr}]");

0 commit comments

Comments
 (0)