Skip to content

Commit c238ca6

Browse files
Introduce marshalled opcode type
1 parent e661328 commit c238ca6

File tree

17 files changed

+345
-208
lines changed

17 files changed

+345
-208
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ serde = { version = "1", default-features = false }
5858
serde_json = { version = "1", default-features = false }
5959
sha3 = { version = "0.10", default-features = false }
6060
similar-asserts = { version = "1", default-features = false }
61+
smallvec = { version = "1.13", default-features = false }
6162
static_assertions = { version = "1", default-features = false }
6263
syn = { version = "2", default-features = false }
6364
thiserror = { version = "1.0.69", default-features = false }

crates/evm-tracing-client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ publish = false
88
evm-tracing-events = { path = "../evm-tracing-events" }
99

1010
codec = { workspace = true }
11-
evm = { workspace = true }
1211
frame-support = { workspace = true, features = ["std"] }
1312
hex = { workspace = true, features = ["serde"] }
1413
serde = { workspace = true, features = ["derive"] }

crates/evm-tracing-client/src/formatters/call_tracer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Call tracer formatter implementation.
22
3+
use evm_tracing_events::MarshalledOpcode;
34
use sp_core::sp_std::cmp::Ordering;
45

56
use crate::{
@@ -54,10 +55,12 @@ impl super::ResponseFormatter for Formatter {
5455
call_type,
5556
} => CallTracerInner::Call {
5657
call_type: match call_type {
57-
CallType::Call => evm::Opcode::CALL,
58-
CallType::CallCode => evm::Opcode::CALLCODE,
59-
CallType::DelegateCall => evm::Opcode::DELEGATECALL,
60-
CallType::StaticCall => evm::Opcode::STATICCALL,
58+
CallType::Call => MarshalledOpcode::call_opcode(),
59+
CallType::CallCode => MarshalledOpcode::callcode_opcode(),
60+
CallType::DelegateCall => {
61+
MarshalledOpcode::delegatecall_opcode()
62+
}
63+
CallType::StaticCall => MarshalledOpcode::staticcall_opcode(),
6164
},
6265
to,
6366
input,
@@ -85,13 +88,13 @@ impl super::ResponseFormatter for Formatter {
8588
CreateResult::Error { .. } => None,
8689
},
8790
value,
88-
call_type: evm::Opcode::CREATE,
91+
call_type: MarshalledOpcode::create_opcode(),
8992
},
9093
BlockscoutCallInner::SelfDestruct { balance, to } => {
9194
CallTracerInner::SelfDestruct {
9295
value: balance,
9396
to,
94-
call_type: evm::Opcode::SUICIDE,
97+
call_type: MarshalledOpcode::selfdestruct_opcode(),
9598
}
9699
}
97100
},

crates/evm-tracing-client/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ pub mod formatters;
44
pub mod listeners;
55
mod serialization;
66
pub mod types;
7-
mod utils;

crates/evm-tracing-client/src/listeners/call_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ mod tests {
634634
evm::CreateScheme,
635635
gasometer::Snapshot,
636636
runtime::{Memory, Stack},
637-
Context as EvmContext,
637+
Context as EvmContext, MarshalledOpcode,
638638
};
639639
use sp_core::H256;
640640

