From 1a540c77f031e3fe23d9a5b0d1dc7c67291eca42 Mon Sep 17 00:00:00 2001 From: Pia Date: Tue, 3 Sep 2024 12:37:28 +0900 Subject: [PATCH 1/6] chore: ci to just file --- .github/workflows/ci.yml | 5 ++--- Makefile.toml | 29 ----------------------------- justfile | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 32 deletions(-) delete mode 100644 Makefile.toml create mode 100644 justfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d247b59d..7575e505 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,6 @@ jobs: run: | rustup component add clippy rustup component add rustfmt - - name: Install cargo-make - run: cargo install --debug cargo-make + - uses: taiki-e/install-action@just - name: Run clippy and formatter checks - run: cargo make run-ci-flow + run: just run-ci-flow diff --git a/Makefile.toml b/Makefile.toml deleted file mode 100644 index 408c717c..00000000 --- a/Makefile.toml +++ /dev/null @@ -1,29 +0,0 @@ -[env] -CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true - -[tasks.format] -install_crate = "rustfmt" -command = "cargo" -args = ["fmt", "--", "--check"] -description = "Run rustfmt to check the code formatting without making changes." - -[tasks.clean] -command = "cargo" -args = ["clean"] -description = "Clean up the project by removing the target directory." - -[tasks.clippy] -command = "cargo" -args = ["clippy", "--all-targets", "--all-features", "--", "-Dwarnings"] -description = "Run clippy to catch common mistakes and improve your Rust code." - -[tasks.test] -workspace = false -command = "cargo" -args = ["llvm-cov", "nextest", "--features", "test_utils"] -description = "Execute all unit tests in the workspace." - -[tasks.run-ci-flow] -workspace = false -description = "Run the entire CI pipeline including format, clippy, and test checks." -dependencies = ["format", "clippy", "test"] diff --git a/justfile b/justfile new file mode 100644 index 00000000..b698c87f --- /dev/null +++ b/justfile @@ -0,0 +1,22 @@ +# Set environment variable +export CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE := "true" + +# Run rustfmt to check the code formatting without making changes +format: + cargo fmt -- --check + +# Clean up the project by removing the target directory +clean: + cargo clean + +# Run clippy to catch common mistakes and improve your Rust code +clippy: + cargo clippy --all-targets --all-features -- -Dwarnings + +# Execute all unit tests in the workspace +test: + cargo llvm-cov nextest --features test_utils + +# Run the entire CI pipeline including format, clippy, and test checks +run-ci-flow: format clippy test + @echo "CI flow completed" From f20276130c0afcc1c1f3e61b534627bf9690aa5e Mon Sep 17 00:00:00 2001 From: Pia Date: Tue, 3 Sep 2024 14:26:25 +0900 Subject: [PATCH 2/6] wip --- Cargo.lock | 343 +++++++++++++++++++++++++- Cargo.toml | 3 +- hdp/Cargo.toml | 2 + hdp/src/provider/error.rs | 16 +- hdp/src/provider/evm/rpc.rs | 14 +- hdp/src/provider/starknet/mod.rs | 4 +- hdp/src/provider/starknet/provider.rs | 28 +++ hdp/src/provider/starknet/rpc.rs | 155 ++++++++++++ hdp/src/provider/starknet/types.rs | 73 ++++++ 9 files changed, 616 insertions(+), 22 deletions(-) create mode 100644 hdp/src/provider/starknet/provider.rs create mode 100644 hdp/src/provider/starknet/rpc.rs create mode 100644 hdp/src/provider/starknet/types.rs diff --git a/Cargo.lock b/Cargo.lock index 30a118f9..5210da32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -854,6 +854,12 @@ dependencies = [ "rustc_version 0.4.0", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "atty" version = "0.2.14" @@ -1212,6 +1218,12 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.0" @@ -1335,6 +1347,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "const-fnv1a-hash" version = "1.1.0" @@ -2016,6 +2038,16 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" +dependencies = [ + "gloo-timers", + "send_wrapper 0.4.0", +] + [[package]] name = "futures-util" version = "0.3.30" @@ -2094,6 +2126,52 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-net" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06f627b1a58ca3d42b45d6104bf1e1a03799df472df00988b6ba21accc10580" +dependencies = [ + "futures-channel", + "futures-core", + "futures-sink", + "gloo-utils", + "http 1.1.0", + "js-sys", + "pin-project", + "serde", + "serde_json", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "gloo-utils" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "good_lp" version = "1.8.1" @@ -2134,6 +2212,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.1.0", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.4.1" @@ -2174,6 +2271,7 @@ dependencies = [ "eth-trie-proofs", "futures", "itertools 0.10.5", + "jsonrpsee", "lazy_static", "regex", "reqwest 0.11.27", @@ -2182,6 +2280,7 @@ dependencies = [ "serde_with 2.3.3", "starknet", "starknet-crypto", + "starknet-types-core", "tempfile", "thiserror", "tokio", @@ -2338,7 +2437,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -2361,6 +2460,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", + "h2 0.4.6", "http 1.1.0", "http-body 1.0.0", "httparse", @@ -2385,6 +2485,24 @@ dependencies = [ "tokio-rustls 0.24.1", ] +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.3.1", + "hyper-util", + "log", + "rustls 0.23.10", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -2637,6 +2755,26 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jni" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + [[package]] name = "js-sys" version = "0.3.69" @@ -2646,6 +2784,131 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "jsonrpsee" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ec465b607a36dc5dd45d48b7689bc83f679f66a3ac6b6b21cc787a11e0f8685" +dependencies = [ + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-http-client", + "jsonrpsee-types", + "jsonrpsee-wasm-client", + "jsonrpsee-ws-client", +] + +[[package]] +name = "jsonrpsee-client-transport" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f0977f9c15694371b8024c35ab58ca043dbbf4b51ccb03db8858a021241df1" +dependencies = [ + "base64 0.22.0", + "futures-channel", + "futures-util", + "gloo-net", + "http 1.1.0", + "jsonrpsee-core", + "pin-project", + "rustls 0.23.10", + "rustls-pki-types", + "rustls-platform-verifier", + "soketto", + "thiserror", + "tokio", + "tokio-rustls 0.26.0", + "tokio-util", + "tracing", + "url", +] + +[[package]] +name = "jsonrpsee-core" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e942c55635fbf5dc421938b8558a8141c7e773720640f4f1dbe1f4164ca4e221" +dependencies = [ + "async-trait", + "bytes", + "futures-timer", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "jsonrpsee-types", + "pin-project", + "rustc-hash 2.0.0", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "wasm-bindgen-futures", +] + +[[package]] +name = "jsonrpsee-http-client" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33774602df12b68a2310b38a535733c477ca4a498751739f89fe8dbbb62ec4c" +dependencies = [ + "async-trait", + "base64 0.22.0", + "http-body 1.0.0", + "hyper 1.3.1", + "hyper-rustls 0.27.2", + "hyper-util", + "jsonrpsee-core", + "jsonrpsee-types", + "rustls 0.23.10", + "rustls-platform-verifier", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "tracing", + "url", +] + +[[package]] +name = "jsonrpsee-types" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b67d6e008164f027afbc2e7bb79662650158d26df200040282d2aa1cbb093b" +dependencies = [ + "http 1.1.0", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "jsonrpsee-wasm-client" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0470d0ae043ffcb0cd323797a631e637fb4b55fe3eaa6002934819458bba62a7" +dependencies = [ + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-types", +] + +[[package]] +name = "jsonrpsee-ws-client" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "992bf67d1132f88edf4a4f8cff474cf01abb2be203004a2b8e11c2b20795b99e" +dependencies = [ + "http 1.1.0", + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-types", + "url", +] + [[package]] name = "jsonwebtoken" version = "9.3.0" @@ -3599,11 +3862,11 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", + "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-rustls", + "hyper-rustls 0.24.2", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -3748,6 +4011,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -3803,6 +4072,7 @@ version = "0.23.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" dependencies = [ + "log", "once_cell", "ring", "rustls-pki-types", @@ -3811,6 +4081,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04182dffc9091a404e0fc069ea5cd60e5b866c3adf881eff99a32d048242dffa" +dependencies = [ + "openssl-probe", + "rustls-pemfile 2.1.2", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -3836,6 +4119,33 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +[[package]] +name = "rustls-platform-verifier" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93bda3f493b9abe5b93b3e7e3ecde0df292f2bd28c0296b90586ee0055ff5123" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls 0.23.10", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki 0.102.4", + "security-framework", + "security-framework-sys", + "webpki-roots 0.26.3", + "winapi", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -3893,7 +4203,7 @@ dependencies = [ "log", "oorandom", "parking_lot 0.11.2", - "rustc-hash", + "rustc-hash 1.1.0", "salsa-macros", "smallvec", ] @@ -4014,6 +4324,7 @@ dependencies = [ "core-foundation", "core-foundation-sys", "libc", + "num-bigint", "security-framework-sys", ] @@ -4051,6 +4362,12 @@ dependencies = [ "pest", ] +[[package]] +name = "send_wrapper" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" + [[package]] name = "send_wrapper" version = "0.6.0" @@ -4323,6 +4640,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "soketto" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37468c595637c10857701c990f93a40ce0e357cedb0953d1c26c8d8027f9bb53" +dependencies = [ + "base64 0.22.0", + "bytes", + "futures", + "httparse", + "log", + "rand", + "sha1", +] + [[package]] name = "spin" version = "0.9.8" @@ -4891,6 +5223,7 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -5516,7 +5849,7 @@ dependencies = [ "log", "pharos", "rustc_version 0.4.0", - "send_wrapper", + "send_wrapper 0.6.0", "thiserror", "wasm-bindgen", "wasm-bindgen-futures", diff --git a/Cargo.toml b/Cargo.toml index 05890d1e..1bf76b87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [workspace] -resolver = "2" members = ["cli", "examples/private-input-module", "hdp"] [workspace.package] +resolver = "2" version = "0.4.0" edition = "2021" license-file = "LICENSE" @@ -37,6 +37,7 @@ rand = "0.8.4" regex = "1" starknet = "0.10.0" starknet-crypto = "0.6.1" +starknet-types-core = "0.1.0" cairo-lang-starknet-classes = "2.7.0" cairo-vm = "1.0.0-rc6" futures = "0.3.30" diff --git a/hdp/Cargo.toml b/hdp/Cargo.toml index 6ff37feb..e9ef6a42 100644 --- a/hdp/Cargo.toml +++ b/hdp/Cargo.toml @@ -24,6 +24,7 @@ serde = { workspace = true } serde_with = { workspace = true } serde_json = { workspace = true } starknet-crypto = { workspace = true } +starknet-types-core = { workspace = true } starknet = { workspace = true } thiserror.workspace = true alloy-merkle-tree = { workspace = true } @@ -33,6 +34,7 @@ reqwest = { workspace = true } lazy_static = { workspace = true } eth-trie-proofs = { workspace = true } itertools = { workspace = true } +jsonrpsee = { version = "0.24.3", features = ["http-client", "client"] } [features] default = [] diff --git a/hdp/src/provider/error.rs b/hdp/src/provider/error.rs index c82699fb..f55377b3 100644 --- a/hdp/src/provider/error.rs +++ b/hdp/src/provider/error.rs @@ -1,9 +1,8 @@ +use alloy::primitives::BlockNumber; use thiserror::Error; use crate::provider::indexer::IndexerError; -use super::evm::rpc::RpcProviderError; - /// Error type for provider #[derive(Error, Debug)] pub enum ProviderError { @@ -34,3 +33,16 @@ pub enum ProviderError { #[error("Fetch key error: {0}")] FetchKeyError(String), } + +/// Error from [`RpcProvider`] +#[derive(Error, Debug)] +pub enum RpcProviderError { + #[error("Failed to send proofs with mpsc")] + MpscError( + #[from] + tokio::sync::mpsc::error::SendError<( + BlockNumber, + alloy::rpc::types::EIP1186AccountProofResponse, + )>, + ), +} diff --git a/hdp/src/provider/evm/rpc.rs b/hdp/src/provider/evm/rpc.rs index 24d33e7e..e315b00f 100644 --- a/hdp/src/provider/evm/rpc.rs +++ b/hdp/src/provider/evm/rpc.rs @@ -15,25 +15,13 @@ use alloy::{ }; use futures::future::join_all; use reqwest::Url; -use thiserror::Error; use tokio::sync::{ mpsc::{self, Sender}, RwLock, }; use tracing::debug; -/// Error from [`RpcProvider`] -#[derive(Error, Debug)] -pub enum RpcProviderError { - #[error("Failed to send proofs with mpsc")] - MpscError( - #[from] - tokio::sync::mpsc::error::SendError<( - BlockNumber, - alloy::rpc::types::EIP1186AccountProofResponse, - )>, - ), -} +use crate::provider::error::RpcProviderError; /// RPC provider for fetching data from Ethereum RPC /// It is a wrapper around the alloy provider, using eth_getProof for fetching account and storage proofs diff --git a/hdp/src/provider/starknet/mod.rs b/hdp/src/provider/starknet/mod.rs index a8c241cb..93a521a5 100644 --- a/hdp/src/provider/starknet/mod.rs +++ b/hdp/src/provider/starknet/mod.rs @@ -1 +1,3 @@ -pub struct StarknetProvider {} +pub mod provider; +pub mod rpc; +pub mod types; diff --git a/hdp/src/provider/starknet/provider.rs b/hdp/src/provider/starknet/provider.rs new file mode 100644 index 00000000..d322fa9f --- /dev/null +++ b/hdp/src/provider/starknet/provider.rs @@ -0,0 +1,28 @@ +use crate::provider::{config::ProviderConfig, indexer::Indexer}; + +use super::rpc::RpcProvider; + +pub struct StarknetProvider { + /// Account and storage trie provider + pub(crate) rpc_provider: RpcProvider, + /// Header provider + pub(crate) header_provider: Indexer, +} + +#[cfg(feature = "test_utils")] +impl Default for StarknetProvider { + fn default() -> Self { + Self::new(&ProviderConfig::default()) + } +} + +impl StarknetProvider { + pub fn new(config: &ProviderConfig) -> Self { + let rpc_provider = RpcProvider::new(config.rpc_url.to_owned(), config.max_requests); + let indexer = Indexer::new(config.chain_id); + Self { + rpc_provider, + header_provider: indexer, + } + } +} diff --git a/hdp/src/provider/starknet/rpc.rs b/hdp/src/provider/starknet/rpc.rs new file mode 100644 index 00000000..2184b4d9 --- /dev/null +++ b/hdp/src/provider/starknet/rpc.rs @@ -0,0 +1,155 @@ +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, + time::Instant, +}; + +use alloy::primitives::BlockNumber; + +use futures::future::join_all; +use jsonrpsee::{ + core::{client::ClientT, BoxError, ClientError}, + http_client::{HttpClient, HttpClientBuilder}, + rpc_params, +}; +use reqwest::{Client, Url}; +use starknet_types_core::felt::Felt; +use tokio::sync::{ + mpsc::{self, Sender}, + RwLock, +}; +use tracing::debug; + +use crate::provider::error::RpcProviderError; + +use super::types::GetProofOutput; + +/// !Note: have to use pathfinder node as we need `pathfinder_getProof` +pub struct RpcProvider { + client: HttpClient, + chunk_size: u64, +} + +impl RpcProvider { + pub fn new(rpc_url: Url, chunk_size: u64) -> Self { + let client = HttpClientBuilder::default().build(rpc_url).unwrap(); + Self { client, chunk_size } + } + + pub async fn get_account_proofs(&self, blocks: Vec, address: Felt) {} + + async fn get_proofs( + &self, + blocks: Vec, + address: Felt, + storage_key: Option, + ) -> Result, RpcProviderError> { + let start_fetch = Instant::now(); + let (rpc_sender, mut rx) = mpsc::channel::<(BlockNumber, GetProofOutput)>(32); + self.spawn_proof_fetcher(rpc_sender, blocks, address, storage_key); + + let mut fetched_proofs = HashMap::new(); + while let Some((block_number, proof)) = rx.recv().await { + fetched_proofs.insert(block_number, proof); + } + let duration = start_fetch.elapsed(); + debug!("time taken (Fetch): {:?}", duration); + + Ok(fetched_proofs) + } + + fn spawn_proof_fetcher( + &self, + rpc_sender: Sender<(BlockNumber, GetProofOutput)>, + blocks: Vec, + address: Felt, + storage_key: Option, + ) { + let chunk_size = self.chunk_size; + let provider_clone = self.client.clone(); + let target_blocks_length = blocks.len(); + + debug!( + "fetching proofs for {}, with chunk size: {}", + address, chunk_size + ); + + tokio::spawn(async move { + let mut try_count = 0; + let blocks_map = Arc::new(RwLock::new(HashSet::::new())); + + while blocks_map.read().await.len() < target_blocks_length { + try_count += 1; + if try_count > 50 { + panic!("❗️❗️❗️ Too many retries, failed to fetch all blocks") + } + let fetched_blocks_clone = blocks_map.read().await.clone(); + + let blocks_to_fetch: Vec = blocks + .iter() + .filter(|block_number| !fetched_blocks_clone.contains(block_number)) + .take(chunk_size as usize) + .cloned() + .collect(); + + let fetch_futures = blocks_to_fetch + .into_iter() + .map(|block_number| { + let fetched_blocks_clone = blocks_map.clone(); + let rpc_sender = rpc_sender.clone(); + let provider_clone = provider_clone.clone(); + async move { + let proof = pathfinder_get_proof( + &provider_clone, + address, + block_number, + storage_key, + ) + .await; + handle_proof_result( + proof, + block_number, + fetched_blocks_clone, + rpc_sender, + ) + .await; + } + }) + .collect::>(); + + join_all(fetch_futures).await; + } + }); + } +} + +/// Fetches proof (account or storage) for a given block number +async fn pathfinder_get_proof( + provider: &HttpClient, + address: Felt, + block_number: BlockNumber, + storage_key: Option, +) -> Result { + match storage_key { + Some(key) => { + let params = rpc_params!["param1", "param2"]; + let response: String = provider.request("method_name", params).await?; + let get_proof_output: GetProofOutput = serde_json::from_str(&response)?; + Ok(get_proof_output) + } + None => { + let params = rpc_params!["param1", "param2"]; + let response: String = provider.request("method_name", params).await?; + let get_proof_output: GetProofOutput = serde_json::from_str(&response)?; + Ok(get_proof_output) + } + } +} + +async fn handle_proof_result( + proof: Result, + block_number: BlockNumber, + blocks_map: Arc>>, + rpc_sender: Sender<(BlockNumber, GetProofOutput)>, +) { +} diff --git a/hdp/src/provider/starknet/types.rs b/hdp/src/provider/starknet/types.rs new file mode 100644 index 00000000..709c6901 --- /dev/null +++ b/hdp/src/provider/starknet/types.rs @@ -0,0 +1,73 @@ +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +use starknet_types_core::{felt::Felt, hash::StarkHash}; + +/// Codebase is from https://github.com/eqlabs/pathfinder/tree/ae81d84b7c4157891069bd02ef810a29b60a94e3 + +/// Holds the membership/non-membership of a contract and its associated +/// contract contract if the contract exists. +#[derive(Debug, Serialize, Deserialize)] +#[skip_serializing_none] +pub struct GetProofOutput { + /// The global state commitment for Starknet 0.11.0 blocks onwards, if + /// absent the hash of the first node in the + /// [contract_proof](GetProofOutput#contract_proof) is the global state + /// commitment. + state_commitment: Option, + /// Required to verify that the hash of the class commitment and the root of + /// the [contract_proof](GetProofOutput::contract_proof) matches the + /// [state_commitment](Self#state_commitment). Present only for Starknet + /// blocks 0.11.0 onwards. + class_commitment: Option, + + /// Membership / Non-membership proof for the queried contract + contract_proof: Vec, + + /// Additional contract data if it exists. + contract_data: Option, +} + +/// A node in a Starknet patricia-merkle trie. +/// +/// See pathfinders merkle-tree crate for more information. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub enum TrieNode { + Binary { left: Felt, right: Felt }, + Edge { child: Felt, path: [u8; 32] }, +} + +impl TrieNode { + pub fn hash(&self) -> Felt { + match self { + TrieNode::Binary { left, right } => H::hash(left, right), + TrieNode::Edge { child, path } => { + let mut length = [0; 32]; + // Safe as len() is guaranteed to be <= 251 + length[31] = path.len() as u8; + let path = Felt::from_bytes_be_slice(path); + + let length = Felt::from_bytes_be(&length); + H::hash(child, &path) + length + } + } + } +} + +/// Holds the data and proofs for a specific contract. +#[derive(Debug, Serialize, Deserialize)] +pub struct ContractData { + /// Required to verify the contract state hash to contract root calculation. + class_hash: Felt, + /// Required to verify the contract state hash to contract root calculation. + nonce: Felt, + + /// Root of the Contract state tree + root: Felt, + + /// This is currently just a constant = 0, however it might change in the + /// future. + contract_state_hash_version: Felt, + + /// The proofs associated with the queried storage values + storage_proofs: Vec>, +} From e21940be624f52fa6f7d13e320b8991a664d3621 Mon Sep 17 00:00:00 2001 From: Pia Date: Tue, 3 Sep 2024 15:10:58 +0900 Subject: [PATCH 3/6] wip --- hdp/src/provider/starknet/rpc.rs | 92 ++++++++++++++++++++++++++------ pathfinder.request.json | 14 +++++ 2 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 pathfinder.request.json diff --git a/hdp/src/provider/starknet/rpc.rs b/hdp/src/provider/starknet/rpc.rs index 2184b4d9..e81b60aa 100644 --- a/hdp/src/provider/starknet/rpc.rs +++ b/hdp/src/provider/starknet/rpc.rs @@ -8,17 +8,18 @@ use alloy::primitives::BlockNumber; use futures::future::join_all; use jsonrpsee::{ - core::{client::ClientT, BoxError, ClientError}, + core::{client::ClientT, BoxError}, http_client::{HttpClient, HttpClientBuilder}, rpc_params, }; -use reqwest::{Client, Url}; +use reqwest::Url; +use serde_json::json; use starknet_types_core::felt::Felt; use tokio::sync::{ mpsc::{self, Sender}, RwLock, }; -use tracing::debug; +use tracing::{debug, error}; use crate::provider::error::RpcProviderError; @@ -130,20 +131,35 @@ async fn pathfinder_get_proof( block_number: BlockNumber, storage_key: Option, ) -> Result { - match storage_key { - Some(key) => { - let params = rpc_params!["param1", "param2"]; - let response: String = provider.request("method_name", params).await?; - let get_proof_output: GetProofOutput = serde_json::from_str(&response)?; - Ok(get_proof_output) - } - None => { - let params = rpc_params!["param1", "param2"]; - let response: String = provider.request("method_name", params).await?; - let get_proof_output: GetProofOutput = serde_json::from_str(&response)?; - Ok(get_proof_output) - } + let mut keys = Vec::new(); + if let Some(key) = storage_key { + keys.push(format!("{}", key.to_hex_string())); } + + let request = json!({ + "jsonrpc": "2.0", + "method": "pathfinder_getProof", + "params": { + "block_id": "latest", + "contract_address": format!("{}", address.to_hex_string()), + "keys": keys + }, + "id": 0 + }); + + println!("req:{}", request); + + let response: serde_json::Value = provider + .request( + "pathfinder_getProof", + rpc_params![request["params"].clone()], + ) + .await?; + + println!("res:{}", response); + + let get_proof_output: GetProofOutput = serde_json::from_value(response["result"].clone())?; + Ok(get_proof_output) } async fn handle_proof_result( @@ -152,4 +168,48 @@ async fn handle_proof_result( blocks_map: Arc>>, rpc_sender: Sender<(BlockNumber, GetProofOutput)>, ) { + match proof { + Ok(proof) => { + blocks_map.write().await.insert(block_number); + rpc_sender.send((block_number, proof)).await.unwrap(); + } + Err(e) => { + error!("❗️❗️❗️ Error fetching proof: {:?}", e); + } + } +} +#[cfg(test)] +mod tests { + use core::str::FromStr; + + use super::*; + use reqwest::Url; + + + + fn test_provider() -> RpcProvider { + RpcProvider::new(Url::from_str(PATHFINDER_URL).unwrap(), 100) + } + + #[tokio::test] + async fn test_get_proof() { + let provider = test_provider(); + let proof = provider + .get_proofs( + [156600].to_vec(), + Felt::from_str( + "0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd", + ) + .unwrap(), + Some( + Felt::from_str( + "0x1", + ) + .unwrap(), + ), + ) + .await; + + println!("{:?}", proof); + } } diff --git a/pathfinder.request.json b/pathfinder.request.json new file mode 100644 index 00000000..cdfb351c --- /dev/null +++ b/pathfinder.request.json @@ -0,0 +1,14 @@ +❯ curl -s -X POST \ + -H 'Content-Type: application/json' \ + -d '{ + "jsonrpc": "2.0", + "method": "pathfinder_getProof", + "params": { + "block_id": "latest", + "contract_address": "0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd", + "keys": ["0x1"] + }, + "id": 0 + }' \ + https://pathfinder.sepolia.iosis.tech +{"jsonrpc":"2.0","result":{"class_commitment":"0x46c1a0374b8ccf8d928e62ef40974304732c8a28f10b2c494adfabfcff0fa0a","contract_data":null,"contract_proof":[{"binary":{"left":"0x1fce6ebc4ed28309974e4d5ecf9e51420ba5585d90110c130b8600ede80c5c0","right":"0x75fb62a61d1ffc4ef82df685c74a7292b34bd30fa7c68ff7b5f4774662ad61c"}},{"binary":{"left":"0x234737de2705b5c4b6511397cfbfd4a7be5e1039bb3750cbdcdda3233bb75df","right":"0x4593f0345afeff3ab53e34ef598ad41ac0c77823dbd1ef6f84af312ffb31996"}},{"binary":{"left":"0x271ff2593020872e524af8daa846983b7b043339fcef335890f6c7df7a9d889","right":"0x66cff3b63768084f84013ff15047adcaee3129e5b25d7373907e3ec33d3142f"}},{"binary":{"left":"0x7fe8dc7a63c3242e0dcca7c30083bdef80281cf4dcdc560271914921468a22b","right":"0x6a4c4de2a4248369f763d7051039c9166a052c87d02265c413cc2e985d13a7b"}},{"binary":{"left":"0x42cb837e41783f18d4b755c5ab9805cf978ab2968ed90f3a5ef7d2cca875782","right":"0x1940dc58b742c2ef3380f00705042bc8cede62574889bddf7794e00a3237d3"}},{"binary":{"left":"0x3b4567923933c70ea41388c0b7a417abe33b2be6c63502aa0498df43641067d","right":"0x1bfed7273176888d48091ca5cf9b86c18e0b46c19c4480e6085ed21fba2baa"}},{"binary":{"left":"0x6a7544e21d79895fef3ee3fca0a1e054e39d667d1b81db9178b7a365c246fa8","right":"0x7464f2a0dcfc72f24b3ab83aa27df75ff49c8a1a2cb6d6013dea24115e5a1a4"}},{"binary":{"left":"0x2b38c99a85f2a7d24cbc11776e7c60063e771d2a40ff779d7da788b515a10cc","right":"0x3c1de78e157fe6c9b9a17bc13c03aa6b96079c544ada06e4121295bcfb4df40"}},{"binary":{"left":"0x7b9b97aab2974de84a5c5a8c3a6dc5be6eea17e01edd78108d93ecb0b84384c","right":"0x343d11c95e7fe731f5b18581bd0d7880a52d5354e786fedb27e2755ed98ba4"}},{"binary":{"left":"0x520b92021697702ebcf7224412f6b836f3bbdef2a70d64f9c623ece3722959f","right":"0x76b5410380a8ef83218486d4e2889f987966f6149e917746b2f054eec154e23"}},{"binary":{"left":"0x272f761c0bb1b1d70a785b56c894dccd5a8cb54c57ca61a1fde1a35592c028e","right":"0x73b6378d6db93716a1e4998412332b56bda8fc422bf5e6090beb9640fe9c087"}},{"binary":{"left":"0x79781ee9e623c7191682931049148cf58187ca270aa5597cd54cad6a8b2e724","right":"0x3aae622e14c7e7932ca1739995b02333e17839009ce838fdee422e85bfdce1c"}},{"binary":{"left":"0x26bd7f3203f07c81053e59d589f77a4c543e7204190466c4070befd50e42fd1","right":"0x3e5e3061d0165c807ef5b01bb1fb52640b563e01e0d95a2147332cd531236d0"}},{"binary":{"left":"0x35bff569ae6378256a0f8edc16e11465b80c6df65d43f63db2de397255a37b","right":"0x7dee4b21e69cb6d8a0c8b9a02dbe3a7051db9e3227c8e5a4fe3a982d73e15b1"}},{"binary":{"left":"0x19095f7dfd2ad48be7993ae0ddf6cdf7edbe3f452c732ce1aacb6427508641d","right":"0x77f9c3d354e07acb48309d1e8480412878bce30b375255019a091ed16b204c1"}},{"binary":{"left":"0x18f2fd53fcef537df9e9198ffe6f1070c39944cd8ecb101d6f6fc18b4ad96a7","right":"0x544f935e562e1d83d5e0c9b58ab9b4e0697ce2f2bb198dd5392b04c5920bfdb"}},{"binary":{"left":"0x3d0cb13372330e94a75f435c1317747b03b5f9764ce19576f505ce251a9b8b2","right":"0x2e25083e3f2ffec2ee585973ffbf1a582592212ad43242234c13ff602385270"}},{"binary":{"left":"0xacbb7ead42ba37145b629bd63bb9d7f7b11715c8d2c4ac98d60c8b35372206","right":"0x581421ecef4b2058e07350602f60fd90ab9eb3422a5726849a1422d1a725b0a"}},{"binary":{"left":"0x25bc11ec36c9db342daa61f89176ae920ff7dde4ab1aa7786d307005a8b5f0c","right":"0x142db9370528b7ff388cc7a64437c2054aecea95cac1e8bed856b78104d0ab6"}},{"binary":{"left":"0x874891a64e16fe2a0ef32af13755e477c7d4d503f074426980d3a60448c245","right":"0x61835e9c88fe6010fe08337cd71ab13f2b189395a93bbfd4db66c060a58c835"}},{"binary":{"left":"0x4c8259021fbb82e40baaa003d3fe9cf6c109b2a49600b93aba5a22860de1d5d","right":"0x383b888ba52b75d69f4dd2bc3cb28fbac033a01e68c4b8f2862183aecbe4fd7"}},{"binary":{"left":"0x4ad807c717fddd60daf73b94c59a47f376aa0ac0a4e1f549e688f5da7e5e3ea","right":"0x271123d1041a65dc8989e2bfaa6f08d4bc735ef12d13b22ba2ea0811534c9cc"}},{"edge":{"child":"0x2c90ab8d4024644723029081b8fa75e909af50e19c8c3a146bb17ef00e52b3d","path":{"len":229,"value":"0x1"}}}],"state_commitment":"0x46407af434cc224b639c22aceea1df94df3f1b0f102b763a1f0610f824a3bd0"},"id":0}% From bc8d548a915ef3d4c36c1e2ce653aba6de4d851e Mon Sep 17 00:00:00 2001 From: Pia Date: Tue, 3 Sep 2024 21:23:36 +0900 Subject: [PATCH 4/6] works! --- Cargo.lock | 342 +------------------------- hdp/Cargo.toml | 1 - hdp/src/provider/error.rs | 6 + hdp/src/provider/starknet/provider.rs | 101 +++++++- hdp/src/provider/starknet/rpc.rs | 150 +++++++---- hdp/src/provider/starknet/types.rs | 23 +- 6 files changed, 228 insertions(+), 395 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5210da32..09c984d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -854,12 +854,6 @@ dependencies = [ "rustc_version 0.4.0", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "atty" version = "0.2.14" @@ -1218,12 +1212,6 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" -[[package]] -name = "cesu8" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" - [[package]] name = "cfg-if" version = "1.0.0" @@ -1347,16 +1335,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "combine" -version = "4.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" -dependencies = [ - "bytes", - "memchr", -] - [[package]] name = "const-fnv1a-hash" version = "1.1.0" @@ -2038,16 +2016,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" -[[package]] -name = "futures-timer" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" -dependencies = [ - "gloo-timers", - "send_wrapper 0.4.0", -] - [[package]] name = "futures-util" version = "0.3.30" @@ -2126,52 +2094,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "gloo-net" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06f627b1a58ca3d42b45d6104bf1e1a03799df472df00988b6ba21accc10580" -dependencies = [ - "futures-channel", - "futures-core", - "futures-sink", - "gloo-utils", - "http 1.1.0", - "js-sys", - "pin-project", - "serde", - "serde_json", - "thiserror", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - -[[package]] -name = "gloo-timers" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "gloo-utils" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa" -dependencies = [ - "js-sys", - "serde", - "serde_json", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "good_lp" version = "1.8.1" @@ -2212,25 +2134,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http 1.1.0", - "indexmap 2.2.6", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "half" version = "2.4.1" @@ -2271,7 +2174,6 @@ dependencies = [ "eth-trie-proofs", "futures", "itertools 0.10.5", - "jsonrpsee", "lazy_static", "regex", "reqwest 0.11.27", @@ -2437,7 +2339,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.26", + "h2", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -2460,7 +2362,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.6", "http 1.1.0", "http-body 1.0.0", "httparse", @@ -2485,24 +2386,6 @@ dependencies = [ "tokio-rustls 0.24.1", ] -[[package]] -name = "hyper-rustls" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" -dependencies = [ - "futures-util", - "http 1.1.0", - "hyper 1.3.1", - "hyper-util", - "log", - "rustls 0.23.10", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.26.0", - "tower-service", -] - [[package]] name = "hyper-tls" version = "0.5.0" @@ -2755,26 +2638,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "jni" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" -dependencies = [ - "cesu8", - "combine", - "jni-sys", - "log", - "thiserror", - "walkdir", -] - -[[package]] -name = "jni-sys" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" - [[package]] name = "js-sys" version = "0.3.69" @@ -2784,131 +2647,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpsee" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ec465b607a36dc5dd45d48b7689bc83f679f66a3ac6b6b21cc787a11e0f8685" -dependencies = [ - "jsonrpsee-client-transport", - "jsonrpsee-core", - "jsonrpsee-http-client", - "jsonrpsee-types", - "jsonrpsee-wasm-client", - "jsonrpsee-ws-client", -] - -[[package]] -name = "jsonrpsee-client-transport" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f0977f9c15694371b8024c35ab58ca043dbbf4b51ccb03db8858a021241df1" -dependencies = [ - "base64 0.22.0", - "futures-channel", - "futures-util", - "gloo-net", - "http 1.1.0", - "jsonrpsee-core", - "pin-project", - "rustls 0.23.10", - "rustls-pki-types", - "rustls-platform-verifier", - "soketto", - "thiserror", - "tokio", - "tokio-rustls 0.26.0", - "tokio-util", - "tracing", - "url", -] - -[[package]] -name = "jsonrpsee-core" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e942c55635fbf5dc421938b8558a8141c7e773720640f4f1dbe1f4164ca4e221" -dependencies = [ - "async-trait", - "bytes", - "futures-timer", - "futures-util", - "http 1.1.0", - "http-body 1.0.0", - "http-body-util", - "jsonrpsee-types", - "pin-project", - "rustc-hash 2.0.0", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-stream", - "tracing", - "wasm-bindgen-futures", -] - -[[package]] -name = "jsonrpsee-http-client" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33774602df12b68a2310b38a535733c477ca4a498751739f89fe8dbbb62ec4c" -dependencies = [ - "async-trait", - "base64 0.22.0", - "http-body 1.0.0", - "hyper 1.3.1", - "hyper-rustls 0.27.2", - "hyper-util", - "jsonrpsee-core", - "jsonrpsee-types", - "rustls 0.23.10", - "rustls-platform-verifier", - "serde", - "serde_json", - "thiserror", - "tokio", - "tower", - "tracing", - "url", -] - -[[package]] -name = "jsonrpsee-types" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b67d6e008164f027afbc2e7bb79662650158d26df200040282d2aa1cbb093b" -dependencies = [ - "http 1.1.0", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "jsonrpsee-wasm-client" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0470d0ae043ffcb0cd323797a631e637fb4b55fe3eaa6002934819458bba62a7" -dependencies = [ - "jsonrpsee-client-transport", - "jsonrpsee-core", - "jsonrpsee-types", -] - -[[package]] -name = "jsonrpsee-ws-client" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "992bf67d1132f88edf4a4f8cff474cf01abb2be203004a2b8e11c2b20795b99e" -dependencies = [ - "http 1.1.0", - "jsonrpsee-client-transport", - "jsonrpsee-core", - "jsonrpsee-types", - "url", -] - [[package]] name = "jsonwebtoken" version = "9.3.0" @@ -3862,11 +3600,11 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2 0.3.26", + "h2", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-rustls 0.24.2", + "hyper-rustls", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -4011,12 +3749,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-hash" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" - [[package]] name = "rustc-hex" version = "2.1.0" @@ -4072,7 +3804,6 @@ version = "0.23.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" dependencies = [ - "log", "once_cell", "ring", "rustls-pki-types", @@ -4081,19 +3812,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-native-certs" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04182dffc9091a404e0fc069ea5cd60e5b866c3adf881eff99a32d048242dffa" -dependencies = [ - "openssl-probe", - "rustls-pemfile 2.1.2", - "rustls-pki-types", - "schannel", - "security-framework", -] - [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -4119,33 +3837,6 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" -[[package]] -name = "rustls-platform-verifier" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93bda3f493b9abe5b93b3e7e3ecde0df292f2bd28c0296b90586ee0055ff5123" -dependencies = [ - "core-foundation", - "core-foundation-sys", - "jni", - "log", - "once_cell", - "rustls 0.23.10", - "rustls-native-certs", - "rustls-platform-verifier-android", - "rustls-webpki 0.102.4", - "security-framework", - "security-framework-sys", - "webpki-roots 0.26.3", - "winapi", -] - -[[package]] -name = "rustls-platform-verifier-android" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" - [[package]] name = "rustls-webpki" version = "0.101.7" @@ -4203,7 +3894,7 @@ dependencies = [ "log", "oorandom", "parking_lot 0.11.2", - "rustc-hash 1.1.0", + "rustc-hash", "salsa-macros", "smallvec", ] @@ -4324,7 +4015,6 @@ dependencies = [ "core-foundation", "core-foundation-sys", "libc", - "num-bigint", "security-framework-sys", ] @@ -4362,12 +4052,6 @@ dependencies = [ "pest", ] -[[package]] -name = "send_wrapper" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" - [[package]] name = "send_wrapper" version = "0.6.0" @@ -4640,21 +4324,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "soketto" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37468c595637c10857701c990f93a40ce0e357cedb0953d1c26c8d8027f9bb53" -dependencies = [ - "base64 0.22.0", - "bytes", - "futures", - "httparse", - "log", - "rand", - "sha1", -] - [[package]] name = "spin" version = "0.9.8" @@ -5223,7 +4892,6 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -5849,7 +5517,7 @@ dependencies = [ "log", "pharos", "rustc_version 0.4.0", - "send_wrapper 0.6.0", + "send_wrapper", "thiserror", "wasm-bindgen", "wasm-bindgen-futures", diff --git a/hdp/Cargo.toml b/hdp/Cargo.toml index e9ef6a42..a4baafff 100644 --- a/hdp/Cargo.toml +++ b/hdp/Cargo.toml @@ -34,7 +34,6 @@ reqwest = { workspace = true } lazy_static = { workspace = true } eth-trie-proofs = { workspace = true } itertools = { workspace = true } -jsonrpsee = { version = "0.24.3", features = ["http-client", "client"] } [features] default = [] diff --git a/hdp/src/provider/error.rs b/hdp/src/provider/error.rs index f55377b3..23678940 100644 --- a/hdp/src/provider/error.rs +++ b/hdp/src/provider/error.rs @@ -45,4 +45,10 @@ pub enum RpcProviderError { alloy::rpc::types::EIP1186AccountProofResponse, )>, ), + + #[error("Failed to fetch proofs: {0}")] + ReqwestError(#[from] reqwest::Error), + + #[error("Failed to parse response: {0}")] + SerdeJsonError(#[from] serde_json::Error), } diff --git a/hdp/src/provider/starknet/provider.rs b/hdp/src/provider/starknet/provider.rs index d322fa9f..7b03d600 100644 --- a/hdp/src/provider/starknet/provider.rs +++ b/hdp/src/provider/starknet/provider.rs @@ -1,12 +1,23 @@ -use crate::provider::{config::ProviderConfig, indexer::Indexer}; +use std::{collections::HashMap, time::Instant}; -use super::rpc::RpcProvider; +use alloy::primitives::BlockNumber; +use itertools::Itertools; +use starknet_types_core::felt::Felt; +use tracing::info; + +use crate::provider::{config::ProviderConfig, error::ProviderError, indexer::Indexer}; + +use super::{rpc::RpcProvider, types::GetProofOutput}; + +type AccountProofsResult = Result, ProviderError>; +type StorageProofsResult = Result, ProviderError>; pub struct StarknetProvider { /// Account and storage trie provider pub(crate) rpc_provider: RpcProvider, /// Header provider - pub(crate) header_provider: Indexer, + //TODO: indexer is not supported for starknet yet + pub(crate) _header_provider: Indexer, } #[cfg(feature = "test_utils")] @@ -22,7 +33,89 @@ impl StarknetProvider { let indexer = Indexer::new(config.chain_id); Self { rpc_provider, - header_provider: indexer, + _header_provider: indexer, + } + } + + /// Fetches the account proofs for the given block range. + /// The account proofs are fetched from the RPC provider. + /// + /// Return: + /// - Account proofs mapped by block number + pub async fn get_range_of_account_proofs( + &self, + from_block: BlockNumber, + to_block: BlockNumber, + increment: u64, + address: Felt, + ) -> AccountProofsResult { + let start_fetch = Instant::now(); + + let target_blocks_batch: Vec> = + self._chunk_block_range(from_block, to_block, increment); + + let mut fetched_accounts_proofs_with_blocks_map = HashMap::new(); + for target_blocks in target_blocks_batch { + fetched_accounts_proofs_with_blocks_map.extend( + self.rpc_provider + .get_account_proofs(target_blocks, address) + .await?, + ); } + + let duration = start_fetch.elapsed(); + info!("time taken (Account Proofs Fetch): {:?}", duration); + + Ok(fetched_accounts_proofs_with_blocks_map) + } + + /// Fetches the storage proofs for the given block range. + /// The storage proofs are fetched from the RPC provider. + /// + /// Return: + /// - Storage proofs mapped by block number + pub async fn get_range_of_storage_proofs( + &self, + from_block: BlockNumber, + to_block: BlockNumber, + increment: u64, + address: Felt, + storage_slot: Felt, + ) -> StorageProofsResult { + let start_fetch = Instant::now(); + + let target_blocks_batch: Vec> = + self._chunk_block_range(from_block, to_block, increment); + + let mut processed_accounts = HashMap::new(); + for target_blocks in target_blocks_batch { + processed_accounts.extend( + self.rpc_provider + .get_storage_proofs(target_blocks, address, storage_slot) + .await?, + ); + } + + let duration = start_fetch.elapsed(); + info!("time taken (Storage Proofs Fetch): {:?}", duration); + + Ok(processed_accounts) + } + + /// Chunks the block range into smaller ranges of 800 blocks. + /// This is to avoid fetching too many blocks at once from the RPC provider. + /// This is meant to use with data lake definition, which have sequential block numbers + pub(crate) fn _chunk_block_range( + &self, + from_block: BlockNumber, + to_block: BlockNumber, + increment: u64, + ) -> Vec> { + (from_block..=to_block) + .step_by(increment as usize) + .chunks(800) + .into_iter() + .map(|chunk| chunk.collect()) + .collect() } } diff --git a/hdp/src/provider/starknet/rpc.rs b/hdp/src/provider/starknet/rpc.rs index e81b60aa..a65b3ecb 100644 --- a/hdp/src/provider/starknet/rpc.rs +++ b/hdp/src/provider/starknet/rpc.rs @@ -1,18 +1,12 @@ +use alloy::primitives::BlockNumber; use std::{ collections::{HashMap, HashSet}, sync::Arc, time::Instant, }; -use alloy::primitives::BlockNumber; - use futures::future::join_all; -use jsonrpsee::{ - core::{client::ClientT, BoxError}, - http_client::{HttpClient, HttpClientBuilder}, - rpc_params, -}; -use reqwest::Url; +use reqwest::{Client, Url}; use serde_json::json; use starknet_types_core::felt::Felt; use tokio::sync::{ @@ -27,17 +21,39 @@ use super::types::GetProofOutput; /// !Note: have to use pathfinder node as we need `pathfinder_getProof` pub struct RpcProvider { - client: HttpClient, + client: reqwest::Client, + url: Url, chunk_size: u64, } impl RpcProvider { pub fn new(rpc_url: Url, chunk_size: u64) -> Self { - let client = HttpClientBuilder::default().build(rpc_url).unwrap(); - Self { client, chunk_size } + Self { + client: Client::new(), + url: rpc_url, + chunk_size, + } + } + + /// Get account with proof in given vector of blocks + pub async fn get_account_proofs( + &self, + blocks: Vec, + address: Felt, + ) -> Result, RpcProviderError> { + self.get_proofs(blocks, address, None).await } - pub async fn get_account_proofs(&self, blocks: Vec, address: Felt) {} + /// Get storage with proof in given vector of blocks and slot + pub async fn get_storage_proofs( + &self, + block_range: Vec, + address: Felt, + storage_key: Felt, + ) -> Result, RpcProviderError> { + self.get_proofs(block_range, address, Some(storage_key)) + .await + } async fn get_proofs( &self, @@ -69,6 +85,7 @@ impl RpcProvider { let chunk_size = self.chunk_size; let provider_clone = self.client.clone(); let target_blocks_length = blocks.len(); + let url = self.url.clone(); debug!( "fetching proofs for {}, with chunk size: {}", @@ -99,9 +116,11 @@ impl RpcProvider { let fetched_blocks_clone = blocks_map.clone(); let rpc_sender = rpc_sender.clone(); let provider_clone = provider_clone.clone(); + let url = url.clone(); async move { let proof = pathfinder_get_proof( &provider_clone, + url, address, block_number, storage_key, @@ -126,44 +145,37 @@ impl RpcProvider { /// Fetches proof (account or storage) for a given block number async fn pathfinder_get_proof( - provider: &HttpClient, + provider: &reqwest::Client, + url: Url, address: Felt, block_number: BlockNumber, storage_key: Option, -) -> Result { +) -> Result { let mut keys = Vec::new(); if let Some(key) = storage_key { - keys.push(format!("{}", key.to_hex_string())); + keys.push(key.to_hex_string()); } let request = json!({ "jsonrpc": "2.0", + "id": "0", "method": "pathfinder_getProof", "params": { - "block_id": "latest", + "block_id": {"block_number": block_number}, "contract_address": format!("{}", address.to_hex_string()), "keys": keys - }, - "id": 0 + } }); - println!("req:{}", request); - - let response: serde_json::Value = provider - .request( - "pathfinder_getProof", - rpc_params![request["params"].clone()], - ) - .await?; - - println!("res:{}", response); - - let get_proof_output: GetProofOutput = serde_json::from_value(response["result"].clone())?; + let response = provider.post(url).json(&request).send().await?; + let response_json = + serde_json::from_str::(&response.text().await?)?["result"].clone(); + let get_proof_output: GetProofOutput = serde_json::from_value(response_json)?; Ok(get_proof_output) } async fn handle_proof_result( - proof: Result, + proof: Result, block_number: BlockNumber, blocks_map: Arc>>, rpc_sender: Sender<(BlockNumber, GetProofOutput)>, @@ -185,31 +197,77 @@ mod tests { use super::*; use reqwest::Url; - + const PATHFINDER_URL: &str = "https://pathfinder.sepolia.iosis.tech/"; fn test_provider() -> RpcProvider { RpcProvider::new(Url::from_str(PATHFINDER_URL).unwrap(), 100) } #[tokio::test] - async fn test_get_proof() { + async fn test_get_100_range_storage_with_proof() { + // TODO: why the storage proof returns same value as account proof + let target_block_start = 156600; + let target_block_end = 156700; + let target_block_range = (target_block_start..=target_block_end).collect::>(); + let provider = test_provider(); + let proof = provider + .get_storage_proofs( + target_block_range.clone(), + Felt::from_str("0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd") + .unwrap(), + Felt::from_str("0x1").unwrap(), + ) + .await + .unwrap(); + + assert_eq!(proof.len(), target_block_range.len()); + let output = proof.get(&target_block_start).unwrap(); + println!("Proof: {:?}", output); + assert_eq!( + output.state_commitment.unwrap(), + Felt::from_str("0x26da0f5f0849cf69b4872ef5dced3ec68ce28c5e3f53207280113abb7feb158") + .unwrap() + ); + + assert_eq!( + output.class_commitment.unwrap(), + Felt::from_str("0x46c1a0374b8ccf8d928e62ef40974304732c8a28f10b2c494adfabfcff0fa0a") + .unwrap() + ); + + assert!(output.contract_data.is_none()); + } + + #[tokio::test] + async fn test_get_100_range_account_with_proof() { + let target_block_start = 156600; + let target_block_end = 156700; + let target_block_range = (target_block_start..=target_block_end).collect::>(); let provider = test_provider(); let proof = provider - .get_proofs( - [156600].to_vec(), - Felt::from_str( - "0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd", - ) - .unwrap(), - Some( - Felt::from_str( - "0x1", - ) + .get_account_proofs( + target_block_range.clone(), + Felt::from_str("0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd") .unwrap(), - ), ) - .await; + .await + .unwrap(); + + assert_eq!(proof.len(), target_block_range.len()); + let output = proof.get(&target_block_start).unwrap(); + println!("Proof: {:?}", output); + assert_eq!( + output.state_commitment.unwrap(), + Felt::from_str("0x26da0f5f0849cf69b4872ef5dced3ec68ce28c5e3f53207280113abb7feb158") + .unwrap() + ); + + assert_eq!( + output.class_commitment.unwrap(), + Felt::from_str("0x46c1a0374b8ccf8d928e62ef40974304732c8a28f10b2c494adfabfcff0fa0a") + .unwrap() + ); - println!("{:?}", proof); + assert!(output.contract_data.is_none()); } } diff --git a/hdp/src/provider/starknet/types.rs b/hdp/src/provider/starknet/types.rs index 709c6901..3ff53a26 100644 --- a/hdp/src/provider/starknet/types.rs +++ b/hdp/src/provider/starknet/types.rs @@ -13,18 +13,18 @@ pub struct GetProofOutput { /// absent the hash of the first node in the /// [contract_proof](GetProofOutput#contract_proof) is the global state /// commitment. - state_commitment: Option, + pub state_commitment: Option, /// Required to verify that the hash of the class commitment and the root of /// the [contract_proof](GetProofOutput::contract_proof) matches the /// [state_commitment](Self#state_commitment). Present only for Starknet /// blocks 0.11.0 onwards. - class_commitment: Option, + pub class_commitment: Option, /// Membership / Non-membership proof for the queried contract - contract_proof: Vec, + pub contract_proof: Vec, /// Additional contract data if it exists. - contract_data: Option, + pub contract_data: Option, } /// A node in a Starknet patricia-merkle trie. @@ -32,8 +32,16 @@ pub struct GetProofOutput { /// See pathfinders merkle-tree crate for more information. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum TrieNode { + #[serde(rename = "binary")] Binary { left: Felt, right: Felt }, - Edge { child: Felt, path: [u8; 32] }, + #[serde(rename = "edge")] + Edge { child: Felt, path: Path }, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Path { + len: u64, + value: String, } impl TrieNode { @@ -41,12 +49,13 @@ impl TrieNode { match self { TrieNode::Binary { left, right } => H::hash(left, right), TrieNode::Edge { child, path } => { + let bytes: [u8; 32] = path.value.as_bytes().try_into().unwrap(); let mut length = [0; 32]; // Safe as len() is guaranteed to be <= 251 - length[31] = path.len() as u8; - let path = Felt::from_bytes_be_slice(path); + length[31] = bytes.len() as u8; let length = Felt::from_bytes_be(&length); + let path = Felt::from_bytes_be(&bytes); H::hash(child, &path) + length } } From 7a5091702d12a266bbb71b617f29096b214ef2b5 Mon Sep 17 00:00:00 2001 From: Pia Date: Tue, 3 Sep 2024 21:25:55 +0900 Subject: [PATCH 5/6] rm :dummy file --- pathfinder.request.json | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 pathfinder.request.json diff --git a/pathfinder.request.json b/pathfinder.request.json deleted file mode 100644 index cdfb351c..00000000 --- a/pathfinder.request.json +++ /dev/null @@ -1,14 +0,0 @@ -❯ curl -s -X POST \ - -H 'Content-Type: application/json' \ - -d '{ - "jsonrpc": "2.0", - "method": "pathfinder_getProof", - "params": { - "block_id": "latest", - "contract_address": "0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd", - "keys": ["0x1"] - }, - "id": 0 - }' \ - https://pathfinder.sepolia.iosis.tech -{"jsonrpc":"2.0","result":{"class_commitment":"0x46c1a0374b8ccf8d928e62ef40974304732c8a28f10b2c494adfabfcff0fa0a","contract_data":null,"contract_proof":[{"binary":{"left":"0x1fce6ebc4ed28309974e4d5ecf9e51420ba5585d90110c130b8600ede80c5c0","right":"0x75fb62a61d1ffc4ef82df685c74a7292b34bd30fa7c68ff7b5f4774662ad61c"}},{"binary":{"left":"0x234737de2705b5c4b6511397cfbfd4a7be5e1039bb3750cbdcdda3233bb75df","right":"0x4593f0345afeff3ab53e34ef598ad41ac0c77823dbd1ef6f84af312ffb31996"}},{"binary":{"left":"0x271ff2593020872e524af8daa846983b7b043339fcef335890f6c7df7a9d889","right":"0x66cff3b63768084f84013ff15047adcaee3129e5b25d7373907e3ec33d3142f"}},{"binary":{"left":"0x7fe8dc7a63c3242e0dcca7c30083bdef80281cf4dcdc560271914921468a22b","right":"0x6a4c4de2a4248369f763d7051039c9166a052c87d02265c413cc2e985d13a7b"}},{"binary":{"left":"0x42cb837e41783f18d4b755c5ab9805cf978ab2968ed90f3a5ef7d2cca875782","right":"0x1940dc58b742c2ef3380f00705042bc8cede62574889bddf7794e00a3237d3"}},{"binary":{"left":"0x3b4567923933c70ea41388c0b7a417abe33b2be6c63502aa0498df43641067d","right":"0x1bfed7273176888d48091ca5cf9b86c18e0b46c19c4480e6085ed21fba2baa"}},{"binary":{"left":"0x6a7544e21d79895fef3ee3fca0a1e054e39d667d1b81db9178b7a365c246fa8","right":"0x7464f2a0dcfc72f24b3ab83aa27df75ff49c8a1a2cb6d6013dea24115e5a1a4"}},{"binary":{"left":"0x2b38c99a85f2a7d24cbc11776e7c60063e771d2a40ff779d7da788b515a10cc","right":"0x3c1de78e157fe6c9b9a17bc13c03aa6b96079c544ada06e4121295bcfb4df40"}},{"binary":{"left":"0x7b9b97aab2974de84a5c5a8c3a6dc5be6eea17e01edd78108d93ecb0b84384c","right":"0x343d11c95e7fe731f5b18581bd0d7880a52d5354e786fedb27e2755ed98ba4"}},{"binary":{"left":"0x520b92021697702ebcf7224412f6b836f3bbdef2a70d64f9c623ece3722959f","right":"0x76b5410380a8ef83218486d4e2889f987966f6149e917746b2f054eec154e23"}},{"binary":{"left":"0x272f761c0bb1b1d70a785b56c894dccd5a8cb54c57ca61a1fde1a35592c028e","right":"0x73b6378d6db93716a1e4998412332b56bda8fc422bf5e6090beb9640fe9c087"}},{"binary":{"left":"0x79781ee9e623c7191682931049148cf58187ca270aa5597cd54cad6a8b2e724","right":"0x3aae622e14c7e7932ca1739995b02333e17839009ce838fdee422e85bfdce1c"}},{"binary":{"left":"0x26bd7f3203f07c81053e59d589f77a4c543e7204190466c4070befd50e42fd1","right":"0x3e5e3061d0165c807ef5b01bb1fb52640b563e01e0d95a2147332cd531236d0"}},{"binary":{"left":"0x35bff569ae6378256a0f8edc16e11465b80c6df65d43f63db2de397255a37b","right":"0x7dee4b21e69cb6d8a0c8b9a02dbe3a7051db9e3227c8e5a4fe3a982d73e15b1"}},{"binary":{"left":"0x19095f7dfd2ad48be7993ae0ddf6cdf7edbe3f452c732ce1aacb6427508641d","right":"0x77f9c3d354e07acb48309d1e8480412878bce30b375255019a091ed16b204c1"}},{"binary":{"left":"0x18f2fd53fcef537df9e9198ffe6f1070c39944cd8ecb101d6f6fc18b4ad96a7","right":"0x544f935e562e1d83d5e0c9b58ab9b4e0697ce2f2bb198dd5392b04c5920bfdb"}},{"binary":{"left":"0x3d0cb13372330e94a75f435c1317747b03b5f9764ce19576f505ce251a9b8b2","right":"0x2e25083e3f2ffec2ee585973ffbf1a582592212ad43242234c13ff602385270"}},{"binary":{"left":"0xacbb7ead42ba37145b629bd63bb9d7f7b11715c8d2c4ac98d60c8b35372206","right":"0x581421ecef4b2058e07350602f60fd90ab9eb3422a5726849a1422d1a725b0a"}},{"binary":{"left":"0x25bc11ec36c9db342daa61f89176ae920ff7dde4ab1aa7786d307005a8b5f0c","right":"0x142db9370528b7ff388cc7a64437c2054aecea95cac1e8bed856b78104d0ab6"}},{"binary":{"left":"0x874891a64e16fe2a0ef32af13755e477c7d4d503f074426980d3a60448c245","right":"0x61835e9c88fe6010fe08337cd71ab13f2b189395a93bbfd4db66c060a58c835"}},{"binary":{"left":"0x4c8259021fbb82e40baaa003d3fe9cf6c109b2a49600b93aba5a22860de1d5d","right":"0x383b888ba52b75d69f4dd2bc3cb28fbac033a01e68c4b8f2862183aecbe4fd7"}},{"binary":{"left":"0x4ad807c717fddd60daf73b94c59a47f376aa0ac0a4e1f549e688f5da7e5e3ea","right":"0x271123d1041a65dc8989e2bfaa6f08d4bc735ef12d13b22ba2ea0811534c9cc"}},{"edge":{"child":"0x2c90ab8d4024644723029081b8fa75e909af50e19c8c3a146bb17ef00e52b3d","path":{"len":229,"value":"0x1"}}}],"state_commitment":"0x46407af434cc224b639c22aceea1df94df3f1b0f102b763a1f0610f824a3bd0"},"id":0}% From 4a0949dd713f07efdb93b9a05eea0958ca9a44be Mon Sep 17 00:00:00 2001 From: Pia Date: Wed, 4 Sep 2024 11:53:57 +0900 Subject: [PATCH 6/6] chore: minor edit --- .env.example | 2 ++ hdp/src/provider/starknet/rpc.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 6ade5e55..cf06a8d3 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,8 @@ RPC_URL_ETHEREUM_SEPOLIA=https://goerli.infura.io/v3/your-infura-api-key # this value is optional RPC_CHUNK_SIZE_ETHEREUM_SEPOLIA=2000 +RPC_URL_STARKNET_SEPOLIA=# if it's starknet make sure to use pathfinder + # Optional DRY_RUN_CAIRO_PATH= # path for dry run cairo SOUND_RUN_CAIRO_PATH= # path for sound run cairo diff --git a/hdp/src/provider/starknet/rpc.rs b/hdp/src/provider/starknet/rpc.rs index a65b3ecb..542f65ac 100644 --- a/hdp/src/provider/starknet/rpc.rs +++ b/hdp/src/provider/starknet/rpc.rs @@ -215,7 +215,7 @@ mod tests { target_block_range.clone(), Felt::from_str("0x23371b227eaecd8e8920cd429d2cd0f3fee6abaacca08d3ab82a7cdd") .unwrap(), - Felt::from_str("0x1").unwrap(), + Felt::from_str("0x2").unwrap(), ) .await .unwrap(); @@ -229,6 +229,8 @@ mod tests { .unwrap() ); + assert_eq!(output.contract_proof.len(), 23); + assert_eq!( output.class_commitment.unwrap(), Felt::from_str("0x46c1a0374b8ccf8d928e62ef40974304732c8a28f10b2c494adfabfcff0fa0a") @@ -261,6 +263,7 @@ mod tests { Felt::from_str("0x26da0f5f0849cf69b4872ef5dced3ec68ce28c5e3f53207280113abb7feb158") .unwrap() ); + assert_eq!(output.contract_proof.len(), 23); assert_eq!( output.class_commitment.unwrap(),