Skip to content

Commit e4de7b7

Browse files
authored
refactor: replace internal CallKind (#6824)
* refactor: replace internal `CallKind` * chore: fmt
1 parent b3f57f1 commit e4de7b7

File tree

11 files changed

+23
-77
lines changed

11 files changed

+23
-77
lines changed

Cargo.lock

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

crates/debugger/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ foundry-common.workspace = true
1414
foundry-compilers.workspace = true
1515
foundry-evm-core.workspace = true
1616
foundry-evm-traces.workspace = true
17+
revm-inspectors.workspace = true
1718

1819
alloy-primitives.workspace = true
1920

crates/debugger/src/tui/context.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
use crate::{Debugger, ExitReason};
44
use alloy_primitives::Address;
55
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
6-
use foundry_evm_core::{
7-
debug::{DebugNodeFlat, DebugStep},
8-
utils::CallKind,
9-
};
6+
use foundry_evm_core::debug::{DebugNodeFlat, DebugStep};
7+
use revm_inspectors::tracing::types::CallKind;
108
use std::{cell::RefCell, ops::ControlFlow};
119

1210
/// This is currently used to remember last scroll position so screen doesn't wiggle as much.
@@ -271,7 +269,7 @@ impl DebuggerContext<'_> {
271269
if let Some(step) = node.steps.iter().position(|step| step.pc == *pc) {
272270
self.draw_memory.inner_call_index = i;
273271
self.current_step = step;
274-
break
272+
break;
275273
}
276274
}
277275
}

