Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Feb 3, 2025
1 parent c8f3312 commit 9217abf
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ futures = "0.3.31"
hex = "0.4.3"
http-body-util = "=0.1.0"
indicatif = "0.17.9"
keccak = "0.1.5"
lazy_static = "1.5.0"
num-bigint = "0.4.6"
num-integer = "0.1.46"
num-traits = "0.2.19"
rand = "0.8"
reqwest = "0.12.9"
Expand All @@ -53,8 +56,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
utoipa = { version = "5.3.1", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "9", features = ["axum"] }
version-compare = "=0.0.11"
num-integer = "0.1.46"
keccak = "0.1.5"

dry_hint_processor = { path = "crates/dry_hint_processor" }
eth_essentials_cairo_vm_hints = { path = "packages/eth_essentials/cairo_vm_hints" }
Expand Down
8 changes: 4 additions & 4 deletions crates/dry_hint_processor/src/syscall_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use hints::vars;
use serde::{Deserialize, Serialize};
use starknet::CallContractHandler as StarknetCallContractHandler;
use syscall_handler::{
debug::DebugHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits, SyscallExecutionError, SyscallResult, SyscallSelector,
WriteResponseResult,
call_contract, call_contract::debug::DebugCallContractHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits,
SyscallExecutionError, SyscallResult, SyscallSelector, WriteResponseResult,
};
use tokio::{sync::RwLock, task};
use types::{
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct CallContractHandlerRelay {
pub evm_call_contract_handler: EvmCallContractHandler,
pub starknet_call_contract_handler: StarknetCallContractHandler,
#[serde(skip)]
pub debug_handler: DebugHandler,
pub debug_call_contract_handler: DebugCallContractHandler,
}

impl traits::SyscallHandler for CallContractHandlerRelay {
Expand All @@ -97,7 +97,7 @@ impl traits::SyscallHandler for CallContractHandlerRelay {

async fn execute(&mut self, request: Self::Request, vm: &mut VirtualMachine) -> SyscallResult<Self::Response> {
match request.contract_address {
addr if addr == Felt252::from_bytes_be_slice(b"debug") => self.debug_handler.execute(request, vm).await,
v if v == call_contract::debug::CONTRACT_ADDRESS => self.debug_call_contract_handler.execute(request, vm).await,
_ => {
let chain_id = <Felt252 as TryInto<u128>>::try_into(*vm.get_integer((request.calldata_start + 2)?)?)
.map_err(|e| SyscallExecutionError::InternalError(e.to_string().into()))?;
Expand Down
10 changes: 5 additions & 5 deletions crates/sound_hint_processor/src/syscall_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use cairo_vm::{
use hints::vars;
use serde::{Deserialize, Serialize};
use syscall_handler::{
debug::DebugHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits, SyscallExecutionError, SyscallResult, SyscallSelector,
WriteResponseResult,
call_contract, call_contract::debug::DebugCallContractHandler, felt_from_ptr, keccak::KeccakHandler, run_handler, traits,
SyscallExecutionError, SyscallResult, SyscallSelector, WriteResponseResult,
};
use tokio::{sync::RwLock, task};
use types::{
Expand Down Expand Up @@ -86,15 +86,15 @@ impl CairoType for Memorizer {
pub struct CallContractHandlerRelay {
pub evm_call_contract_handler: EvmCallContractHandler,
pub starknet_call_contract_handler: StarknetCallContractHandler,
pub debug_handler: DebugHandler,
pub debug_call_contract_handler: DebugCallContractHandler,
}

impl CallContractHandlerRelay {
pub fn new(dict_manager: Rc<RefCell<DictManager>>) -> Self {
Self {
evm_call_contract_handler: EvmCallContractHandler::new(dict_manager.clone()),
starknet_call_contract_handler: StarknetCallContractHandler::new(dict_manager),
debug_handler: DebugHandler,
debug_call_contract_handler: DebugCallContractHandler,
}
}
}
Expand All @@ -111,7 +111,7 @@ impl traits::SyscallHandler for CallContractHandlerRelay {

async fn execute(&mut self, request: Self::Request, vm: &mut VirtualMachine) -> SyscallResult<Self::Response> {
match request.contract_address {
addr if addr == Felt252::from_bytes_be_slice(b"debug") => self.debug_handler.execute(request, vm).await,
v if v == call_contract::debug::CONTRACT_ADDRESS => self.debug_call_contract_handler.execute(request, vm).await,
_ => {
let chain_id = <Felt252 as TryInto<u128>>::try_into(*vm.get_integer((request.calldata_start + 2)?)?)
.map_err(|e| SyscallExecutionError::InternalError(e.to_string().into()))?;
Expand Down
6 changes: 3 additions & 3 deletions crates/syscall_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ edition = "2021"

[dependencies]
cairo-vm.workspace = true
thiserror.workspace = true
types.workspace = true
num-integer.workspace = true
keccak.workspace = true
num-bigint.workspace = true
num-integer.workspace = true
num-traits.workspace = true
serde.workspace = true
strum_macros.workspace = true
thiserror.workspace = true
types.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ use types::cairo::{

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

pub const CONTRACT_ADDRESS: Felt252 = Felt252::from_hex_unchecked("0x6465627567"); // 'debug' in hex

#[derive(FromRepr)]
pub enum CallHandlerId {
Print = 0,
PrintArray = 1,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct DebugHandler;
pub struct DebugCallContractHandler;

impl traits::SyscallHandler for DebugHandler {
impl traits::SyscallHandler for DebugCallContractHandler {
type Request = CallContractRequest;
type Response = CallContractResponse;

Expand Down
1 change: 1 addition & 0 deletions crates/syscall_handler/src/call_contract/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod debug;
2 changes: 1 addition & 1 deletion crates/syscall_handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]

pub mod debug;
pub mod call_contract;
pub mod keccak;
pub mod traits;

Expand Down

0 comments on commit 9217abf

Please sign in to comment.