@@ -757,7 +757,7 @@ mod tests {
757757
match event_type {
758758
TestRuntimeEvent::Step => RuntimeEvent::Step {
759759
context: test_context(),
760-
opcode: evm::Opcode::STOP,
760+
opcode: MarshalledOpcode::default(),
761761
position: Ok(0u64),
762762
stack: test_stack(),
763763
memory: test_memory(),

crates/evm-tracing-client/src/listeners/raw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use evm_tracing_events::{
44
runtime::Capture, runtime::ExitReason, Event, GasometerEvent, Listener as ListenerT,
5-
RuntimeEvent, StepEventFilter,
5+
MarshalledOpcode, RuntimeEvent, StepEventFilter,
66
};
77
use sp_core::{sp_std::collections::btree_map::BTreeMap, H160, H256};
88

@@ -48,7 +48,7 @@ struct Context {
4848
#[derive(Debug)]
4949
struct Step {
5050
/// Current opcode.
51-
opcode: evm::Opcode,
51+
opcode: MarshalledOpcode,
5252
/// Depth of the context.
5353
depth: usize,
5454
/// Remaining gas.
@@ -289,7 +289,7 @@ impl Listener {
289289
}
290290
}
291291
}
292-
Err(Capture::Trap(opcode)) if ContextType::from(opcode).is_some() => {
292+
Err(Capture::Trap(opcode)) if ContextType::from(opcode.clone()).is_some() => {
293293
self.new_context = true;
294294
}
295295
_ => (),

crates/evm-tracing-client/src/serialization.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Serialization functions for various types and formats.
22
3+
use evm_tracing_events::MarshalledOpcode;
34
use serde::{
45
ser::{Error, SerializeSeq},
56
Serializer,
@@ -50,16 +51,11 @@ where
5051
}
5152

5253
/// Serializes opcode.
53-
pub fn opcode_serialize<S>(opcode: &evm::Opcode, serializer: S) -> Result<S::Ok, S::Error>
54+
pub fn opcode_serialize<S>(opcode: &MarshalledOpcode, serializer: S) -> Result<S::Ok, S::Error>
5455
where
5556
S: Serializer,
5657
{
57-
let d = match crate::utils::opcode_known_name(opcode) {
58-
Some(s) => s.to_uppercase(),
59-
None => format!("UNKNOWN({})", opcode.0),
60-
};
61-
62-
serializer.serialize_str(&d)
58+
serializer.serialize_str(&opcode.to_string())
6359
}
6460

6561
/// Serializes string.

crates/evm-tracing-client/src/types/call_tracer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Call tracer explicitly types.
22
33
use codec::{Decode, Encode};
4+
use evm_tracing_events::MarshalledOpcode;
45
use serde::Serialize;
56
use sp_core::{H160, U256};
67

@@ -36,7 +37,7 @@ pub enum CallTracerInner {
3637
Call {
3738
/// Call type.
3839
#[serde(rename = "type", serialize_with = "opcode_serialize")]
39-
call_type: evm::Opcode,
40+
call_type: MarshalledOpcode,
4041
/// To.
4142
to: H160,
4243
/// Input.
@@ -53,7 +54,7 @@ pub enum CallTracerInner {
5354
Create {
5455
/// Call type.
5556
#[serde(rename = "type", serialize_with = "opcode_serialize")]
56-
call_type: evm::Opcode,
57+
call_type: MarshalledOpcode,
5758
/// Input.
5859
#[serde(serialize_with = "bytes_0x_serialize")]
5960
input: Vec<u8>,
@@ -79,7 +80,7 @@ pub enum CallTracerInner {
7980
SelfDestruct {
8081
/// Call type.
8182
#[serde(rename = "type", serialize_with = "opcode_serialize")]
82-
call_type: evm::Opcode,
83+
call_type: MarshalledOpcode,
8384
/// To.
8485
to: H160,
8586
/// Value.

crates/evm-tracing-client/src/types/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
extern crate alloc;
44

55
use codec::{Decode, Encode};
6+
use evm_tracing_events::MarshalledOpcode;
67
use serde::Serialize;
78
use sp_core::{H160, H256};
89

@@ -77,15 +78,19 @@ pub enum ContextType {
7778

7879
impl ContextType {
7980
/// Obtain context type from opcode.
80-
pub fn from(opcode: evm::Opcode) -> Option<Self> {
81-
match opcode {
82-
evm::Opcode::CREATE | evm::Opcode::CREATE2 => Some(ContextType::Create),
83-
evm::Opcode::CALL => Some(ContextType::Call(CallType::Call)),
84-
evm::Opcode::CALLCODE => Some(ContextType::Call(CallType::CallCode)),
85-
evm::Opcode::DELEGATECALL => Some(ContextType::Call(CallType::DelegateCall)),
86-
evm::Opcode::STATICCALL => Some(ContextType::Call(CallType::StaticCall)),
87-
_ => None,
81+
pub fn from(opcode: MarshalledOpcode) -> Option<Self> {
82+
if let Some(opcode_known_name) = opcode.known_name() {
83+
return match &opcode_known_name.to_uppercase()[..] {
84+
"CREATE" | "CREATE2" => Some(ContextType::Create),
85+
"CALL" => Some(ContextType::Call(CallType::Call)),
86+
"CALLCODE" => Some(ContextType::Call(CallType::CallCode)),
87+
"DELEGATECALL" => Some(ContextType::Call(CallType::DelegateCall)),
88+
"STATICCALL" => Some(ContextType::Call(CallType::StaticCall)),
89+
_ => None,
90+
};
8891
}
92+
93+
None
8994
}
9095
}
9196

0 commit comments

Comments
 (0)