From 0ef68b7d63fee5337281848efe2289fe8f829e3d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 18 Jul 2023 17:34:38 +0200 Subject: [PATCH] fix: map more errors to messages (#3837) --- .../revm-inspectors/src/tracing/config.rs | 19 +++++++++++++ .../revm/revm-inspectors/src/tracing/types.rs | 28 +++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/crates/revm/revm-inspectors/src/tracing/config.rs b/crates/revm/revm-inspectors/src/tracing/config.rs index f968993062..5096d83075 100644 --- a/crates/revm/revm-inspectors/src/tracing/config.rs +++ b/crates/revm/revm-inspectors/src/tracing/config.rs @@ -1,5 +1,24 @@ use reth_rpc_types::trace::geth::GethDefaultTracingOptions; +/// What kind of tracing style this is. +/// +/// This affects things like error messages. +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub(crate) enum TraceStyle { + /// Parity style tracer + Parity, + /// Geth style tracer + #[allow(unused)] + Geth, +} + +impl TraceStyle { + /// Returns true if this is a parity style tracer. + pub(crate) const fn is_parity(self) -> bool { + matches!(self, Self::Parity) + } +} + /// Gives guidance to the [TracingInspector](crate::tracing::TracingInspector). /// /// Use [TracingInspectorConfig::default_parity] or [TracingInspectorConfig::default_geth] to get diff --git a/crates/revm/revm-inspectors/src/tracing/types.rs b/crates/revm/revm-inspectors/src/tracing/types.rs index 548ae72b87..76ff0f5100 100644 --- a/crates/revm/revm-inspectors/src/tracing/types.rs +++ b/crates/revm/revm-inspectors/src/tracing/types.rs @@ -1,6 +1,6 @@ //! Types for representing call trace items. -use crate::tracing::utils::convert_memory; +use crate::tracing::{config::TraceStyle, utils::convert_memory}; use reth_primitives::{abi::decode_revert_reason, bytes::Bytes, Address, H256, U256}; use reth_rpc_types::trace::{ geth::{CallFrame, CallLogFrame, GethDefaultTracingOptions, StructLog}, @@ -160,9 +160,26 @@ impl CallTrace { } /// Returns the error message if it is an erroneous result. - pub(crate) fn as_error(&self) -> Option { + pub(crate) fn as_error(&self, kind: TraceStyle) -> Option { + // See also self.is_error().then(|| match self.status { - InstructionResult::Revert => "Reverted".to_string(), + InstructionResult::Revert => { + if kind.is_parity() { "Reverted" } else { "execution reverted" }.to_string() + } + InstructionResult::OutOfGas | InstructionResult::MemoryOOG => { + if kind.is_parity() { "Out of gas" } else { "out of gas" }.to_string() + } + InstructionResult::OpcodeNotFound => { + if kind.is_parity() { "Bad instruction" } else { "invalid opcode" }.to_string() + } + InstructionResult::StackOverflow => "Out of stack".to_string(), + InstructionResult::InvalidJump => { + if kind.is_parity() { "Bad jump destination" } else { "invalid jump destination" } + .to_string() + } + InstructionResult::PrecompileError => { + if kind.is_parity() { "Built-in failed" } else { "precompiled failed" }.to_string() + } status => format!("{:?}", status), }) } @@ -324,7 +341,7 @@ impl CallTraceNode { pub(crate) fn parity_transaction_trace(&self, trace_address: Vec) -> TransactionTrace { let action = self.parity_action(); let output = self.parity_trace_output(); - let error = self.trace.as_error(); + let error = self.trace.as_error(TraceStyle::Parity); TransactionTrace { action, error, @@ -402,7 +419,8 @@ impl CallTraceNode { // we need to populate error and revert reason if !self.trace.success { call_frame.revert_reason = decode_revert_reason(self.trace.output.clone()); - call_frame.error = self.trace.as_error(); + // Note: the call tracer mimics parity's trace transaction and geth maps errors to parity style error messages, + call_frame.error = self.trace.as_error(TraceStyle::Parity); } if include_logs && !self.logs.is_empty() {