From e06fdcebb0173d33fbdf9093784f3d822c2a526f Mon Sep 17 00:00:00 2001 From: Pia Date: Wed, 31 Jul 2024 09:20:04 -0400 Subject: [PATCH 1/3] hotfix path --- Cargo.lock | 143 ++------------------ Cargo.toml | 11 +- cli/Cargo.toml | 2 +- crates/pre-processor/src/module_registry.rs | 66 ++++----- 4 files changed, 44 insertions(+), 178 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 859bfc89..81ef6e79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2175,23 +2175,11 @@ dependencies = [ name = "hdp" version = "0.4.0" dependencies = [ - "hdp-cairo-runner 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-preprocessor 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-processor 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-provider 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "hdp" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b48d4f3ed4627f93adb3df5035b34a8ca5345a9fff8c71402642f925ed8d35" -dependencies = [ - "hdp-preprocessor 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-processor 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-provider 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hdp-cairo-runner", + "hdp-preprocessor", + "hdp-primitives", + "hdp-processor", + "hdp-provider", ] [[package]] @@ -2201,30 +2189,8 @@ dependencies = [ "alloy", "anyhow", "cairo-lang-starknet-classes", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-provider 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex", - "serde", - "serde_json", - "serde_with 2.3.3", - "starknet", - "starknet-crypto", - "tempfile", - "thiserror", - "tracing", -] - -[[package]] -name = "hdp-cairo-runner" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500b833308975920a4789fe7a4ef7c328cb30b5763da1284d4d3535cfded33fc" -dependencies = [ - "alloy", - "anyhow", - "cairo-lang-starknet-classes", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-provider 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hdp-primitives", + "hdp-provider", "regex", "serde", "serde_json", @@ -2244,7 +2210,7 @@ dependencies = [ "anyhow", "clap 4.5.4", "dotenv", - "hdp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hdp", "inquire", "serde", "serde_json", @@ -2263,35 +2229,9 @@ dependencies = [ "anyhow", "cairo-lang-starknet-classes", "futures", - "hdp-cairo-runner 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-provider 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static", - "reqwest 0.11.27", - "serde", - "serde_json", - "starknet", - "starknet-crypto", - "tempfile", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "hdp-preprocessor" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88e26881f1c03b6bcde41f9eccdd7e806804351600e50e44a220fb5b2d00165" -dependencies = [ - "alloy", - "alloy-merkle-tree", - "anyhow", - "cairo-lang-starknet-classes", - "futures", - "hdp-cairo-runner 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-provider 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hdp-cairo-runner", + "hdp-primitives", + "hdp-provider", "lazy_static", "reqwest 0.11.27", "serde", @@ -2321,50 +2261,15 @@ dependencies = [ "starknet-crypto", ] -[[package]] -name = "hdp-primitives" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3824542b75eb1151df198eea3cb45d7266e87184a1173f6fb4873fb9add5ca05" -dependencies = [ - "alloy", - "alloy-rlp", - "anyhow", - "cairo-lang-starknet-classes", - "eth-trie-proofs", - "rand", - "serde", - "serde_json", - "serde_with 2.3.3", - "starknet", - "starknet-crypto", -] - -[[package]] -name = "hdp-processor" -version = "0.4.0" -dependencies = [ - "alloy", - "alloy-merkle-tree", - "anyhow", - "hdp-cairo-runner 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde", - "serde_json", - "tracing", -] - [[package]] name = "hdp-processor" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469705fb7a88fd55d922945709828c3ec5fc5ea0107da4a3a760ca800f297e45" dependencies = [ "alloy", "alloy-merkle-tree", "anyhow", - "hdp-cairo-runner 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hdp-cairo-runner", + "hdp-primitives", "serde", "serde_json", "tracing", @@ -2379,27 +2284,7 @@ dependencies = [ "criterion", "eth-trie-proofs", "futures", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.10.5", - "reqwest 0.11.27", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "hdp-provider" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7364bab8544f1d3edbaf1b0249621d4e58a74866916c45f7ce81ea8545a11915" -dependencies = [ - "alloy", - "anyhow", - "eth-trie-proofs", - "futures", - "hdp-primitives 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hdp-primitives", "itertools 0.10.5", "reqwest 0.11.27", "serde", diff --git a/Cargo.toml b/Cargo.toml index 5fb45976..7b78290f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,11 +27,11 @@ categories = [ ] [workspace.dependencies] -hdp-preprocessor = { version = "0.4.0" } -hdp-processor = { version = "0.4.0" } -hdp-primitives = { version = "0.4.0" } -hdp-provider = { version = "0.4.0" } -hdp-cairo-runner = { version = "0.4.0" } +hdp-preprocessor = { path = "crates/pre-processor" } +hdp-processor = { path = "crates/processor" } +hdp-primitives = { path = "crates/primitives" } +hdp-provider = { path = "crates/provider" } +hdp-cairo-runner = { path = "crates/cairo-runner" } tokio = { version = "1", features = ["full"] } tempfile = "3.10.1" alloy-merkle-tree = { version = "0.6.0" } @@ -49,6 +49,7 @@ regex = "1" starknet = "0.10.0" starknet-crypto = "0.6.1" cairo-lang-starknet-classes = "2.6.4" +cairo-vm = "1.0.0-rc6" futures = "0.3.30" lazy_static = "1.4.0" thiserror = "1.0" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 3ac6dda9..fc7bdedd 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -19,7 +19,7 @@ path = "src/main.rs" [dependencies] tracing-subscriber = { version = "0.3.0", features = ["env-filter"] } -hdp = { version = "0.4.0", default-features = false, features = [ +hdp = { path = "../crates/hdp", default-features = false, features = [ "preprocessor", "processor", "provider", diff --git a/crates/pre-processor/src/module_registry.rs b/crates/pre-processor/src/module_registry.rs index 1ac9c884..45697251 100644 --- a/crates/pre-processor/src/module_registry.rs +++ b/crates/pre-processor/src/module_registry.rs @@ -7,7 +7,6 @@ use cairo_lang_starknet_classes::casm_contract_class::{ use hdp_primitives::task::{module::Module, ExtendedModule}; use reqwest::Client; -use serde::Deserialize; use starknet_crypto::FieldElement; use std::path::PathBuf; use thiserror::Error; @@ -38,11 +37,6 @@ pub struct ModuleRegistry { client: Client, } -#[derive(Deserialize)] -struct GitHubFileResponse { - download_url: String, -} - impl Default for ModuleRegistry { fn default() -> Self { Self::new() @@ -133,54 +127,40 @@ impl ModuleRegistry { &self, program_hash: FieldElement, ) -> Result { + let program_hash_hex = format!("{:#x}", program_hash); + info!( - "Fetching contract class from module registry... program_hash: {:#?}", - program_hash.to_string() + "Fetching contract class from module registry... program_hash: {}", + program_hash_hex ); - let program_hash_key = program_hash.to_string(); - let branch = "dev"; let api_url = format!( - "https://api.github.com/repos/HerodotusDev/hdp/contents/crates/pre-processor/module-registery/{}.json?ref={}", - program_hash_key, branch + "http://212.47.227.57/get-program?program_hash={}", + program_hash_hex ); - let response_text = self + let response = self .client .get(&api_url) .header("User-Agent", "request") .send() .await - .unwrap() - .text() - .await - .unwrap(); - - // Try to deserialize the response into GitHubFileResponse - let response: Result = - serde_json::from_str(&response_text); - let response = match response { - Ok(resp) => resp, - Err(err) => { - eprintln!("Failed to deserialize GitHubFileResponse: {}", err); - return Err(ModuleRegistryError::ClassSourceError("fail".to_string())); - } - }; - let download_response = self - .client - .get(&response.download_url) - .send() - .await - .unwrap(); - - let file_content = download_response.text().await.unwrap(); - let casm: CasmContractClass = serde_json::from_str(&file_content)?; - - info!( - "Contract class fetched successfully from program_hashh: {:?}", - program_hash - ); - Ok(casm) + .expect("response is failed"); + + // Check if the response status is successful + if response.status().is_success() { + let response_text = response.text().await.expect("cannot get response"); + let casm: CasmContractClass = serde_json::from_str(&response_text)?; + info!( + "Contract class fetched successfully from program_hash: {:?}", + program_hash + ); + Ok(casm) + } else { + Err(ModuleRegistryError::ClassSourceError( + "Failed to fetch contract class".to_string(), + )) + } } } From ecd9f8fde4bb53e810f3d5d1e608dd860e15cdf6 Mon Sep 17 00:00:00 2001 From: Pia Date: Wed, 31 Jul 2024 10:05:08 -0400 Subject: [PATCH 2/3] feat: dns resolve --- crates/pre-processor/src/module_registry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pre-processor/src/module_registry.rs b/crates/pre-processor/src/module_registry.rs index 45697251..feea4cc0 100644 --- a/crates/pre-processor/src/module_registry.rs +++ b/crates/pre-processor/src/module_registry.rs @@ -135,7 +135,7 @@ impl ModuleRegistry { ); let api_url = format!( - "http://212.47.227.57/get-program?program_hash={}", + "http://program-registery.api.herodotus.cloud/get-program?program_hash={}", program_hash_hex ); From 6c3a0fff22d79f2e2704452c01a950ccde2e86de Mon Sep 17 00:00:00 2001 From: Pia Date: Wed, 31 Jul 2024 10:10:53 -0400 Subject: [PATCH 3/3] fix: catch error on dry run --- crates/cairo-runner/src/dry_run.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/cairo-runner/src/dry_run.rs b/crates/cairo-runner/src/dry_run.rs index a486b8ff..c00bd347 100644 --- a/crates/cairo-runner/src/dry_run.rs +++ b/crates/cairo-runner/src/dry_run.rs @@ -62,7 +62,10 @@ impl DryRunner { let input_file_path = &NamedTempFile::new()?.path().to_path_buf(); fs::write(input_file_path, input_string).expect("Failed to write input file"); - let _ = self._run(input_file_path)?; + let output = self._run(input_file_path)?; + if output.is_empty() { + return Err(CairoRunnerError::CairoRunError); + } // parse output to return dry run result let dry_run_result = self.parse_run(&PathBuf::from(DRY_CAIRO_RUN_OUTPUT_FILE))?; @@ -73,6 +76,7 @@ impl DryRunner { /// Parse the output of the dry run command fn parse_run(&self, input_file_path: &Path) -> Result { let output = fs::read_to_string(input_file_path)?; + let fetch_keys: Vec = serde_json::from_str(&output)?; fs::remove_file(input_file_path).expect("Failed to remove input file"); if let Some(ref output_path) = self.output_file_path {