diff --git a/core/executor/src/tracing.rs b/core/executor/src/tracing.rs index f9b4ffa1e..ac072fd41 100644 --- a/core/executor/src/tracing.rs +++ b/core/executor/src/tracing.rs @@ -32,11 +32,6 @@ macro_rules! trace_type { self.0.len() } - #[allow(dead_code)] - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - pub fn into_raw(self) -> Vec<[u8; 32]> { self.0 } @@ -48,15 +43,6 @@ macro_rules! trace_type { #[derive(Default, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct $name(pub std::collections::BTreeMap<$key, $val>); - impl IntoIterator for $name { - type Item = ($key, $val); - type IntoIter = std::collections::btree_map::IntoIter<$key, $val>; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } - } - impl $name { pub fn insert(&mut self, key: $key, value: $val) { self.0.insert(key, value); @@ -414,8 +400,18 @@ impl TryFrom for Web3TransactionTrace { if log_len > 1 { let logs = &value.logs().0; - let (mut index, current_depth) = (0usize, logs[0].depth); - ret.calls = Some(build_subcalls(logs, &mut index, current_depth)); + + if !logs.windows(2).all(|pair| { + let (prev, next) = (&pair[0], &pair[1]); + + prev.depth == next.depth + || prev.depth + 1 == next.depth + || prev.depth == next.depth + 1 + }) { + return Err("Log depth variation is not smooth".to_string()); + } + + ret.calls = Some(build_subcalls(logs, &mut 0, logs[0].depth)); } Ok(ret) @@ -450,11 +446,8 @@ fn build_subcalls( *index += 1; } else if t_log.depth == (current_depth + 1) { - let sub_calls = build_subcalls(traces, index, current_depth + 1); - - println!("\n{:?}\n", sub_calls); - - stack.last_mut().unwrap().calls = Some(sub_calls); + stack.last_mut().unwrap().calls = + Some(build_subcalls(traces, index, current_depth + 1)); } else { return stack; } @@ -491,31 +484,6 @@ impl TransactionTrace { } } -#[derive(Default, Clone, Debug, PartialEq, Eq)] -pub struct StepTransactionTrace { - inner: TransactionTrace, - step: usize, -} - -#[allow(dead_code)] -impl StepTransactionTrace { - pub fn new(transaction_trace: TransactionTrace) -> Self { - Self { - inner: transaction_trace, - step: 0, - } - } - - pub fn step(&mut self) -> Option<&TraceLog> { - if self.step > self.inner.struct_logs.len() { - None - } else { - self.step += 1; - Some(&self.inner.struct_logs[self.step]) - } - } -} - #[derive(Default, Clone, Debug, PartialEq, Eq)] pub struct Logs(pub Vec); @@ -570,24 +538,12 @@ mod wrapped_opcode { #[derive(Default, Clone, Copy, Debug, PartialEq, Eq)] pub struct Opcode(u8); - impl PartialEq for Opcode { - fn eq(&self, other: &evm::Opcode) -> bool { - self.0 == other.as_u8() - } - } - impl From for Opcode { fn from(value: evm::Opcode) -> Self { Opcode::new(value.as_u8()) } } - impl From for Opcode { - fn from(value: revm_interpreter::opcode::OpCode) -> Self { - Opcode::new(value.u8()) - } - } - impl Display for Opcode { fn fmt(&self, f: &mut Formatter<'_>) -> Result { Display::fmt( @@ -749,6 +705,98 @@ mod tests { let mut i = 0usize; let res = build_subcalls(&logs, &mut i, 1); - println!("{:?}", serde_json::to_string(&res).unwrap()); + + let data = r#"[ + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x1", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x" + }, + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x1", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x", + "calls": [ + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x2", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x", + "calls": [ + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x3", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x" + } + ] + }, + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x2", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x" + } + ] + }, + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x1", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x", + "calls": [ + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x2", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x" + } + ] + }, + { + "type_": "", + "from": "0x0000000000000000000000000000000000000000", + "to": "0x0000000000000000000000000000000000000000", + "value": "0x1", + "gas": "0x0", + "gas_used": "0x0", + "input": "0x", + "output": "0x" + }]"#; + + assert_eq!( + res, + serde_json::from_str::>(data).unwrap() + ); } }