crates/debugger/src/tui/draw.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::context::DebuggerContext;
44
use crate::op::OpcodeParam;
55
use alloy_primitives::U256;
66
use foundry_compilers::sourcemap::SourceElement;
7-
use foundry_evm_core::{debug::Instruction, utils::CallKind};
7+
use foundry_evm_core::debug::Instruction;
88
use ratatui::{
99
layout::{Alignment, Constraint, Direction, Layout, Rect},
1010
style::{Color, Modifier, Style},
@@ -13,6 +13,7 @@ use ratatui::{
1313
widgets::{Block, Borders, Paragraph, Wrap},
1414
};
1515
use revm::interpreter::opcode;
16+
use revm_inspectors::tracing::types::CallKind;
1617
use std::{cmp, collections::VecDeque, fmt::Write, io};
1718

1819
impl DebuggerContext<'_> {

crates/evm/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ revm = { workspace = true, default-features = false, features = [
3131
"arbitrary",
3232
"optimism",
3333
] }
34+
revm-inspectors.workspace = true
3435
alloy-providers = { workspace = true }
3536
alloy-transport = { workspace = true }
3637
alloy-rpc-types = { workspace = true }

crates/evm/core/src/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::utils::CallKind;
21
use alloy_primitives::{Address, U256};
32
use revm::interpreter::OpCode;
3+
use revm_inspectors::tracing::types::CallKind;
44
use serde::{Deserialize, Serialize};
55
use std::fmt::Display;
66

crates/evm/core/src/utils.rs

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,19 @@
11
use alloy_json_abi::{Function, JsonAbi};
22
use alloy_primitives::FixedBytes;
33
use alloy_rpc_types::{Block, Transaction};
4-
use ethers_core::types::{ActionType, CallType, Chain, H256, U256};
4+
use ethers_core::types::{Chain, H256, U256};
55
use eyre::ContextCompat;
66
use foundry_common::types::ToAlloy;
77
use revm::{
8-
interpreter::{CallScheme, InstructionResult},
9-
primitives::{CreateScheme, Eval, Halt, SpecId, TransactTo},
8+
interpreter::InstructionResult,
9+
primitives::{Eval, Halt, SpecId, TransactTo},
1010
};
11-
use serde::{Deserialize, Serialize};
1211

1312
pub use foundry_compilers::utils::RuntimeOrHandle;
1413
pub use revm::primitives::State as StateChangeset;
1514

1615
pub use crate::ic::*;
1716

18-
// TODO(onbjerg): Remove this and use `CallKind` from the tracer.
19-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
20-
#[serde(rename_all = "UPPERCASE")]
21-
#[derive(Default)]
22-
pub enum CallKind {
23-
#[default]
24-
Call,
25-
StaticCall,
26-
CallCode,
27-
DelegateCall,
28-
Create,
29-
Create2,
30-
}
31-
32-
impl From<CallScheme> for CallKind {
33-
fn from(scheme: CallScheme) -> Self {
34-
match scheme {
35-
CallScheme::Call => CallKind::Call,
36-
CallScheme::StaticCall => CallKind::StaticCall,
37-
CallScheme::CallCode => CallKind::CallCode,
38-
CallScheme::DelegateCall => CallKind::DelegateCall,
39-
}
40-
}
41-
}
42-
43-
impl From<CreateScheme> for CallKind {
44-
fn from(create: CreateScheme) -> Self {
45-
match create {
46-
CreateScheme::Create => CallKind::Create,
47-
CreateScheme::Create2 { .. } => CallKind::Create2,
48-
}
49-
}
50-
}
51-
52-
impl From<CallKind> for ActionType {
53-
fn from(kind: CallKind) -> Self {
54-
match kind {
55-
CallKind::Call | CallKind::StaticCall | CallKind::DelegateCall | CallKind::CallCode => {
56-
ActionType::Call
57-
}
58-
CallKind::Create => ActionType::Create,
59-
CallKind::Create2 => ActionType::Create,
60-
}
61-
}
62-
}
63-
64-
impl From<CallKind> for CallType {
65-
fn from(ty: CallKind) -> Self {
66-
match ty {
67-
CallKind::Call => CallType::Call,
68-
CallKind::StaticCall => CallType::StaticCall,
69-
CallKind::CallCode => CallType::CallCode,
70-
CallKind::DelegateCall => CallType::DelegateCall,
71-
CallKind::Create => CallType::None,
72-
CallKind::Create2 => CallType::None,
73-
}
74-
}
75-
}
76-
7717
/// Small helper function to convert [U256] into [H256].
7818
#[inline]
7919
pub fn u256_to_h256_le(u: U256) -> H256 {

crates/evm/evm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ revm = { workspace = true, default-features = false, features = [
3535
"optional_no_base_fee",
3636
"arbitrary",
3737
] }
38-
38+
revm-inspectors.workspace = true
3939
ethers-core.workspace = true
4040
ethers-signers.workspace = true
4141
itertools.workspace = true

crates/evm/evm/src/inspectors/debugger.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use foundry_evm_core::{
44
backend::DatabaseExt,
55
constants::CHEATCODE_ADDRESS,
66
debug::{DebugArena, DebugNode, DebugStep, Instruction},
7-
utils::{gas_used, CallKind},
7+
utils::gas_used,
88
};
99
use revm::{
1010
interpreter::{
@@ -13,6 +13,7 @@ use revm::{
1313
},
1414
EVMData, Inspector,
1515
};
16+
use revm_inspectors::tracing::types::CallKind;
1617

1718
/// An inspector that collects debug nodes on every step of the interpreter.
1819
#[derive(Clone, Debug, Default)]
@@ -127,7 +128,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Debugger {
127128
// TODO: Does this increase gas cost?
128129
if let Err(err) = data.journaled_state.load_account(call.caller, data.db) {
129130
let gas = Gas::new(call.gas_limit);
130-
return (InstructionResult::Revert, None, gas, err.abi_encode_revert())
131+
return (InstructionResult::Revert, None, gas, err.abi_encode_revert());
131132
}
132133

133134
let nonce = data.journaled_state.account(call.caller).info.nonce;

crates/forge/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ ethers-middleware.workspace = true
3535
ethers-providers.workspace = true
3636
ethers-signers.workspace = true
3737

38+
revm-inspectors.workspace = true
39+
3840
comfy-table = "7"
3941
eyre.workspace = true
4042
proptest = "1"

crates/forge/bin/cmd/script/transaction.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ use foundry_common::{
1010
types::{ToAlloy, ToEthers},
1111
SELECTOR_LEN,
1212
};
13-
use foundry_evm::{
14-
constants::DEFAULT_CREATE2_DEPLOYER,
15-
traces::{CallKind, CallTraceDecoder},
16-
};
13+
use foundry_evm::{constants::DEFAULT_CREATE2_DEPLOYER, traces::CallTraceDecoder};
14+
use revm_inspectors::tracing::types::CallKind;
1715
use serde::{Deserialize, Serialize};
1816
use std::collections::BTreeMap;
1917

0 commit comments

Comments
 (0)