Skip to content

Commit 9217abf

Browse files
committed
refactor
1 parent c8f3312 commit 9217abf

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ futures = "0.3.31"
3131
hex = "0.4.3"
3232
http-body-util = "=0.1.0"
3333
indicatif = "0.17.9"
34+
keccak = "0.1.5"
35+
lazy_static = "1.5.0"
3436
num-bigint = "0.4.6"
37+
num-integer = "0.1.46"
3538
num-traits = "0.2.19"
3639
rand = "0.8"
3740
reqwest = "0.12.9"
@@ -53,8 +56,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
5356
utoipa = { version = "5.3.1", features = ["axum_extras"] }
5457
utoipa-swagger-ui = { version = "9", features = ["axum"] }
5558
version-compare = "=0.0.11"
56-
num-integer = "0.1.46"
57-
keccak = "0.1.5"
5859

5960
dry_hint_processor = { path = "crates/dry_hint_processor" }
6061
eth_essentials_cairo_vm_hints = { path = "packages/eth_essentials/cairo_vm_hints" }

crates/dry_hint_processor/src/syscall_handler/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use hints::vars;
1414
use serde::{Deserialize, Serialize};
1515
use starknet::CallContractHandler as StarknetCallContractHandler;
1616
use syscall_handler::{
17-
debug::DebugHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits, SyscallExecutionError, SyscallResult, SyscallSelector,
18-
WriteResponseResult,
17+
call_contract, call_contract::debug::DebugCallContractHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits,
18+
SyscallExecutionError, SyscallResult, SyscallSelector, WriteResponseResult,
1919
};
2020
use tokio::{sync::RwLock, task};
2121
use types::{
@@ -82,7 +82,7 @@ pub struct CallContractHandlerRelay {
8282
pub evm_call_contract_handler: EvmCallContractHandler,
8383
pub starknet_call_contract_handler: StarknetCallContractHandler,
8484
#[serde(skip)]
85-
pub debug_handler: DebugHandler,
85+
pub debug_call_contract_handler: DebugCallContractHandler,
8686
}
8787

8888
impl traits::SyscallHandler for CallContractHandlerRelay {
@@ -97,7 +97,7 @@ impl traits::SyscallHandler for CallContractHandlerRelay {
9797

9898
async fn execute(&mut self, request: Self::Request, vm: &mut VirtualMachine) -> SyscallResult<Self::Response> {
9999
match request.contract_address {
100-
addr if addr == Felt252::from_bytes_be_slice(b"debug") => self.debug_handler.execute(request, vm).await,
100+
v if v == call_contract::debug::CONTRACT_ADDRESS => self.debug_call_contract_handler.execute(request, vm).await,
101101
_ => {
102102
let chain_id = <Felt252 as TryInto<u128>>::try_into(*vm.get_integer((request.calldata_start + 2)?)?)
103103
.map_err(|e| SyscallExecutionError::InternalError(e.to_string().into()))?;

crates/sound_hint_processor/src/syscall_handler/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use cairo_vm::{
1717
use hints::vars;
1818
use serde::{Deserialize, Serialize};
1919
use syscall_handler::{
20-
debug::DebugHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits, SyscallExecutionError, SyscallResult, SyscallSelector,
21-
WriteResponseResult,
20+
call_contract, call_contract::debug::DebugCallContractHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits,
21+
SyscallExecutionError, SyscallResult, SyscallSelector, WriteResponseResult,
2222
};
2323
use tokio::{sync::RwLock, task};
2424
use types::{
@@ -86,15 +86,15 @@ impl CairoType for Memorizer {
8686
pub struct CallContractHandlerRelay {
8787
pub evm_call_contract_handler: EvmCallContractHandler,
8888
pub starknet_call_contract_handler: StarknetCallContractHandler,
89-
pub debug_handler: DebugHandler,
89+
pub debug_call_contract_handler: DebugCallContractHandler,
9090
}
9191

9292
impl CallContractHandlerRelay {
9393
pub fn new(dict_manager: Rc<RefCell<DictManager>>) -> Self {
9494
Self {
9595
evm_call_contract_handler: EvmCallContractHandler::new(dict_manager.clone()),
9696
starknet_call_contract_handler: StarknetCallContractHandler::new(dict_manager),
97-
debug_handler: DebugHandler,
97+
debug_call_contract_handler: DebugCallContractHandler,
9898
}
9999
}
100100
}
@@ -111,7 +111,7 @@ impl traits::SyscallHandler for CallContractHandlerRelay {
111111

112112
async fn execute(&mut self, request: Self::Request, vm: &mut VirtualMachine) -> SyscallResult<Self::Response> {
113113
match request.contract_address {
114-
addr if addr == Felt252::from_bytes_be_slice(b"debug") => self.debug_handler.execute(request, vm).await,
114+
v if v == call_contract::debug::CONTRACT_ADDRESS => self.debug_call_contract_handler.execute(request, vm).await,
115115
_ => {
116116
let chain_id = <Felt252 as TryInto<u128>>::try_into(*vm.get_integer((request.calldata_start + 2)?)?)
117117
.map_err(|e| SyscallExecutionError::InternalError(e.to_string().into()))?;

crates/syscall_handler/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ edition = "2021"
55

66
[dependencies]
77
cairo-vm.workspace = true
8-
thiserror.workspace = true
9-
types.workspace = true
10-
num-integer.workspace = true
118
keccak.workspace = true
129
num-bigint.workspace = true
10+
num-integer.workspace = true
1311
num-traits.workspace = true
1412
serde.workspace = true
1513
strum_macros.workspace = true
14+
thiserror.workspace = true
15+
types.workspace = true

crates/syscall_handler/src/debug.rs renamed to crates/syscall_handler/src/call_contract/debug.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ use types::cairo::{
88

99
use crate::{traits, SyscallExecutionError, SyscallResult, WriteResponseResult};
1010

11+
pub const CONTRACT_ADDRESS: Felt252 = Felt252::from_hex_unchecked("0x6465627567"); // 'debug' in hex
12+
1113
#[derive(FromRepr)]
1214
pub enum CallHandlerId {
1315
Print = 0,
1416
PrintArray = 1,
1517
}
1618

1719
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
18-
pub struct DebugHandler;
20+
pub struct DebugCallContractHandler;
1921

20-
impl traits::SyscallHandler for DebugHandler {
22+
impl traits::SyscallHandler for DebugCallContractHandler {
2123
type Request = CallContractRequest;
2224
type Response = CallContractResponse;
2325

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod debug;

crates/syscall_handler/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(unused_crate_dependencies)]
44
#![forbid(unsafe_code)]
55

6-
pub mod debug;
6+
pub mod call_contract;
77
pub mod keccak;
88
pub mod traits;
99

0 commit comments

Comments
 (0)