From a96b8d9e52771e839562bd1c5be49b30924d300b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 21 Oct 2024 18:49:42 -0300 Subject: [PATCH 01/31] Sort dependencies --- Cargo.toml | 10 +++++++--- rpc-state-reader/Cargo.toml | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c665f6a..27b2c06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,13 +9,17 @@ resolver = "2" [workspace.dependencies] thiserror = "1.0.32" starknet-types-core = "0.1.6" -starknet_api = { git = "https://github.com/lambdaclass/sequencer", rev = "693cd41a893c7de71682b59686bcd0c99a27c9e0"} -blockifier = { git = "https://github.com/lambdaclass/sequencer", rev = "693cd41a893c7de71682b59686bcd0c99a27c9e0"} -cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "355c250f37cf0977ef2776b1aae2cb2e87c9da3d" } tracing = "0.1" serde_json = "1.0.116" serde_with = "3.9.0" serde = "1.0.197" +cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "355c250f37cf0977ef2776b1aae2cb2e87c9da3d" } + +# Sequencer Dependencies +starknet_api = { git = "https://github.com/lambdaclass/sequencer", rev = "7aefd2cfd6071fff2c702811a47407eb14914aca"} +blockifier = { git = "https://github.com/lambdaclass/sequencer", rev = "7aefd2cfd6071fff2c702811a47407eb14914aca"} +starknet_gateway = { git = "https://github.com/lambdaclass/sequencer", rev = "7aefd2cfd6071fff2c702811a47407eb14914aca"} + [patch.'https://github.com/lambdaclass/cairo_native'] cairo-native = { git = 'https://github.com/lambdaclass//cairo_native.git', rev = "355c250f37cf0977ef2776b1aae2cb2e87c9da3d" } diff --git a/rpc-state-reader/Cargo.toml b/rpc-state-reader/Cargo.toml index b65893d..43e71c2 100644 --- a/rpc-state-reader/Cargo.toml +++ b/rpc-state-reader/Cargo.toml @@ -27,6 +27,7 @@ flate2 = "1.0.25" dotenv = "0.15.0" cairo-vm = "1.0.0-rc5" blockifier = { workspace = true } +starknet_gateway = { workspace = true } tracing = { workspace = true } [dev-dependencies] From d1f590d21e3413cd361ea89d7857c3087cb08df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 21 Oct 2024 18:49:57 -0300 Subject: [PATCH 02/31] Reimplement reader with sequencer as inner --- rpc-state-reader/src/lib.rs | 1 + rpc-state-reader/src/reader.rs | 115 +++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 rpc-state-reader/src/reader.rs diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index 0cf55e0..65a5079 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -1,3 +1,4 @@ +pub mod reader; pub mod rpc_state; pub mod rpc_state_errors; pub mod utils; diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs new file mode 100644 index 0000000..dc6fd8f --- /dev/null +++ b/rpc-state-reader/src/reader.rs @@ -0,0 +1,115 @@ +use std::sync::Arc; + +use blockifier::{ + execution::contract_class::{ + ContractClass, ContractClassV0, ContractClassV0Inner, NativeContractClassV1, + }, + state::state_api::{StateReader, StateResult}, +}; +use cairo_vm::types::program::Program; +use starknet::core::types::ContractClass as SNContractClass; +use starknet_api::{ + block::BlockNumber, + core::{ClassHash, CompiledClassHash, ContractAddress}, + state::StorageKey, +}; +use starknet_gateway::{ + config::RpcStateReaderConfig, errors::serde_err_to_state_err, + rpc_state_reader::RpcStateReader as GatewayRpcStateReader, +}; +use ureq::json; + +use crate::utils; + +pub struct RpcStateReader { + inner: GatewayRpcStateReader, +} + +impl RpcStateReader { + pub fn from_number(config: &RpcStateReaderConfig, block_number: BlockNumber) -> Self { + Self { + inner: GatewayRpcStateReader::from_number(config, block_number), + } + } + + pub fn get_contract_class(&self, class_hash: ClassHash) -> StateResult { + let params = json!({ + "block_id": self.inner.block_id, + "class_hash": class_hash.to_string(), + }); + + serde_json::from_value( + self.inner + .send_rpc_request("starknet_getClass", params.clone())?, + ) + .map_err(serde_err_to_state_err) + } +} + +impl StateReader for RpcStateReader { + fn get_storage_at( + &self, + contract_address: ContractAddress, + key: StorageKey, + ) -> StateResult { + self.inner.get_storage_at(contract_address, key) + } + + fn get_nonce_at( + &self, + contract_address: ContractAddress, + ) -> StateResult { + self.inner.get_nonce_at(contract_address) + } + + fn get_class_hash_at(&self, contract_address: ContractAddress) -> StateResult { + self.inner.get_class_hash_at(contract_address) + } + + fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + Ok(match self.get_contract_class(class_hash)? { + SNContractClass::Legacy(compressed_legacy_cc) => { + let as_str = utils::decode_reader(compressed_legacy_cc.program).unwrap(); + let program = Program::from_bytes(as_str.as_bytes(), None).unwrap(); + let entry_points_by_type = utils::map_entry_points_by_type_legacy( + compressed_legacy_cc.entry_points_by_type, + ); + let inner = Arc::new(ContractClassV0Inner { + program, + entry_points_by_type, + }); + ContractClass::V0(ContractClassV0(inner)) + } + SNContractClass::Sierra(flattened_sierra_cc) => { + let middle_sierra: utils::MiddleSierraContractClass = { + let v = serde_json::to_value(flattened_sierra_cc).unwrap(); + serde_json::from_value(v).unwrap() + }; + let sierra_cc = cairo_lang_starknet_classes::contract_class::ContractClass { + sierra_program: middle_sierra.sierra_program, + contract_class_version: middle_sierra.contract_class_version, + entry_points_by_type: middle_sierra.entry_points_by_type, + sierra_program_debug_info: None, + abi: None, + }; + + if cfg!(feature = "only_casm") { + let casm_cc = + cairo_lang_starknet_classes::casm_contract_class::CasmContractClass::from_contract_class(sierra_cc, false, usize::MAX).unwrap(); + ContractClass::V1(casm_cc.try_into().unwrap()) + } else { + let program = sierra_cc.extract_sierra_program().unwrap(); + let executor = utils::get_native_executor(program, class_hash); + + ContractClass::V1Native( + NativeContractClassV1::new(executor, sierra_cc).unwrap(), + ) + } + } + }) + } + + fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult { + self.inner.get_compiled_class_hash(class_hash) + } +} From 695751ab352feb596e0a980216cd2f7711a7bc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 21 Oct 2024 18:51:45 -0300 Subject: [PATCH 03/31] Update lock --- Cargo.lock | 2394 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 2238 insertions(+), 156 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b87611..68ef68c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,16 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "addr2line" version = "0.24.2" @@ -121,9 +131,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95" [[package]] name = "aquamarine" @@ -136,7 +146,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -167,7 +177,7 @@ dependencies = [ "ark-serialize", "ark-std", "derivative", - "digest", + "digest 0.10.7", "itertools 0.10.5", "num-bigint", "num-traits 0.2.19", @@ -242,7 +252,7 @@ checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ "ark-serialize-derive", "ark-std", - "digest", + "digest 0.10.7", "num-bigint", ] @@ -288,6 +298,15 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener", +] + [[package]] name = "async-trait" version = "0.1.83" @@ -296,7 +315,18 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", +] + +[[package]] +name = "async_io_stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" +dependencies = [ + "futures", + "pharos", + "rustc_version", ] [[package]] @@ -307,7 +337,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -316,6 +346,55 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.74" @@ -361,6 +440,21 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +dependencies = [ + "serde", +] + [[package]] name = "bigdecimal" version = "0.3.1" @@ -373,6 +467,15 @@ dependencies = [ "serde", ] +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bincode" version = "2.0.0-rc.3" @@ -382,6 +485,26 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.82", +] + [[package]] name = "bindgen" version = "0.69.5" @@ -401,7 +524,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.79", + "syn 2.0.82", "which", ] @@ -422,7 +545,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -464,6 +587,15 @@ dependencies = [ "wyz", ] +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -476,7 +608,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=693cd41a893c7de71682b59686bcd0c99a27c9e0#693cd41a893c7de71682b59686bcd0c99a27c9e0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" dependencies = [ "anyhow", "ark-ec", @@ -503,6 +635,8 @@ dependencies = [ "papyrus_config", "paste", "phf", + "rand", + "rstest", "serde", "serde_json", "sha2", @@ -518,6 +652,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "sha2", + "tinyvec", +] + [[package]] name = "bstr" version = "1.10.0" @@ -548,9 +692,12 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" +dependencies = [ + "serde", +] [[package]] name = "bzip2" @@ -804,7 +951,7 @@ checksum = "d72f17373740f242d6995e896b9195c2cedff7e8b14e496afdd16b405039d1fb" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1201,7 +1348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58363ad8065ed891e3b14a8191b707677c7c7cb5b9d10030822506786d8d8108" dependencies = [ "anyhow", - "bincode", + "bincode 2.0.0-rc.3", "bitvec", "generic-array", "hashbrown 0.14.5", @@ -1225,6 +1372,38 @@ dependencies = [ "zip", ] +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "caseless" version = "0.2.1" @@ -1237,9 +1416,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.28" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ "jobserver", "libc", @@ -1326,7 +1505,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1335,6 +1514,58 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "coins-bip32" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" +dependencies = [ + "bs58", + "coins-core", + "digest 0.10.7", + "hmac", + "k256", + "serde", + "sha2", + "thiserror", +] + +[[package]] +name = "coins-bip39" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" +dependencies = [ + "bitvec", + "coins-bip32", + "hmac", + "once_cell", + "pbkdf2 0.12.2", + "rand", + "sha2", + "thiserror", +] + +[[package]] +name = "coins-core" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" +dependencies = [ + "base64 0.21.7", + "bech32", + "bs58", + "digest 0.10.7", + "generic-array", + "hex", + "ripemd", + "serde", + "serde_derive", + "sha2", + "sha3", + "thiserror", +] + [[package]] name = "colorchoice" version = "1.0.2" @@ -1374,6 +1605,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" +[[package]] +name = "const-hex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0121754e84117e65f9d90648ee6aa4882a6e63110307ab73967a4c5e7e69e586" +dependencies = [ + "cfg-if", + "cpufeatures", + "hex", + "proptest", + "serde", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -1562,7 +1806,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1584,7 +1828,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1613,6 +1857,12 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + [[package]] name = "der" version = "0.7.9" @@ -1663,7 +1913,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1673,7 +1923,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1686,7 +1936,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1710,18 +1960,36 @@ dependencies = [ "nu-ansi-term", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", + "block-buffer 0.10.4", "const-oid", "crypto-common", "subtle", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -1732,6 +2000,18 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1749,6 +2029,18 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "downcast" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "dyn-clone" version = "1.0.17" @@ -1762,7 +2054,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ "der", - "digest", + "digest 0.10.7", "elliptic-curve", "rfc6979", "signature", @@ -1778,7 +2070,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1795,7 +2087,7 @@ checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", "crypto-bigint", - "digest", + "digest 0.10.7", "ff", "generic-array", "group", @@ -1825,12 +2117,41 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enr" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3d8dc56e02f954cac8eb489772c552c473346fc34f67412bb6244fd647f7e4" +dependencies = [ + "base64 0.21.7", + "bytes", + "hex", + "k256", + "log", + "rand", + "rlp", + "serde", + "sha3", + "zeroize", +] + [[package]] name = "entities" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca" +[[package]] +name = "enum-assoc" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24247b89d37b9502dc5a4b80d369aab1a12106067776e440094c786dae5b9d07" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "enum-ordinalize" version = "4.3.0" @@ -1848,7 +2169,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1875,10 +2196,10 @@ checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" dependencies = [ "aes", "ctr", - "digest", + "digest 0.10.7", "hex", "hmac", - "pbkdf2", + "pbkdf2 0.11.0", "rand", "scrypt", "serde", @@ -1889,6 +2210,23 @@ dependencies = [ "uuid", ] +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types", + "hex", + "once_cell", + "regex", + "serde", + "serde_json", + "sha3", + "thiserror", + "uint", +] + [[package]] name = "ethbloom" version = "0.13.0" @@ -1897,8 +2235,10 @@ checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" dependencies = [ "crunchy", "fixed-hash", + "impl-codec", "impl-rlp", "impl-serde", + "scale-info", "tiny-keccak", ] @@ -1910,17 +2250,283 @@ checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" dependencies = [ "ethbloom", "fixed-hash", + "impl-codec", "impl-rlp", "impl-serde", "primitive-types", + "scale-info", "uint", ] [[package]] -name = "fastrand" -version = "2.1.1" +name = "ethers" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "816841ea989f0c69e459af1cf23a6b0033b19a55424a1ea3a30099becdb8dec0" +dependencies = [ + "ethers-addressbook", + "ethers-contract", + "ethers-core", + "ethers-etherscan", + "ethers-middleware", + "ethers-providers", + "ethers-signers", + "ethers-solc", +] + +[[package]] +name = "ethers-addressbook" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5495afd16b4faa556c3bba1f21b98b4983e53c1755022377051a975c3b021759" +dependencies = [ + "ethers-core", + "once_cell", + "serde", + "serde_json", +] + +[[package]] +name = "ethers-contract" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fceafa3578c836eeb874af87abacfb041f92b4da0a78a5edd042564b8ecdaaa" +dependencies = [ + "const-hex", + "ethers-contract-abigen", + "ethers-contract-derive", + "ethers-core", + "ethers-providers", + "futures-util", + "once_cell", + "pin-project", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "ethers-contract-abigen" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04ba01fbc2331a38c429eb95d4a570166781f14290ef9fdb144278a90b5a739b" +dependencies = [ + "Inflector", + "const-hex", + "dunce", + "ethers-core", + "ethers-etherscan", + "eyre", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "reqwest", + "serde", + "serde_json", + "syn 2.0.82", + "toml", + "walkdir", +] + +[[package]] +name = "ethers-contract-derive" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87689dcabc0051cde10caaade298f9e9093d65f6125c14575db3fd8c669a168f" +dependencies = [ + "Inflector", + "const-hex", + "ethers-contract-abigen", + "ethers-core", + "proc-macro2", + "quote", + "serde_json", + "syn 2.0.82", +] + +[[package]] +name = "ethers-core" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d80cc6ad30b14a48ab786523af33b37f28a8623fc06afd55324816ef18fb1f" +dependencies = [ + "arrayvec", + "bytes", + "cargo_metadata", + "chrono", + "const-hex", + "elliptic-curve", + "ethabi", + "generic-array", + "k256", + "num_enum", + "once_cell", + "open-fastrlp", + "rand", + "rlp", + "serde", + "serde_json", + "strum 0.26.3", + "syn 2.0.82", + "tempfile", + "thiserror", + "tiny-keccak", + "unicode-xid", +] + +[[package]] +name = "ethers-etherscan" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79e5973c26d4baf0ce55520bd732314328cabe53193286671b47144145b9649" +dependencies = [ + "chrono", + "ethers-core", + "reqwest", + "semver", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "ethers-middleware" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f9fdf09aec667c099909d91908d5eaf9be1bd0e2500ba4172c1d28bfaa43de" +dependencies = [ + "async-trait", + "auto_impl", + "ethers-contract", + "ethers-core", + "ethers-etherscan", + "ethers-providers", + "ethers-signers", + "futures-channel", + "futures-locks", + "futures-util", + "instant", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "tracing-futures", + "url", +] + +[[package]] +name = "ethers-providers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6434c9a33891f1effc9c75472e12666db2fa5a0fec4b29af6221680a6fe83ab2" +dependencies = [ + "async-trait", + "auto_impl", + "base64 0.21.7", + "bytes", + "const-hex", + "enr", + "ethers-core", + "futures-core", + "futures-timer", + "futures-util", + "hashers", + "http", + "instant", + "jsonwebtoken", + "once_cell", + "pin-project", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-tungstenite", + "tracing", + "tracing-futures", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "ws_stream_wasm", +] + +[[package]] +name = "ethers-signers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228875491c782ad851773b652dd8ecac62cda8571d3bc32a5853644dd26766c2" +dependencies = [ + "async-trait", + "coins-bip32", + "coins-bip39", + "const-hex", + "elliptic-curve", + "eth-keystore", + "ethers-core", + "rand", + "sha2", + "thiserror", + "tracing", +] + +[[package]] +name = "ethers-solc" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66244a771d9163282646dbeffe0e6eca4dda4146b6498644e678ac6089b11edd" +dependencies = [ + "cfg-if", + "const-hex", + "dirs", + "dunce", + "ethers-core", + "glob", + "home", + "md-5", + "num_cpus", + "once_cell", + "path-slash", + "rayon", + "regex", + "semver", + "serde", + "serde_json", + "solang-parser", + "svm-rs", + "thiserror", + "tiny-keccak", + "tokio", + "tracing", + "walkdir", + "yansi 0.5.1", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "ff" @@ -1972,6 +2578,21 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1981,6 +2602,22 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fragile" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "funty" version = "2.0.0" @@ -1995,6 +2632,7 @@ checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", + "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -2017,12 +2655,44 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" +[[package]] +name = "futures-locks" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" +dependencies = [ + "futures-channel", + "futures-task", +] + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.82", +] + [[package]] name = "futures-sink" version = "0.3.31" @@ -2035,17 +2705,41 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +[[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.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", ] [[package]] @@ -2067,7 +2761,7 @@ checksum = "553630feadf7b76442b0849fd25fdf89b860d933623aec9693fed19af0400c78" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2119,6 +2813,52 @@ dependencies = [ "regex-syntax 0.8.5", ] +[[package]] +name = "gloo-net" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ac9e8288ae2c632fa9f8657ac70bfe38a1530f345282d7ba66a1f70b72b7dc4" +dependencies = [ + "futures-channel", + "futures-core", + "futures-sink", + "gloo-utils", + "http", + "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" @@ -2196,6 +2936,25 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hashers" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" +dependencies = [ + "fxhash", +] + +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "byteorder", + "num-traits 0.2.19", +] + [[package]] name = "heck" version = "0.4.1" @@ -2226,7 +2985,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -2281,11 +3040,17 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "human_bytes" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91f255a4535024abf7640cb288260811fc14794f62b063652ed349f9a6c2348e" + [[package]] name = "hyper" -version = "0.14.30" +version = "0.14.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" dependencies = [ "bytes", "futures-channel", @@ -2314,11 +3079,26 @@ dependencies = [ "futures-util", "http", "hyper", + "log", "rustls 0.21.12", + "rustls-native-certs", "tokio", "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.61" @@ -2460,6 +3240,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9f1a0777d972970f204fdf8ef319f1f4f8459131636d7e3c96c5d59570d0fa6" +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.3" @@ -2506,6 +3292,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "integer-encoding" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bb03732005da905c88227371639bf1ad885cc712789c011c31c5fb3ab3ccf02" + [[package]] name = "ipnet" version = "2.10.1" @@ -2571,13 +3363,188 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] +[[package]] +name = "jsonrpsee" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138572befc78a9793240645926f30161f8b4143d2be18d09e44ed9814bd7ee2c" +dependencies = [ + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-http-client", + "jsonrpsee-proc-macros", + "jsonrpsee-server", + "jsonrpsee-types", + "jsonrpsee-wasm-client", + "jsonrpsee-ws-client", + "tokio", + "tracing", +] + +[[package]] +name = "jsonrpsee-client-transport" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c671353e4adf926799107bd7f5724a06b6bc0a333db442a0843c58640bdd0c1" +dependencies = [ + "futures-channel", + "futures-util", + "gloo-net", + "http", + "jsonrpsee-core", + "pin-project", + "rustls-native-certs", + "soketto", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-util", + "tracing", + "url", + "webpki-roots 0.25.4", +] + +[[package]] +name = "jsonrpsee-core" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f24ea59b037b6b9b0e2ebe2c30a3e782b56bd7c76dcc5d6d70ba55d442af56e3" +dependencies = [ + "anyhow", + "async-lock", + "async-trait", + "beef", + "futures-timer", + "futures-util", + "hyper", + "jsonrpsee-types", + "parking_lot", + "rand", + "rustc-hash", + "serde", + "serde_json", + "soketto", + "thiserror", + "tokio", + "tracing", + "wasm-bindgen-futures", +] + +[[package]] +name = "jsonrpsee-http-client" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c7b9f95208927653e7965a98525e7fc641781cab89f0e27c43fa2974405683" +dependencies = [ + "async-trait", + "hyper", + "hyper-rustls", + "jsonrpsee-core", + "jsonrpsee-types", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "tracing", + "url", +] + +[[package]] +name = "jsonrpsee-proc-macros" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcc0eba68ba205452bcb4c7b80a79ddcb3bf36c261a841b239433142db632d24" +dependencies = [ + "heck 0.4.1", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "jsonrpsee-server" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a482bc4e25eebd0adb61a3468c722763c381225bd3ec46e926f709df8a8eb548" +dependencies = [ + "futures-util", + "http", + "hyper", + "jsonrpsee-core", + "jsonrpsee-types", + "route-recognizer", + "serde", + "serde_json", + "soketto", + "thiserror", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "jsonrpsee-types" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3264e339143fe37ed081953842ee67bfafa99e3b91559bdded6e4abd8fc8535e" +dependencies = [ + "anyhow", + "beef", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "jsonrpsee-wasm-client" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9437dd0e8728897d0aa5a0075b8710266300e55ced07101ca0930fac4a611384" +dependencies = [ + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-types", +] + +[[package]] +name = "jsonrpsee-ws-client" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d06eeabbb55f0af8405288390a358ebcceb6e79e1390741e6f152309c4d6076" +dependencies = [ + "http", + "jsonrpsee-client-transport", + "jsonrpsee-core", + "jsonrpsee-types", + "url", +] + +[[package]] +name = "jsonwebtoken" +version = "8.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" +dependencies = [ + "base64 0.21.7", + "pem", + "ring 0.16.20", + "serde", + "serde_json", + "simple_asn1", +] + [[package]] name = "k256" version = "0.13.4" @@ -2660,7 +3627,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin", + "spin 0.9.8", ] [[package]] @@ -2671,9 +3638,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libloading" @@ -2685,6 +3652,29 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libmdbx" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f0bee397dc9a7003e7bd34fffc1dc2d4c4fdc96530a0c439a5f98c9402bc7bf" +dependencies = [ + "bitflags 2.6.0", + "byteorder", + "derive_more", + "indexmap 1.9.3", + "libc", + "lifetimed-bytes", + "mdbx-sys", + "parking_lot", + "thiserror", +] + [[package]] name = "libredox" version = "0.1.3" @@ -2695,6 +3685,15 @@ dependencies = [ "libc", ] +[[package]] +name = "lifetimed-bytes" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c970c8ea4c7b023a41cfa4af4c785a16694604c2f2a3b0d1f20a9bcb73fa550" +dependencies = [ + "bytes", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -2755,6 +3754,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "matrixmultiply" version = "0.2.4" @@ -2764,41 +3769,104 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest 0.10.7", +] + +[[package]] +name = "mdbx-sys" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a329f8d655fb646cc9511c00886eefcddb6ef131869ef2d4b02c24c66825ac" +dependencies = [ + "bindgen 0.66.1", + "cc", + "libc", +] + [[package]] name = "melior" version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d97014786c173a839839e2a068e82516ad1eb94fca1d40013d3c5e224e7c1e" +checksum = "c5d97014786c173a839839e2a068e82516ad1eb94fca1d40013d3c5e224e7c1e" +dependencies = [ + "dashmap", + "melior-macro", + "mlir-sys", + "once_cell", +] + +[[package]] +name = "melior-macro" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef7ae0ba2f96784ec407d58374c8477f5b04ec8c57a114cafef0c8f165c4b288" +dependencies = [ + "comrak", + "convert_case 0.6.0", + "once_cell", + "proc-macro2", + "quote", + "regex", + "syn 2.0.82", + "tblgen-alt", + "unindent", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memmap2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a5a03cefb0d953ec0be133036f14e109412fa594edc2f77227249db66cc3ed" +dependencies = [ + "libc", +] + +[[package]] +name = "mempool_test_utils" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "blockifier", + "serde_json", + "starknet-types-core", + "starknet_api", +] + +[[package]] +name = "metrics" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde3af1a009ed76a778cb84fdef9e7dbbdf5775ae3e4cc1f434a6a307f6f76c5" dependencies = [ - "dashmap", - "melior-macro", - "mlir-sys", - "once_cell", + "ahash", + "metrics-macros", + "portable-atomic", ] [[package]] -name = "melior-macro" -version = "0.12.0" +name = "metrics-macros" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef7ae0ba2f96784ec407d58374c8477f5b04ec8c57a114cafef0c8f165c4b288" +checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" dependencies = [ - "comrak", - "convert_case 0.6.0", - "once_cell", "proc-macro2", "quote", - "regex", - "syn 2.0.79", - "tblgen-alt", - "unindent", + "syn 2.0.82", ] -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - [[package]] name = "mime" version = "0.3.17" @@ -2851,6 +3919,50 @@ dependencies = [ "bindgen 0.70.1", ] +[[package]] +name = "mockall" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43766c2b5203b10de348ffe19f7e54564b64f3d6018ff7648d1e2d6d3a0f0a48" +dependencies = [ + "cfg-if", + "downcast", + "fragile", + "lazy_static", + "mockall_derive", + "predicates", + "predicates-tree", +] + +[[package]] +name = "mockall_derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cbce79ec385a1d4f54baa90a76401eb15d9cab93685f62e7e9f942aa00ae2" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "syn 2.0.82", +] + +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "ndarray" version = "0.13.1" @@ -2982,6 +4094,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_enum" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.82", ] [[package]] @@ -3005,6 +4149,87 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "open-fastrlp" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", + "ethereum-types", + "open-fastrlp-derive", +] + +[[package]] +name = "open-fastrlp-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" +dependencies = [ + "bytes", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "openssl" +version = "0.10.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.82", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "ordered-float" version = "2.10.1" @@ -3014,6 +4239,17 @@ dependencies = [ "num-traits 0.2.19", ] +[[package]] +name = "os_info" +version = "3.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" +dependencies = [ + "log", + "serde", + "windows-sys 0.52.0", +] + [[package]] name = "overload" version = "0.1.1" @@ -3032,10 +4268,39 @@ dependencies = [ "sha2", ] +[[package]] +name = "page_size" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "papyrus_common" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "cairo-lang-starknet-classes", + "hex", + "indexmap 2.6.0", + "itertools 0.10.5", + "lazy_static", + "rand", + "serde", + "serde_json", + "sha3", + "starknet-types-core", + "starknet_api", + "thiserror", +] + [[package]] name = "papyrus_config" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=693cd41a893c7de71682b59686bcd0c99a27c9e0#693cd41a893c7de71682b59686bcd0c99a27c9e0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" dependencies = [ "clap", "itertools 0.10.5", @@ -3046,11 +4311,110 @@ dependencies = [ "validator", ] +[[package]] +name = "papyrus_execution" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "anyhow", + "blockifier", + "cairo-lang-starknet-classes", + "cairo-vm", + "indexmap 2.6.0", + "itertools 0.10.5", + "lazy_static", + "papyrus_common", + "papyrus_config", + "papyrus_storage", + "serde", + "serde_json", + "starknet-types-core", + "starknet_api", + "thiserror", + "tracing", +] + +[[package]] +name = "papyrus_proc_macros" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "quote", + "syn 2.0.82", + "tracing", +] + +[[package]] +name = "papyrus_rpc" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "anyhow", + "async-trait", + "base64 0.13.1", + "cairo-lang-starknet-classes", + "ethers", + "flate2", + "futures-util", + "hex", + "hyper", + "jsonrpsee", + "lazy_static", + "metrics", + "papyrus_common", + "papyrus_config", + "papyrus_execution", + "papyrus_proc_macros", + "papyrus_storage", + "regex", + "serde", + "serde_json", + "starknet-types-core", + "starknet_api", + "starknet_client", + "tokio", + "tower", + "tracing", + "validator", +] + +[[package]] +name = "papyrus_storage" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "byteorder", + "cairo-lang-casm", + "cairo-lang-starknet-classes", + "cairo-lang-utils", + "human_bytes", + "indexmap 2.6.0", + "integer-encoding", + "libmdbx", + "memmap2", + "metrics", + "num-bigint", + "page_size", + "papyrus_common", + "papyrus_config", + "papyrus_proc_macros", + "parity-scale-codec", + "primitive-types", + "serde", + "serde_json", + "starknet-types-core", + "starknet_api", + "thiserror", + "tracing", + "validator", + "zstd 0.13.2", +] + [[package]] name = "parity-scale-codec" -version = "3.6.12" +version = "3.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" +checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" dependencies = [ "arrayvec", "bitvec", @@ -3066,7 +4430,7 @@ version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 1.0.109", @@ -3110,24 +4474,55 @@ dependencies = [ name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "path-clean" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" + +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac", +] [[package]] -name = "path-clean" -version = "1.0.1" +name = "peeking_take_while" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] -name = "pbkdf2" -version = "0.11.0" +name = "pem" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" dependencies = [ - "digest", - "hmac", - "password-hash", - "sha2", + "base64 0.13.1", ] [[package]] @@ -3155,6 +4550,16 @@ dependencies = [ "indexmap 2.6.0", ] +[[package]] +name = "pharos" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" +dependencies = [ + "futures", + "rustc_version", +] + [[package]] name = "phf" version = "0.11.2" @@ -3185,7 +4590,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -3212,6 +4617,26 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +[[package]] +name = "pin-project" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.82", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -3240,6 +4665,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "powerfmt" version = "0.2.0" @@ -3261,6 +4692,32 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "predicates" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" +dependencies = [ + "anstyle", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" + +[[package]] +name = "predicates-tree" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "pretty_assertions" version = "1.4.1" @@ -3268,7 +4725,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", - "yansi", + "yansi 1.0.1", ] [[package]] @@ -3283,12 +4740,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.22" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d" dependencies = [ "proc-macro2", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -3310,16 +4767,27 @@ dependencies = [ "impl-codec", "impl-rlp", "impl-serde", + "scale-info", "uint", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit 0.19.15", +] + [[package]] name = "proc-macro-crate" version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml_edit", + "toml_edit 0.22.22", ] [[package]] @@ -3348,13 +4816,29 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] +[[package]] +name = "proptest" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" +dependencies = [ + "bitflags 2.6.0", + "lazy_static", + "num-traits 0.2.19", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax 0.8.5", + "unarray", +] + [[package]] name = "quote" version = "1.0.37" @@ -3400,6 +4884,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + [[package]] name = "rawpointer" version = "0.2.1" @@ -3535,10 +5028,12 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -3550,6 +5045,7 @@ dependencies = [ "sync_wrapper", "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls", "tower-service", "url", @@ -3570,6 +5066,21 @@ dependencies = [ "subtle", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + [[package]] name = "ring" version = "0.17.8" @@ -3580,11 +5091,20 @@ dependencies = [ "cfg-if", "getrandom", "libc", - "spin", - "untrusted", + "spin 0.9.8", + "untrusted 0.9.0", "windows-sys 0.52.0", ] +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "rlp" version = "0.5.2" @@ -3592,9 +5112,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ "bytes", + "rlp-derive", "rustc-hex", ] +[[package]] +name = "rlp-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "route-recognizer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" + [[package]] name = "rpc-state-reader" version = "0.1.0" @@ -3613,12 +5151,39 @@ dependencies = [ "serde_json", "starknet", "starknet_api", + "starknet_gateway", "test-case", "thiserror", "tracing", "ureq", ] +[[package]] +name = "rstest" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de1bb486a691878cd320c2f0d319ba91eeaa2e894066d8b5f8f117c000e9d962" +dependencies = [ + "futures", + "futures-timer", + "rstest_macros", + "rustc_version", +] + +[[package]] +name = "rstest_macros" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290ca1a1c8ca7edb7c3283bd44dc35dd54fdec6253a3912e201ba1072018fca8" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", + "unicode-ident", +] + [[package]] name = "rust-analyzer-salsa" version = "0.17.0-pre.6" @@ -3645,7 +5210,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -3705,26 +5270,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring", + "ring 0.17.8", "rustls-webpki 0.101.7", "sct", ] [[package]] name = "rustls" -version = "0.23.14" +version = "0.23.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" dependencies = [ "log", "once_cell", - "ring", + "ring 0.17.8", "rustls-pki-types", "rustls-webpki 0.102.8", "subtle", "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -3736,9 +5313,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" [[package]] name = "rustls-webpki" @@ -3746,8 +5323,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -3756,16 +5333,16 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "ring", + "ring 0.17.8", "rustls-pki-types", - "untrusted", + "untrusted 0.9.0", ] [[package]] name = "rustversion" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "ryu" @@ -3791,6 +5368,39 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scale-info" +version = "2.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca070c12893629e2cc820a9761bedf6ce1dcddc9852984d1dc734b8bd9bd024" +dependencies = [ + "cfg-if", + "derive_more", + "parity-scale-codec", + "scale-info-derive", +] + +[[package]] +name = "scale-info-derive" +version = "2.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "schannel" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "schemars" version = "0.8.21" @@ -3813,7 +5423,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -3829,7 +5439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" dependencies = [ "hmac", - "pbkdf2", + "pbkdf2 0.11.0", "salsa20", "sha2", ] @@ -3840,8 +5450,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -3858,6 +5468,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.23" @@ -3867,24 +5500,36 @@ dependencies = [ "serde", ] +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" -version = "1.0.210" +version = "1.0.211" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "1ac55e59090389fb9f0dd9e0f3c09615afed1d19094284d0b200441f13550793" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.211" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "54be4f245ce16bc58d57ef2716271d0d4519e0f6defa147f6e081005bcb278ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -3895,14 +5540,14 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -3921,6 +5566,27 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "serde_repr" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.82", +] + [[package]] name = "serde_spanned" version = "0.6.8" @@ -3985,7 +5651,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -3997,7 +5663,20 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", +] + +[[package]] +name = "sha-1" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", ] [[package]] @@ -4008,7 +5687,7 @@ checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -4019,7 +5698,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -4028,7 +5707,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest", + "digest 0.10.7", "keccak", ] @@ -4050,7 +5729,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "sierra-emu" version = "0.1.0" -source = "git+https://github.com/lambdaclass/sierra-emu.git#40ee99489effa22fd806d0ccabe4ed8c3bb87629" +source = "git+https://github.com/lambdaclass/sierra-emu.git#071caea75a403fb940a96b574f2a70dc431e0662" dependencies = [ "cairo-lang-compiler", "cairo-lang-filesystem", @@ -4079,16 +5758,37 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "signature" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "digest", + "digest 0.10.7", "rand_core", ] +[[package]] +name = "simple_asn1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +dependencies = [ + "num-bigint", + "num-traits 0.2.19", + "thiserror", + "time", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -4139,6 +5839,42 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "soketto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" +dependencies = [ + "base64 0.13.1", + "bytes", + "futures", + "http", + "httparse", + "log", + "rand", + "sha-1", +] + +[[package]] +name = "solang-parser" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c425ce1c59f4b154717592f0bdf4715c3a1d55058883622d3157e1f0908a5b26" +dependencies = [ + "itertools 0.11.0", + "lalrpop", + "lalrpop-util", + "phf", + "thiserror", + "unicode-xid", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -4320,7 +6056,7 @@ checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ "starknet-curve 0.4.2", "starknet-ff", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -4372,7 +6108,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95d549d3078bdbe775d0deaa8ddb57a19942989ce7c1f2dfd60beeb322bb4945" dependencies = [ "starknet-core 0.10.0", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -4429,7 +6165,7 @@ dependencies = [ [[package]] name = "starknet_api" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=693cd41a893c7de71682b59686bcd0c99a27c9e0#693cd41a893c7de71682b59686bcd0c99a27c9e0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" dependencies = [ "bitvec", "cairo-lang-starknet-classes", @@ -4448,6 +6184,110 @@ dependencies = [ "thiserror", ] +[[package]] +name = "starknet_client" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "async-trait", + "cairo-lang-starknet-classes", + "http", + "indexmap 2.6.0", + "os_info", + "papyrus_common", + "papyrus_config", + "reqwest", + "serde", + "serde_json", + "serde_repr", + "starknet-types-core", + "starknet_api", + "strum 0.25.0", + "strum_macros 0.25.3", + "thiserror", + "tokio", + "tokio-retry", + "tracing", + "url", +] + +[[package]] +name = "starknet_gateway" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "async-trait", + "axum", + "blockifier", + "cairo-lang-starknet-classes", + "enum-assoc", + "hyper", + "mempool_test_utils", + "papyrus_config", + "papyrus_rpc", + "reqwest", + "serde", + "serde_json", + "starknet-types-core", + "starknet_api", + "starknet_mempool_infra", + "starknet_mempool_types", + "starknet_sierra_compile", + "thiserror", + "tokio", + "tracing", + "validator", +] + +[[package]] +name = "starknet_mempool_infra" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "async-trait", + "bincode 1.3.3", + "hyper", + "papyrus_config", + "rstest", + "serde", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "validator", +] + +[[package]] +name = "starknet_mempool_types" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "async-trait", + "mockall", + "papyrus_proc_macros", + "serde", + "starknet_api", + "starknet_mempool_infra", + "thiserror", +] + +[[package]] +name = "starknet_sierra_compile" +version = "0.0.0" +source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +dependencies = [ + "cairo-lang-sierra", + "cairo-lang-starknet-classes", + "cairo-lang-utils", + "papyrus_config", + "serde", + "serde_json", + "starknet-types-core", + "starknet_api", + "thiserror", + "validator", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -4497,6 +6337,15 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros 0.26.4", +] + [[package]] name = "strum_macros" version = "0.24.3" @@ -4520,7 +6369,20 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.79", + "syn 2.0.82", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.82", ] [[package]] @@ -4529,6 +6391,26 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "svm-rs" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11297baafe5fa0c99d5722458eac6a5e25c01eb1b8e5cd137f54079093daa7a4" +dependencies = [ + "dirs", + "fs2", + "hex", + "once_cell", + "reqwest", + "semver", + "serde", + "serde_json", + "sha2", + "thiserror", + "url", + "zip", +] + [[package]] name = "syn" version = "1.0.109" @@ -4542,9 +6424,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" dependencies = [ "proc-macro2", "quote", @@ -4620,6 +6502,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + [[package]] name = "test-case" version = "3.3.1" @@ -4638,7 +6526,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -4649,7 +6537,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "test-case-core", ] @@ -4670,7 +6558,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -4760,9 +6648,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" dependencies = [ "backtrace", "bytes", @@ -4770,6 +6658,7 @@ dependencies = [ "mio", "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", @@ -4783,7 +6672,28 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-retry" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" +dependencies = [ + "pin-project", + "rand", + "tokio", ] [[package]] @@ -4796,6 +6706,32 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +dependencies = [ + "futures-util", + "log", + "rustls 0.21.12", + "tokio", + "tokio-rustls", + "tungstenite", + "webpki-roots 0.25.4", +] + [[package]] name = "tokio-util" version = "0.7.12" @@ -4804,6 +6740,7 @@ checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -4818,7 +6755,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.22.22", ] [[package]] @@ -4830,6 +6767,17 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.6.0", + "toml_datetime", + "winnow 0.5.40", +] + [[package]] name = "toml_edit" version = "0.22.22" @@ -4840,9 +6788,36 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.20", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "hdrhistogram", + "indexmap 1.9.3", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", ] +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + [[package]] name = "tower-service" version = "0.3.3" @@ -4855,6 +6830,7 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4868,7 +6844,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -4881,6 +6857,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "tracing-log" version = "0.2.0" @@ -4939,6 +6925,26 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "tungstenite" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "rustls 0.21.12", + "sha1", + "thiserror", + "url", + "utf-8", +] + [[package]] name = "typed-arena" version = "2.0.2" @@ -4963,6 +6969,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "unescaper" version = "0.1.5" @@ -5017,6 +7029,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -5033,7 +7051,7 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "serde", "serde_json", @@ -5052,6 +7070,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "utf8-width" version = "0.1.7" @@ -5125,6 +7149,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -5158,9 +7188,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", "once_cell", @@ -5169,24 +7199,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.43" +version = "0.4.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" dependencies = [ "cfg-if", "js-sys", @@ -5196,9 +7226,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5206,28 +7236,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", @@ -5448,6 +7478,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + [[package]] name = "winnow" version = "0.6.20" @@ -5467,6 +7506,25 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "ws_stream_wasm" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" +dependencies = [ + "async_io_stream", + "futures", + "js-sys", + "log", + "pharos", + "rustc_version", + "send_wrapper 0.6.0", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "wyz" version = "0.5.1" @@ -5491,6 +7549,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "yansi" version = "1.0.1" @@ -5515,7 +7579,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -5535,7 +7599,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -5552,10 +7616,10 @@ dependencies = [ "crossbeam-utils", "flate2", "hmac", - "pbkdf2", + "pbkdf2 0.11.0", "sha1", "time", - "zstd", + "zstd 0.11.2+zstd.1.5.2", ] [[package]] @@ -5564,7 +7628,16 @@ version = "0.11.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" dependencies = [ - "zstd-safe", + "zstd-safe 5.0.2+zstd.1.5.2", +] + +[[package]] +name = "zstd" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" +dependencies = [ + "zstd-safe 7.2.1", ] [[package]] @@ -5577,6 +7650,15 @@ dependencies = [ "zstd-sys", ] +[[package]] +name = "zstd-safe" +version = "7.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" +dependencies = [ + "zstd-sys", +] + [[package]] name = "zstd-sys" version = "2.0.13+zstd.1.5.6" From e17d4269f57fc115e897d59000ff71ae4e9ef3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 12:36:12 -0300 Subject: [PATCH 04/31] Copy objects --- rpc-state-reader/src/lib.rs | 2 ++ rpc-state-reader/src/objects.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 rpc-state-reader/src/objects.rs diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index 65a5079..a6c02fa 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -1,4 +1,6 @@ +pub mod objects; pub mod reader; + pub mod rpc_state; pub mod rpc_state_errors; pub mod utils; diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs new file mode 100644 index 0000000..ba83b3e --- /dev/null +++ b/rpc-state-reader/src/objects.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; +use starknet::core::types::Transaction; +use starknet_api::{block::BlockStatus, transaction::TransactionHash}; +use starknet_gateway::rpc_objects::BlockHeader; + +// The following structures are taken from https://github.com/starkware-libs/sequencer, +// but modified to suit our particular needs. + +#[derive(Debug, Deserialize, Serialize)] +pub struct BlockWithTxHahes { + #[serde(skip_serializing_if = "Option::is_none")] + pub status: Option, + #[serde(flatten)] + pub header: BlockHeader, + pub transactions: Vec, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct BlockWithTxs { + #[serde(skip_serializing_if = "Option::is_none")] + pub status: Option, + #[serde(flatten)] + pub header: BlockHeader, + pub transactions: Vec, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct TransactionWithHash { + pub transaction_hash: TransactionHash, + #[serde(flatten)] + pub transaction: Transaction, +} From 3af7f84091116b845d43d291e29feb66a9c19268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 12:36:21 -0300 Subject: [PATCH 05/31] Implement missing methods --- rpc-state-reader/src/reader.rs | 72 ++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index dc6fd8f..949c791 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -1,25 +1,31 @@ use std::sync::Arc; use blockifier::{ + blockifier::block::BlockInfo, execution::contract_class::{ ContractClass, ContractClassV0, ContractClassV0Inner, NativeContractClassV1, }, state::state_api::{StateReader, StateResult}, }; use cairo_vm::types::program::Program; -use starknet::core::types::ContractClass as SNContractClass; +use starknet::core::types::{ContractClass as SNContractClass, Transaction, TransactionTrace}; use starknet_api::{ block::BlockNumber, core::{ClassHash, CompiledClassHash, ContractAddress}, state::StorageKey, + transaction::{TransactionHash, TransactionReceipt}, }; use starknet_gateway::{ config::RpcStateReaderConfig, errors::serde_err_to_state_err, - rpc_state_reader::RpcStateReader as GatewayRpcStateReader, + rpc_objects::GetBlockWithTxHashesParams, + rpc_state_reader::RpcStateReader as GatewayRpcStateReader, state_reader::MempoolStateReader, }; use ureq::json; -use crate::utils; +use crate::{ + objects::{BlockWithTxHahes, BlockWithTxs}, + utils, +}; pub struct RpcStateReader { inner: GatewayRpcStateReader, @@ -38,9 +44,67 @@ impl RpcStateReader { "class_hash": class_hash.to_string(), }); + serde_json::from_value(self.inner.send_rpc_request("starknet_getClass", params)?) + .map_err(serde_err_to_state_err) + } + + pub fn get_transaction_trace(&self, hash: &TransactionHash) -> StateResult { + let params = json!([hash]); + + serde_json::from_value( + self.inner + .send_rpc_request("starknet_traceTransaction", params)?, + ) + .map_err(serde_err_to_state_err) + } + + pub fn get_transaction(&self, hash: &TransactionHash) -> StateResult { + let params = json!([hash]); + + serde_json::from_value( + self.inner + .send_rpc_request("starknet_getTransactionByHash", params)?, + ) + .map_err(serde_err_to_state_err) + } + + pub fn get_block_info(&self) -> StateResult { + self.inner.get_block_info() + } + + pub fn get_block_with_tx_hashes(&self) -> StateResult { + let params = GetBlockWithTxHashesParams { + block_id: self.inner.block_id, + }; + + serde_json::from_value( + self.inner + .send_rpc_request("starknet_getBlockWithTxHashes", params)?, + ) + .map_err(serde_err_to_state_err) + } + + pub fn get_block_with_txs(&self) -> StateResult { + let params = GetBlockWithTxHashesParams { + block_id: self.inner.block_id, + }; + + serde_json::from_value( + self.inner + .send_rpc_request("starknet_getBlockWithTxs", params)?, + ) + .map_err(serde_err_to_state_err) + } + + pub fn get_transaction_receipt( + &self, + hash: &TransactionHash, + ) -> StateResult { + let params = json!([hash]); + serde_json::from_value( self.inner - .send_rpc_request("starknet_getClass", params.clone())?, + .send_rpc_request("starknet_getTransactionReceipt", params)?, ) .map_err(serde_err_to_state_err) } From 4ffbf4883a2b7233f583e7108c43cb9c484fdba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 12:36:23 -0300 Subject: [PATCH 06/31] Update deps --- Cargo.lock | 28 ++++++++++++++-------------- Cargo.toml | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68ef68c..c919305 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -608,7 +608,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "anyhow", "ark-ec", @@ -3837,7 +3837,7 @@ dependencies = [ [[package]] name = "mempool_test_utils" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "blockifier", "serde_json", @@ -4281,7 +4281,7 @@ dependencies = [ [[package]] name = "papyrus_common" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "cairo-lang-starknet-classes", "hex", @@ -4300,7 +4300,7 @@ dependencies = [ [[package]] name = "papyrus_config" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "clap", "itertools 0.10.5", @@ -4314,7 +4314,7 @@ dependencies = [ [[package]] name = "papyrus_execution" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "anyhow", "blockifier", @@ -4337,7 +4337,7 @@ dependencies = [ [[package]] name = "papyrus_proc_macros" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "quote", "syn 2.0.82", @@ -4347,7 +4347,7 @@ dependencies = [ [[package]] name = "papyrus_rpc" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "anyhow", "async-trait", @@ -4381,7 +4381,7 @@ dependencies = [ [[package]] name = "papyrus_storage" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "byteorder", "cairo-lang-casm", @@ -6165,7 +6165,7 @@ dependencies = [ [[package]] name = "starknet_api" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "bitvec", "cairo-lang-starknet-classes", @@ -6187,7 +6187,7 @@ dependencies = [ [[package]] name = "starknet_client" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "async-trait", "cairo-lang-starknet-classes", @@ -6214,7 +6214,7 @@ dependencies = [ [[package]] name = "starknet_gateway" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "async-trait", "axum", @@ -6242,7 +6242,7 @@ dependencies = [ [[package]] name = "starknet_mempool_infra" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "async-trait", "bincode 1.3.3", @@ -6260,7 +6260,7 @@ dependencies = [ [[package]] name = "starknet_mempool_types" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "async-trait", "mockall", @@ -6274,7 +6274,7 @@ dependencies = [ [[package]] name = "starknet_sierra_compile" version = "0.0.0" -source = "git+https://github.com/lambdaclass/sequencer?rev=7aefd2cfd6071fff2c702811a47407eb14914aca#7aefd2cfd6071fff2c702811a47407eb14914aca" +source = "git+https://github.com/lambdaclass/sequencer?rev=1b1b95cae7ae07b9bc778443ca75ee18008a6bc8#1b1b95cae7ae07b9bc778443ca75ee18008a6bc8" dependencies = [ "cairo-lang-sierra", "cairo-lang-starknet-classes", diff --git a/Cargo.toml b/Cargo.toml index 27b2c06..d862406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,9 @@ serde = "1.0.197" cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "355c250f37cf0977ef2776b1aae2cb2e87c9da3d" } # Sequencer Dependencies -starknet_api = { git = "https://github.com/lambdaclass/sequencer", rev = "7aefd2cfd6071fff2c702811a47407eb14914aca"} -blockifier = { git = "https://github.com/lambdaclass/sequencer", rev = "7aefd2cfd6071fff2c702811a47407eb14914aca"} -starknet_gateway = { git = "https://github.com/lambdaclass/sequencer", rev = "7aefd2cfd6071fff2c702811a47407eb14914aca"} +starknet_api = { git = "https://github.com/lambdaclass/sequencer", rev = "1b1b95cae7ae07b9bc778443ca75ee18008a6bc8"} +blockifier = { git = "https://github.com/lambdaclass/sequencer", rev = "1b1b95cae7ae07b9bc778443ca75ee18008a6bc8"} +starknet_gateway = { git = "https://github.com/lambdaclass/sequencer", rev = "1b1b95cae7ae07b9bc778443ca75ee18008a6bc8"} [patch.'https://github.com/lambdaclass/cairo_native'] cairo-native = { git = 'https://github.com/lambdaclass//cairo_native.git', rev = "355c250f37cf0977ef2776b1aae2cb2e87c9da3d" } From 1e941791e5aedaaa9ee0ae75d173724e00c4cc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 13:18:29 -0300 Subject: [PATCH 07/31] Add tests --- rpc-state-reader/src/reader.rs | 124 ++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 10 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index 949c791..f79b5ab 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -1,7 +1,7 @@ -use std::sync::Arc; +use std::{env, fmt, num::NonZeroU128, sync::Arc}; use blockifier::{ - blockifier::block::BlockInfo, + blockifier::block::{BlockInfo, GasPrices}, execution::contract_class::{ ContractClass, ContractClassV0, ContractClassV0Inner, NativeContractClassV1, }, @@ -10,15 +10,17 @@ use blockifier::{ use cairo_vm::types::program::Program; use starknet::core::types::{ContractClass as SNContractClass, Transaction, TransactionTrace}; use starknet_api::{ - block::BlockNumber, - core::{ClassHash, CompiledClassHash, ContractAddress}, + block::{BlockNumber, GasPrice}, + core::{ChainId, ClassHash, CompiledClassHash, ContractAddress}, + data_availability::L1DataAvailabilityMode, state::StorageKey, transaction::{TransactionHash, TransactionReceipt}, }; use starknet_gateway::{ - config::RpcStateReaderConfig, errors::serde_err_to_state_err, - rpc_objects::GetBlockWithTxHashesParams, - rpc_state_reader::RpcStateReader as GatewayRpcStateReader, state_reader::MempoolStateReader, + config::RpcStateReaderConfig, + errors::serde_err_to_state_err, + rpc_objects::{BlockHeader, GetBlockWithTxHashesParams}, + rpc_state_reader::RpcStateReader as GatewayRpcStateReader, }; use ureq::json; @@ -27,14 +29,57 @@ use crate::{ utils, }; +/// Starknet chains supported in Infura. +#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord)] +pub enum RpcChain { + MainNet, + TestNet, + TestNet2, +} + +impl fmt::Display for RpcChain { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RpcChain::MainNet => write!(f, "starknet-mainnet"), + RpcChain::TestNet => write!(f, "starknet-goerli"), + RpcChain::TestNet2 => write!(f, "starknet-goerli2"), + } + } +} + +impl From for ChainId { + fn from(value: RpcChain) -> Self { + ChainId::Other(match value { + RpcChain::MainNet => "alpha-mainnet".to_string(), + RpcChain::TestNet => "alpha4".to_string(), + RpcChain::TestNet2 => "alpha4-2".to_string(), + }) + } +} + pub struct RpcStateReader { inner: GatewayRpcStateReader, } impl RpcStateReader { - pub fn from_number(config: &RpcStateReaderConfig, block_number: BlockNumber) -> Self { + pub fn new(chain: RpcChain, block_number: BlockNumber) -> Self { + let url = match chain { + RpcChain::MainNet => { + env::var("RPC_ENDPOINT_MAINNET").expect("Missing env var: RPC_ENDPOINT_MAINNET") + } + RpcChain::TestNet => { + env::var("RPC_ENDPOINT_TESTNET").expect("Missing env var: RPC_ENDPOINT_TESTNET") + } + RpcChain::TestNet2 => unimplemented!(), + }; + + let config = RpcStateReaderConfig { + url, + json_rpc_version: "2.0".to_string(), + }; + Self { - inner: GatewayRpcStateReader::from_number(config, block_number), + inner: GatewayRpcStateReader::from_number(&config, block_number), } } @@ -69,7 +114,36 @@ impl RpcStateReader { } pub fn get_block_info(&self) -> StateResult { - self.inner.get_block_info() + // This function is inspired by sequencer's RpcStateReader::get_block_info + + fn parse_gas_price(price: GasPrice) -> NonZeroU128 { + NonZeroU128::new(price.0).unwrap_or(NonZeroU128::new(1).unwrap()) + } + + let params = GetBlockWithTxHashesParams { + block_id: self.inner.block_id, + }; + + let header: BlockHeader = serde_json::from_value( + self.inner + .send_rpc_request("starknet_getBlockWithTxHashes", params)?, + ) + .map_err(serde_err_to_state_err)?; + + Ok(BlockInfo { + block_number: header.block_number, + sequencer_address: header.sequencer_address, + block_timestamp: header.timestamp, + gas_prices: GasPrices::new( + parse_gas_price(header.l1_gas_price.price_in_wei), + parse_gas_price(header.l1_gas_price.price_in_fri), + parse_gas_price(header.l1_data_gas_price.price_in_wei), + parse_gas_price(header.l1_data_gas_price.price_in_fri), + NonZeroU128::MIN, + NonZeroU128::MIN, + ), + use_kzg_da: matches!(header.l1_da_mode, L1DataAvailabilityMode::Blob), + }) } pub fn get_block_with_tx_hashes(&self) -> StateResult { @@ -177,3 +251,33 @@ impl StateReader for RpcStateReader { self.inner.get_compiled_class_hash(class_hash) } } + +#[cfg(test)] +mod tests { + use std::num::NonZeroU128; + + use super::*; + + #[test] + fn test_get_block_info() { + let reader = RpcStateReader::new(RpcChain::MainNet, BlockNumber(169928)); + + let block = reader.get_block_info().unwrap(); + + assert_eq!( + block + .gas_prices + .get_l1_gas_price_by_fee_type(&blockifier::transaction::objects::FeeType::Eth), + NonZeroU128::new(22804578690).unwrap() + ); + } + + #[test] + fn test_get_block_with_tx_hashes() { + let reader = RpcStateReader::new(RpcChain::MainNet, BlockNumber(397709)); + + let block = reader.get_block_with_tx_hashes().unwrap(); + + assert_eq!(block.transactions.len(), 211); + } +} From a6364cb393e1346ef4f11eb5376ca6769df8ca77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 16:46:56 -0300 Subject: [PATCH 08/31] Add builder --- rpc-state-reader/src/reader.rs | 51 ++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index f79b5ab..aee068e 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -8,13 +8,15 @@ use blockifier::{ state::state_api::{StateReader, StateResult}, }; use cairo_vm::types::program::Program; -use starknet::core::types::{ContractClass as SNContractClass, Transaction, TransactionTrace}; +use starknet::core::types::{ + ContractClass as SNContractClass, Transaction, TransactionReceipt, TransactionTrace, +}; use starknet_api::{ block::{BlockNumber, GasPrice}, core::{ChainId, ClassHash, CompiledClassHash, ContractAddress}, data_availability::L1DataAvailabilityMode, state::StorageKey, - transaction::{TransactionHash, TransactionReceipt}, + transaction::TransactionHash, }; use starknet_gateway::{ config::RpcStateReaderConfig, @@ -63,27 +65,22 @@ pub struct RpcStateReader { impl RpcStateReader { pub fn new(chain: RpcChain, block_number: BlockNumber) -> Self { - let url = match chain { - RpcChain::MainNet => { - env::var("RPC_ENDPOINT_MAINNET").expect("Missing env var: RPC_ENDPOINT_MAINNET") - } - RpcChain::TestNet => { - env::var("RPC_ENDPOINT_TESTNET").expect("Missing env var: RPC_ENDPOINT_TESTNET") - } - RpcChain::TestNet2 => unimplemented!(), - }; - - let config = RpcStateReaderConfig { - url, - json_rpc_version: "2.0".to_string(), - }; + let config = build_config(chain); Self { inner: GatewayRpcStateReader::from_number(&config, block_number), } } - pub fn get_contract_class(&self, class_hash: ClassHash) -> StateResult { + pub fn new_latest(chain: RpcChain) -> Self { + let config = build_config(chain); + + Self { + inner: GatewayRpcStateReader::from_latest(&config), + } + } + + pub fn get_contract_class(&self, class_hash: &ClassHash) -> StateResult { let params = json!({ "block_id": self.inner.block_id, "class_hash": class_hash.to_string(), @@ -184,6 +181,24 @@ impl RpcStateReader { } } +fn build_config(chain: RpcChain) -> RpcStateReaderConfig { + let url = match chain { + RpcChain::MainNet => { + env::var("RPC_ENDPOINT_MAINNET").expect("Missing env var: RPC_ENDPOINT_MAINNET") + } + RpcChain::TestNet => { + env::var("RPC_ENDPOINT_TESTNET").expect("Missing env var: RPC_ENDPOINT_TESTNET") + } + RpcChain::TestNet2 => unimplemented!(), + }; + + let config = RpcStateReaderConfig { + url, + json_rpc_version: "2.0".to_string(), + }; + config +} + impl StateReader for RpcStateReader { fn get_storage_at( &self, @@ -205,7 +220,7 @@ impl StateReader for RpcStateReader { } fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { - Ok(match self.get_contract_class(class_hash)? { + Ok(match self.get_contract_class(&class_hash)? { SNContractClass::Legacy(compressed_legacy_cc) => { let as_str = utils::decode_reader(compressed_legacy_cc.program).unwrap(); let program = Program::from_bytes(as_str.as_bytes(), None).unwrap(); From b2ad4e496b19069c0165fbb3e4ae6ad049b8852e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 17:23:25 -0300 Subject: [PATCH 09/31] Migrate old objects --- rpc-state-reader/src/objects.rs | 116 +++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs index ba83b3e..81940a9 100644 --- a/rpc-state-reader/src/objects.rs +++ b/rpc-state-reader/src/objects.rs @@ -1,8 +1,58 @@ +use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use serde::{Deserialize, Serialize}; use starknet::core::types::Transaction; -use starknet_api::{block::BlockStatus, transaction::TransactionHash}; +use starknet_api::{ + block::BlockStatus, + hash::StarkHash, + transaction::{Event, Fee, MessageToL1, TransactionExecutionStatus, TransactionHash}, +}; use starknet_gateway::rpc_objects::BlockHeader; +// The following are not used right now +// We are keeping them just in case + +#[derive(Debug, Deserialize, Clone, Eq, PartialEq)] +pub struct RpcTransactionTrace { + pub validate_invocation: Option, + #[serde( + alias = "execute_invocation", + alias = "constructor_invocation", + alias = "function_invocation" + )] + pub execute_invocation: Option, + pub fee_transfer_invocation: Option, +} + +#[derive(Debug, Clone, Eq, PartialEq, Default, Deserialize)] +pub struct RpcCallInfo { + pub result: Option>, + pub calldata: Option>, + pub calls: Vec, + pub revert_reason: Option, +} + +#[derive(Debug, Deserialize)] +pub struct RpcTransactionReceipt { + pub transaction_hash: TransactionHash, + pub block_hash: StarkHash, + pub block_number: u64, + #[serde(rename = "type")] + pub tx_type: String, + pub actual_fee: FeePayment, + pub messages_sent: Vec, + pub events: Vec, + #[serde(flatten)] + pub execution_status: TransactionExecutionStatus, + #[serde(deserialize_with = "deser::vm_execution_resources_deser")] + pub execution_resources: ExecutionResources, +} + +#[derive(Debug, Deserialize)] +pub struct FeePayment { + pub amount: Fee, + pub unit: String, +} + // The following structures are taken from https://github.com/starkware-libs/sequencer, // but modified to suit our particular needs. @@ -30,3 +80,67 @@ pub struct TransactionWithHash { #[serde(flatten)] pub transaction: Transaction, } + +mod deser { + use std::collections::HashMap; + + use cairo_vm::{ + types::builtin_name::BuiltinName, vm::runners::cairo_runner::ExecutionResources, + }; + use serde::{Deserialize, Deserializer}; + + pub fn vm_execution_resources_deser<'de, D>( + deserializer: D, + ) -> Result + where + D: Deserializer<'de>, + { + let value: serde_json::Value = Deserialize::deserialize(deserializer)?; + + // Parse n_steps + let n_steps: usize = serde_json::from_value( + value + .get("steps") + .ok_or(serde::de::Error::custom("missing field `n_steps`"))? + .clone(), + ) + .map_err(|e| serde::de::Error::custom(e.to_string()))?; + + // Parse n_memory_holes + let n_memory_holes: usize = if let Some(memory_holes) = value.get("memory_holes") { + serde_json::from_value(memory_holes.clone()) + .map_err(|e| serde::de::Error::custom(e.to_string()))? + } else { + 0 + }; + + // Parse builtin instance counter + let builtn_names: [BuiltinName; 8] = [ + BuiltinName::output, + BuiltinName::range_check, + BuiltinName::pedersen, + BuiltinName::ecdsa, + BuiltinName::keccak, + BuiltinName::bitwise, + BuiltinName::ec_op, + BuiltinName::poseidon, + ]; + let mut builtin_instance_counter = HashMap::new(); + for name in builtn_names { + let builtin_counter: Option = value + .get(format!("{}_applications", name.to_str())) + .and_then(|a| serde_json::from_value(a.clone()).ok()); + if let Some(builtin_counter) = builtin_counter { + if builtin_counter > 0 { + builtin_instance_counter.insert(name, builtin_counter); + } + }; + } + + Ok(ExecutionResources { + n_steps, + n_memory_holes, + builtin_instance_counter, + }) + } +} From 5ab1ca92d679d5cc899457c4a87f51db0e5bcc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 17:23:36 -0300 Subject: [PATCH 10/31] Update methods with new objects --- rpc-state-reader/src/reader.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index aee068e..dbe8d7f 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -8,9 +8,7 @@ use blockifier::{ state::state_api::{StateReader, StateResult}, }; use cairo_vm::types::program::Program; -use starknet::core::types::{ - ContractClass as SNContractClass, Transaction, TransactionReceipt, TransactionTrace, -}; +use starknet::core::types::{ContractClass as SNContractClass, Transaction}; use starknet_api::{ block::{BlockNumber, GasPrice}, core::{ChainId, ClassHash, CompiledClassHash, ContractAddress}, @@ -27,7 +25,7 @@ use starknet_gateway::{ use ureq::json; use crate::{ - objects::{BlockWithTxHahes, BlockWithTxs}, + objects::{BlockWithTxHahes, BlockWithTxs, RpcTransactionReceipt, RpcTransactionTrace}, utils, }; @@ -90,7 +88,10 @@ impl RpcStateReader { .map_err(serde_err_to_state_err) } - pub fn get_transaction_trace(&self, hash: &TransactionHash) -> StateResult { + pub fn get_transaction_trace( + &self, + hash: &TransactionHash, + ) -> StateResult { let params = json!([hash]); serde_json::from_value( @@ -170,7 +171,7 @@ impl RpcStateReader { pub fn get_transaction_receipt( &self, hash: &TransactionHash, - ) -> StateResult { + ) -> StateResult { let params = json!([hash]); serde_json::from_value( From 2fece33253972e012cae3d92df2e6f98ec8fa7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 17:24:01 -0300 Subject: [PATCH 11/31] Update tests --- rpc-state-reader/src/lib.rs | 91 ++++++++++++++----------------------- 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index a6c02fa..601f651 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -8,22 +8,20 @@ pub mod utils; pub mod blockifier_state_reader; #[cfg(test)] -mod tests { - use blockifier::transaction::{ - account_transaction::AccountTransaction, transactions::InvokeTransaction, - }; +mod tests1 { + use blockifier::state::state_api::StateReader; use pretty_assertions_sorted::{assert_eq, assert_eq_sorted}; use starknet_api::{ class_hash, - core::{ClassHash, ContractAddress, PatriciaKey}, + core::{ClassHash, ContractAddress, Nonce, PatriciaKey}, felt, hash::StarkHash, patricia_key, state::StorageKey, - transaction::{Transaction as SNTransaction, TransactionHash}, + transaction::TransactionHash, }; - use crate::rpc_state::*; + use crate::reader::*; /// A utility macro to create a [`ContractAddress`] from a hex string / unsigned integer /// representation. @@ -36,7 +34,7 @@ mod tests { #[test] fn test_get_contract_class_cairo1() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let class_hash = class_hash!("0298e56befa6d1446b86ed5b900a9ba51fd2faa683cd6f50e8f833c0fb847216"); @@ -44,59 +42,59 @@ mod tests { // https://starkscan.co/class/0x0298e56befa6d1446b86ed5b900a9ba51fd2faa683cd6f50e8f833c0fb847216 // which is cairo1.0 - rpc_state.get_contract_class(&class_hash); + rpc_state.get_contract_class(&class_hash).unwrap(); } #[test] fn test_get_contract_class_cairo0() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let class_hash = class_hash!("025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918"); - rpc_state.get_contract_class(&class_hash); + rpc_state.get_contract_class(&class_hash).unwrap(); } #[test] fn test_get_class_hash_at() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let address = contract_address!("00b081f7ba1efc6fe98770b09a827ae373ef2baa6116b3d2a0bf5154136573a9"); assert_eq!( - rpc_state.get_class_hash_at(&address), + rpc_state.get_class_hash_at(address).unwrap(), class_hash!("025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918") ); } #[test] fn test_get_nonce_at() { - let rpc_state = RpcState::new_rpc(RpcChain::TestNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::TestNet); // Contract deployed by xqft which will not be used again, so nonce changes will not break // this test. let address = contract_address!("07185f2a350edcc7ea072888edb4507247de23e710cbd56084c356d265626bea"); assert_eq!( - rpc_state.get_nonce_at(&address), - StarkHash::from_hex("0x0").unwrap() + rpc_state.get_nonce_at(address).unwrap(), + Nonce(felt!("0x0")), ); } #[test] fn test_get_storage_at() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let address = contract_address!("00b081f7ba1efc6fe98770b09a827ae373ef2baa6116b3d2a0bf5154136573a9"); let key = StorageKey(patricia_key!(0u128)); assert_eq_sorted!( - rpc_state.get_storage_at(&address, &key), + rpc_state.get_storage_at(address, key).unwrap(), StarkHash::from_hex("0x0").unwrap() ); } #[test] fn test_get_transaction() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let tx_hash = TransactionHash( StarkHash::from_hex("06da92cfbdceac5e5e94a1f40772d6c79d34f011815606742658559ec77b6955") .unwrap(), @@ -107,28 +105,18 @@ mod tests { #[test] fn test_try_from_invoke() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let tx_hash = TransactionHash( StarkHash::from_hex("06da92cfbdceac5e5e94a1f40772d6c79d34f011815606742658559ec77b6955") .unwrap(), ); - let tx = rpc_state.get_transaction(&tx_hash).unwrap(); - match tx { - SNTransaction::Invoke(tx) => { - let invoke = InvokeTransaction { - tx: starknet_api::executable_transaction::InvokeTransaction { tx, tx_hash }, - only_query: false, - }; - AccountTransaction::Invoke(invoke) - } - _ => unreachable!(), - }; + rpc_state.get_transaction(&tx_hash).unwrap(); } #[test] fn test_get_block_info() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); assert!(rpc_state.get_block_info().is_ok()); } @@ -137,7 +125,7 @@ mod tests { // https://alpha-mainnet.starknet.io/feeder_gateway/get_transaction_trace?transactionHash=0x035673e42bd485ae699c538d8502f730d1137545b22a64c094ecdaf86c59e592 #[test] fn test_get_transaction_trace() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let tx_hash = TransactionHash( StarkHash::from_hex( @@ -185,16 +173,11 @@ mod tests { ]) ); assert_eq!( - tx_trace.validate_invocation.as_ref().unwrap().retdata, + tx_trace.validate_invocation.as_ref().unwrap().result, Some(vec![]) ); assert_eq!( - tx_trace - .validate_invocation - .as_ref() - .unwrap() - .internal_calls - .len(), + tx_trace.validate_invocation.as_ref().unwrap().calls.len(), 1 ); @@ -235,27 +218,19 @@ mod tests { ]) ); assert_eq!( - tx_trace.execute_invocation.as_ref().unwrap().retdata, + tx_trace.execute_invocation.as_ref().unwrap().result, Some(vec![0u128.into()]) ); + assert_eq!(tx_trace.execute_invocation.as_ref().unwrap().calls.len(), 1); assert_eq!( - tx_trace - .execute_invocation - .as_ref() - .unwrap() - .internal_calls - .len(), - 1 - ); - assert_eq!( - tx_trace.execute_invocation.as_ref().unwrap().internal_calls[0] - .internal_calls + tx_trace.execute_invocation.as_ref().unwrap().calls[0] + .calls .len(), 1 ); assert_eq!( - tx_trace.execute_invocation.as_ref().unwrap().internal_calls[0].internal_calls[0] - .internal_calls + tx_trace.execute_invocation.as_ref().unwrap().calls[0].calls[0] + .calls .len(), 0 ); @@ -272,7 +247,7 @@ mod tests { ]) ); assert_eq!( - tx_trace.fee_transfer_invocation.as_ref().unwrap().retdata, + tx_trace.fee_transfer_invocation.as_ref().unwrap().result, Some(vec![1u128.into()]) ); assert_eq!( @@ -280,7 +255,7 @@ mod tests { .fee_transfer_invocation .as_ref() .unwrap() - .internal_calls + .calls .len(), 1 ); @@ -288,12 +263,12 @@ mod tests { #[test] fn test_get_transaction_receipt() { - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, BlockTag::Latest.into()).unwrap(); + let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); let tx_hash = TransactionHash( StarkHash::from_hex("06da92cfbdceac5e5e94a1f40772d6c79d34f011815606742658559ec77b6955") .unwrap(), ); - assert!(rpc_state.get_transaction_receipt(&tx_hash).is_ok()); + rpc_state.get_transaction_receipt(&tx_hash).unwrap(); } } From 1f9648214e4cc37b49bb6dc61d038bf08f5f5795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 18:29:19 -0300 Subject: [PATCH 12/31] Fix bug --- rpc-state-reader/src/reader.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index dbe8d7f..d5f9c85 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -8,13 +8,13 @@ use blockifier::{ state::state_api::{StateReader, StateResult}, }; use cairo_vm::types::program::Program; -use starknet::core::types::{ContractClass as SNContractClass, Transaction}; +use starknet::core::types::ContractClass as SNContractClass; use starknet_api::{ block::{BlockNumber, GasPrice}, core::{ChainId, ClassHash, CompiledClassHash, ContractAddress}, data_availability::L1DataAvailabilityMode, state::StorageKey, - transaction::TransactionHash, + transaction::{Transaction, TransactionHash}, }; use starknet_gateway::{ config::RpcStateReaderConfig, @@ -58,6 +58,7 @@ impl From for ChainId { } pub struct RpcStateReader { + chain: RpcChain, inner: GatewayRpcStateReader, } @@ -67,6 +68,7 @@ impl RpcStateReader { Self { inner: GatewayRpcStateReader::from_number(&config, block_number), + chain, } } @@ -75,6 +77,7 @@ impl RpcStateReader { Self { inner: GatewayRpcStateReader::from_latest(&config), + chain, } } @@ -88,6 +91,10 @@ impl RpcStateReader { .map_err(serde_err_to_state_err) } + pub fn get_chain_id(&self) -> ChainId { + self.chain.into() + } + pub fn get_transaction_trace( &self, hash: &TransactionHash, @@ -104,11 +111,11 @@ impl RpcStateReader { pub fn get_transaction(&self, hash: &TransactionHash) -> StateResult { let params = json!([hash]); - serde_json::from_value( - self.inner - .send_rpc_request("starknet_getTransactionByHash", params)?, - ) - .map_err(serde_err_to_state_err) + let tx = self + .inner + .send_rpc_request("starknet_getTransactionByHash", params)?; + + utils::deserialize_transaction_json(tx).map_err(serde_err_to_state_err) } pub fn get_block_info(&self) -> StateResult { From 8fba9049e2457e880099762a650678f112c44607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 18:29:24 -0300 Subject: [PATCH 13/31] Add execution --- rpc-state-reader/src/execution.rs | 1000 +++++++++++++++++++++++++++++ rpc-state-reader/src/lib.rs | 1 + 2 files changed, 1001 insertions(+) create mode 100644 rpc-state-reader/src/execution.rs diff --git a/rpc-state-reader/src/execution.rs b/rpc-state-reader/src/execution.rs new file mode 100644 index 0000000..b49e898 --- /dev/null +++ b/rpc-state-reader/src/execution.rs @@ -0,0 +1,1000 @@ +use blockifier::{ + blockifier::block::BlockInfo, + bouncer::BouncerConfig, + context::{BlockContext, ChainInfo, FeeTokenAddresses}, + execution::contract_class::{ClassInfo, ContractClass}, + state::{cached_state::CachedState, state_api::StateReader}, + transaction::{ + account_transaction::AccountTransaction, + objects::{TransactionExecutionInfo, TransactionExecutionResult}, + transactions::{ + DeclareTransaction, DeployAccountTransaction, ExecutableTransaction, InvokeTransaction, + L1HandlerTransaction, + }, + }, + versioned_constants::VersionedConstants, +}; +use starknet_api::{ + block::BlockNumber, + core::{calculate_contract_address, ContractAddress, PatriciaKey}, + felt, + hash::StarkHash, + patricia_key, + transaction::{Transaction as SNTransaction, TransactionHash}, +}; + +use crate::{ + objects::{RpcTransactionReceipt, RpcTransactionTrace}, + reader::{RpcChain, RpcStateReader}, + rpc_state::RpcState, +}; + +pub fn execute_tx( + tx_hash: &str, + network: RpcChain, + block_number: BlockNumber, +) -> ( + TransactionExecutionInfo, + RpcTransactionTrace, + RpcTransactionReceipt, +) { + let tx_hash = TransactionHash(StarkHash::from_hex(tx_hash).unwrap()); + + // Instantiate the RPC StateReader and the CachedState + let reader = RpcStateReader::new(network, block_number); + + let block_info = reader.get_block_info().unwrap(); + + // Get transaction before giving ownership of the reader + let transaction = reader.get_transaction(&tx_hash).unwrap(); + + let trace = reader.get_transaction_trace(&tx_hash).unwrap(); + let receipt = reader.get_transaction_receipt(&tx_hash).unwrap(); + + // Create state from RPC reader + let mut state = CachedState::new(reader); + + let fee_token_addresses = FeeTokenAddresses { + strk_fee_token_address: ContractAddress(patricia_key!( + "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" + )), + eth_fee_token_address: ContractAddress(patricia_key!( + "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" + )), + }; + let chain_info = ChainInfo { + chain_id: network.into(), + fee_token_addresses, + }; + let mut versioned_constants = + VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); + versioned_constants.disable_cairo0_redeclaration = false; + + let block_context = BlockContext::new( + block_info, + chain_info, + versioned_constants, + BouncerConfig::empty(), + ); + + // Map starknet_api transaction to blockifier's + let blockifier_tx = match transaction { + SNTransaction::Invoke(tx) => { + let invoke = InvokeTransaction { + tx: starknet_api::executable_transaction::InvokeTransaction { tx, tx_hash }, + only_query: false, + }; + AccountTransaction::Invoke(invoke) + } + SNTransaction::DeployAccount(tx) => { + let contract_address = calculate_contract_address( + tx.contract_address_salt(), + tx.class_hash(), + &tx.constructor_calldata(), + ContractAddress::default(), + ) + .unwrap(); + AccountTransaction::DeployAccount(DeployAccountTransaction { + only_query: false, + tx: starknet_api::executable_transaction::DeployAccountTransaction { + tx, + tx_hash, + contract_address, + }, + }) + } + SNTransaction::Declare(tx) => { + // Fetch the contract_class from the next block (as we don't have it in the previous one) + let next_reader = RpcStateReader::new(network, block_number.next().unwrap()); + + let contract_class = next_reader + .get_compiled_contract_class(tx.class_hash()) + .unwrap(); + + let class_info = calculate_class_info_for_testing(contract_class); + + let declare = DeclareTransaction::new(tx, tx_hash, class_info).unwrap(); + AccountTransaction::Declare(declare) + } + SNTransaction::L1Handler(tx) => { + // As L1Hanlder is not an account transaction we execute it here and return the result + let blockifier_tx = L1HandlerTransaction { + tx, + tx_hash, + paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX), + }; + return ( + blockifier_tx + .execute(&mut state, &block_context, true, true) + .unwrap(), + trace, + receipt, + ); + } + SNTransaction::Deploy(_) => todo!(), + }; + + ( + blockifier_tx + .execute(&mut state, &block_context, true, true) + .unwrap(), + trace, + receipt, + ) +} + +fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo { + let sierra_program_length = match contract_class { + ContractClass::V0(_) => 0, + ContractClass::V1(_) => 100, + ContractClass::V1Native(_) => 100, + }; + ClassInfo::new(&contract_class, sierra_program_length, 100).unwrap() +} + +pub fn execute_tx_configurable_with_state( + tx_hash: &TransactionHash, + tx: SNTransaction, + block_info: BlockInfo, + _skip_validate: bool, + _skip_nonce_check: bool, + charge_fee: bool, + state: &mut CachedState, +) -> TransactionExecutionResult { + let fee_token_address = FeeTokenAddresses { + strk_fee_token_address: ContractAddress( + felt!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d") + .try_into() + .unwrap(), + ), + eth_fee_token_address: ContractAddress( + felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7") + .try_into() + .unwrap(), + ), + }; + + // Get values for block context before giving ownership of the reader + let chain_id = state.state.get_chain_id(); + + let chain_info = ChainInfo { + chain_id: chain_id.clone(), + fee_token_addresses: fee_token_address, + }; + let mut versioned_constants = + VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); + versioned_constants.disable_cairo0_redeclaration = false; + + let block_context = BlockContext::new( + block_info, + chain_info, + versioned_constants, + BouncerConfig::empty(), + ); + + // Get transaction before giving ownership of the reader + let blockifier_tx = match tx { + SNTransaction::Invoke(tx) => { + let invoke = InvokeTransaction { + tx: starknet_api::executable_transaction::InvokeTransaction { + tx, + tx_hash: *tx_hash, + }, + only_query: false, + }; + AccountTransaction::Invoke(invoke) + } + SNTransaction::DeployAccount(tx) => { + let contract_address = calculate_contract_address( + tx.contract_address_salt(), + tx.class_hash(), + &tx.constructor_calldata(), + ContractAddress::default(), + ) + .unwrap(); + AccountTransaction::DeployAccount(DeployAccountTransaction { + only_query: false, + tx: starknet_api::executable_transaction::DeployAccountTransaction { + tx, + tx_hash: *tx_hash, + contract_address, + }, + }) + } + SNTransaction::Declare(tx) => { + let block_number = block_context.block_info().block_number; + let network = parse_to_rpc_chain(&chain_id.to_string()); + // we need to retrieve the next block in order to get the contract_class + let next_reader = RpcStateReader::new(network, block_number.next().unwrap()); + let contract_class = next_reader + .get_compiled_contract_class(tx.class_hash()) + .unwrap(); + let class_info = calculate_class_info_for_testing(contract_class); + + let declare = DeclareTransaction::new(tx, *tx_hash, class_info).unwrap(); + AccountTransaction::Declare(declare) + } + SNTransaction::L1Handler(tx) => { + // As L1Hanlder is not an account transaction we execute it here and return the result + let blockifier_tx = L1HandlerTransaction { + tx, + tx_hash: *tx_hash, + paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX), + }; + return blockifier_tx.execute(state, &block_context, charge_fee, true); + } + _ => unimplemented!(), + }; + + blockifier_tx.execute(state, &block_context, charge_fee, true) +} + +pub fn execute_tx_configurable( + state: &mut CachedState, + tx_hash: &str, + _block_number: BlockNumber, + skip_validate: bool, + skip_nonce_check: bool, + charge_fee: bool, +) -> TransactionExecutionResult<( + TransactionExecutionInfo, + RpcTransactionTrace, + RpcTransactionReceipt, +)> { + let tx_hash = TransactionHash(StarkHash::from_hex(tx_hash).unwrap()); + let tx = state.state.get_transaction(&tx_hash).unwrap(); + let block_info = state.state.get_block_info().unwrap(); + let blockifier_exec_info = execute_tx_configurable_with_state( + &tx_hash, + tx, + block_info, + skip_validate, + skip_nonce_check, + charge_fee, + state, + )?; + let trace = state.state.get_transaction_trace(&tx_hash).unwrap(); + let receipt = state.state.get_transaction_receipt(&tx_hash).unwrap(); + Ok((blockifier_exec_info, trace, receipt)) +} + +/// Executes a transaction with blockifier +/// +/// Unlike `execute_tx_configurable`, it does not depend on our state reader +/// and can be used with any cached state. It already receives all context information +/// needed to execute the transaction. +pub fn execute_tx_with_blockifier( + state: &mut CachedState, + context: BlockContext, + transaction: SNTransaction, + transaction_hash: TransactionHash, +) -> TransactionExecutionResult { + let account_transaction: AccountTransaction = match transaction { + SNTransaction::Invoke(tx) => { + let invoke = InvokeTransaction { + tx: starknet_api::executable_transaction::InvokeTransaction { + tx, + tx_hash: transaction_hash, + }, + only_query: false, + }; + AccountTransaction::Invoke(invoke) + } + SNTransaction::DeployAccount(tx) => { + let contract_address = calculate_contract_address( + tx.contract_address_salt(), + tx.class_hash(), + &tx.constructor_calldata(), + ContractAddress::default(), + ) + .unwrap(); + AccountTransaction::DeployAccount(DeployAccountTransaction { + only_query: false, + tx: starknet_api::executable_transaction::DeployAccountTransaction { + tx, + tx_hash: transaction_hash, + contract_address, + }, + }) + } + SNTransaction::Declare(tx) => { + let contract_class = state + .state + .get_compiled_contract_class(tx.class_hash()) + .unwrap(); + + let class_info = calculate_class_info_for_testing(contract_class); + + let declare = DeclareTransaction::new(tx, transaction_hash, class_info).unwrap(); + AccountTransaction::Declare(declare) + } + SNTransaction::L1Handler(tx) => { + // As L1Hanlder is not an account transaction we execute it here and return the result + let account_transaction = L1HandlerTransaction { + tx, + tx_hash: transaction_hash, + paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX), + }; + + return account_transaction.execute(state, &context, true, true); + } + _ => unimplemented!(), + }; + + account_transaction.execute(state, &context, true, true) +} + +fn parse_to_rpc_chain(network: &str) -> RpcChain { + match network { + "alpha-mainnet" => RpcChain::MainNet, + "alpha4" => RpcChain::TestNet, + "alpha4-2" => RpcChain::TestNet2, + _ => panic!("Invalid network name {}", network), + } +} + +pub fn fetch_block_context(state: &RpcState, block_number: BlockNumber) -> BlockContext { + let rpc_block_info = state.get_block_info().unwrap(); + let gas_price = state.get_gas_price(block_number.0).unwrap(); + let mut versioned_constants = + VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); + versioned_constants.disable_cairo0_redeclaration = false; + + let fee_token_addresses = FeeTokenAddresses { + strk_fee_token_address: ContractAddress( + felt!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d") + .try_into() + .unwrap(), + ), + eth_fee_token_address: ContractAddress( + felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7") + .try_into() + .unwrap(), + ), + }; + + BlockContext::new( + BlockInfo { + block_number, + block_timestamp: rpc_block_info.block_timestamp, + sequencer_address: rpc_block_info.sequencer_address, + gas_prices: gas_price, + use_kzg_da: false, + }, + ChainInfo { + chain_id: state.get_chain_name(), + fee_token_addresses, + }, + versioned_constants, + BouncerConfig::empty(), + ) +} + +#[cfg(test)] +mod tests { + use blockifier::{ + execution::call_info::CallInfo, + state::cached_state::StateChangesCount, + transaction::objects::{GasVector, StarknetResources}, + }; + use pretty_assertions_sorted::assert_eq_sorted; + use starknet_api::block::BlockNumber; + use test_case::test_case; + + use super::*; + use crate::{objects::RpcCallInfo, reader::RpcChain}; + + #[test_case( + "0x00b6d59c19d5178886b4c939656167db0660fe325345138025a3cc4175b21897", + 200304, + RpcChain::MainNet + => ignore["Doesn't revert in newest blockifier version"] + )] + #[test_case( + "0x02b28b4846a756e0cec6385d6d13f811e745a88c7e75a3ebc5fead5b4af152a3", + 200303, + RpcChain::MainNet + => ignore["broken on both due to a cairo-vm error"] + )] + fn blockifier_test_case_reverted_tx(hash: &str, block_number: u64, chain: RpcChain) { + // To reexecute a transaction, we must use the state from its previous block + let previous_block = BlockNumber(block_number - 1); + let (tx_info, trace, _) = execute_tx(hash, chain, previous_block); + + assert_eq!( + tx_info.revert_error, + trace.execute_invocation.unwrap().revert_reason + ); + + // We can't currently compare fee values + } + + #[test_case( + // Declare tx + "0x60506c49e65d84e2cdd0e9142dc43832a0a59cb6a9cbcce1ab4f57c20ba4afb", + 347900, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x014640564509873cf9d24a311e1207040c8b60efd38d96caef79855f0b0075d5", + 90007, + RpcChain::MainNet + )] + #[test_case( + "0x025844447697eb7d5df4d8268b23aef6c11de4087936048278c2559fc35549eb", + 197001, + RpcChain::MainNet + )] + #[test_case( + "0x00164bfc80755f62de97ae7c98c9d67c1767259427bcf4ccfcc9683d44d54676", + 197001, + RpcChain::MainNet + )] + #[test_case( + "0x05d200ef175ba15d676a68b36f7a7b72c17c17604eda4c1efc2ed5e4973e2c91", + 169929, + RpcChain::MainNet + )] + #[test_case( + "0x0528ec457cf8757f3eefdf3f0728ed09feeecc50fd97b1e4c5da94e27e9aa1d6", + 169929, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x0737677385a30ec4cbf9f6d23e74479926975b74db3d55dc5e46f4f8efee41cf", + 169929, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x026c17728b9cd08a061b1f17f08034eb70df58c1a96421e73ee6738ad258a94c", + 169929, + RpcChain::MainNet + )] + #[test_case( + // review later + "0x0743092843086fa6d7f4a296a226ee23766b8acf16728aef7195ce5414dc4d84", + 186549, + RpcChain::MainNet + )] + #[test_case( + // fails in blockifier + "0x00724fc4a84f489ed032ebccebfc9541eb8dc64b0e76b933ed6fc30cd6000bd1", + 186552, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x176a92e8df0128d47f24eebc17174363457a956fa233cc6a7f8561bfbd5023a", + 317093, + RpcChain::MainNet + )] + #[test_case( + "0x04db9b88e07340d18d53b8b876f28f449f77526224afb372daaf1023c8b08036", + 398052, + RpcChain::MainNet + )] + #[test_case( + "0x5a5de1f42f6005f3511ea6099daed9bcbcf9de334ee714e8563977e25f71601", + 281514, + RpcChain::MainNet + )] + #[test_case( + "0x26be3e906db66973de1ca5eec1ddb4f30e3087dbdce9560778937071c3d3a83", + 351269, + RpcChain::MainNet + )] + #[test_case( + "0x4f552c9430bd21ad300db56c8f4cae45d554a18fac20bf1703f180fac587d7e", + 351226, + RpcChain::MainNet + )] + // DeployAccount for different account providers: + + // OpenZeppelin (v0.7.0) + #[test_case( + "0x04df8a364233d995c33c7f4666a776bf458631bec2633e932b433a783db410f8", + 422882, + RpcChain::MainNet + )] + // Argent X (v5.7.0) + #[test_case( + "0x74820d4a1ac6e832a51a8938959e6f15a247f7d34daea2860d4880c27bc2dfd", + 475946, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x41497e62fb6798ff66e4ad736121c0164cdb74005aa5dab025be3d90ad4ba06", + 638867, + RpcChain::MainNet + )] + #[test_case( + "0x7805c2bf5abaf4fe0eb1db7b7be0486a14757b4bf96634c828d11c07e4a763c", + 641976, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x73ef9cde09f005ff6f411de510ecad4cdcf6c4d0dfc59137cff34a4fc74dfd", + 654001, + RpcChain::MainNet + )] + #[test_case( + "0x75d7ef42a815e4d9442efcb509baa2035c78ea6a6272ae29e87885788d4c85e", + 654001, + RpcChain::MainNet + )] + #[test_case( + "0x1ecb4b825f629eeb9816ddfd6905a85f6d2c89995907eacaf6dc64e27a2c917", + 654001, + RpcChain::MainNet + )] + #[test_case( + "0x70d83cb9e25f1e9f7be2608f72c7000796e4a222c1ed79a0ea81abe5172557b", + 654001, + RpcChain::MainNet + )] + #[test_case( + "0x670321c71835004fcab639e871ef402bb807351d126ccc4d93075ff2c31519d", + 654001, + RpcChain::MainNet + )] + #[test_case( + "0x5896b4db732cfc57ce5d56ece4dfa4a514bd435a0ee80dc79b37e60cdae5dd6", + 653001, + RpcChain::MainNet + => ignore["takes to long"] + )] + #[test_case( + "0x5a030fd81f14a1cf29a2e5259d3f2c9960018ade2d135269760e6fb4802ac02", + 653001, + RpcChain::MainNet + => ignore["halts execution"] + )] + #[test_case( + "0x2d2bed435d0b43a820443aad2bc9e3d4fa110c428e65e422101dfa100ba5664", + 653001, + RpcChain::MainNet + => ignore + )] + #[test_case( + "0x3330b29e8b99dedef79f5c7cdc2b510c590155add29dcc5e2f92d176d8e19d", + 653001, + RpcChain::MainNet + => ignore + )] + fn blockifier_tx(hash: &str, block_number: u64, chain: RpcChain) { + // To reexecute a transaction, we must use the state from its previous block + let previous_block = BlockNumber(block_number - 1); + let (tx_info, trace, _receipt) = execute_tx(hash, chain, previous_block); + + // We cannot currently check fee & resources + + // Compare tx CallInfos against trace RpcCallInfos + // Note: This will check calldata, retdata, internal calls and make sure the tx is not reverted. + // It will not chekced accessed or modified storage, messanges, and events (as they are not currenlty part of the RpcCallInfo) + assert_eq_sorted!( + tx_info.validate_call_info.map(|ref ci| ci.into()), + trace.validate_invocation + ); + assert_eq_sorted!( + tx_info.execute_call_info.map(|ref ci| ci.into()), + trace.execute_invocation + ); + //assert_eq!(tx_info.fee_transfer_call_info.map(|ref ci| ci.into()), trace.fee_transfer_invocation); TODO: fix charge_fee + } + + // test cairo-vm's tx execution against cairo-native, using only_cairo_vm feature + #[test_case( + "0x04ba569a40a866fd1cbb2f3d3ba37ef68fb91267a4931a377d6acc6e5a854f9a", + 648462, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 192, l2_gas: 0 }, + 7, + 3, + 0, + None, + StateChangesCount { + n_storage_updates: 2, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 1, + }, + false + )] + #[test_case( + "0x0355059efee7a38ba1fd5aef13d261914608dce7bdfacad92a71e396f0ad7a77", + 661815, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, + 9, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 3, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x05324bac55fb9fb53e738195c2dcc1e7fed1334b6db824665e3e984293bec95e", + 662246, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, + 9, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 3, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x670321c71835004fcab639e871ef402bb807351d126ccc4d93075ff2c31519d", + 654001, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, + 7, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 3, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x06962f11a96849ebf05cd222313858a93a8c5f300493ed6c5859dd44f5f2b4e3", + 654770, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, + 7, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 3, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x078b81326882ecd2dc6c5f844527c3f33e0cdb52701ded7b1aa4d220c5264f72", + 653019, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 640, l2_gas: 0 }, + 28, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 7, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 3, + }, + false + )] + #[test_case( + "0x0780e3a498b4fd91ab458673891d3e8ee1453f9161f4bfcb93dd1e2c91c52e10", + 650558, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 448, l2_gas: 0 }, + 24, + 3, + 0, + None, + StateChangesCount { + n_storage_updates: 4, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 3, + }, + false + )] + #[test_case( + "0x4f552c9430bd21ad300db56c8f4cae45d554a18fac20bf1703f180fac587d7e", + 351226, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 3, + 0, + 0, + Some(3), + StateChangesCount { + n_storage_updates: 2, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 0, + }, + false + )] + #[test_case( + "0x176a92e8df0128d47f24eebc17174363457a956fa233cc6a7f8561bfbd5023a", + 317093, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 6, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 1, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 1, + }, + false + )] + #[test_case( + "0x026c17728b9cd08a061b1f17f08034eb70df58c1a96421e73ee6738ad258a94c", + 169929, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 8, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 1, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 1, + }, + false + )] + #[test_case( + "0x73ef9cde09f005ff6f411de510ecad4cdcf6c4d0dfc59137cff34a4fc74dfd", + 654001, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 5, + 0, + 0, + Some(5), + StateChangesCount { + n_storage_updates: 2, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 0, + }, + false + )] + #[test_case( + "0x0743092843086fa6d7f4a296a226ee23766b8acf16728aef7195ce5414dc4d84", + 186549, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 384, l2_gas: 0 }, + 7, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 4, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x066e1f01420d8e433f6ef64309adb1a830e5af0ea67e3d935de273ca57b3ae5e", + 662252, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 448, l2_gas: 0 }, + 18, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 5, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + // Check this tx, l1_data_gas should be 384 + // https://starkscan.co/tx/0x04756d898323a8f884f5a6aabd6834677f4bbaeecc2522f18b3ae45b3f99cd1e + #[test_case( + "0x04756d898323a8f884f5a6aabd6834677f4bbaeecc2522f18b3ae45b3f99cd1e", + 662250, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 10, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 1, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 1, + }, + false + )] + #[test_case( + "0x00f390691fd9e865f5aef9c7cc99889fb6c2038bc9b7e270e8a4fe224ccd404d", + 662251, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 256, l2_gas: 0 }, + 12, + 5, + 0, + None, + StateChangesCount { + n_storage_updates: 2, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x26be3e906db66973de1ca5eec1ddb4f30e3087dbdce9560778937071c3d3a83", + 351269, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 3, + 0, + 0, + Some(3), + StateChangesCount { + n_storage_updates: 2, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 0, + }, + false + )] + #[test_case( + "0x0310c46edc795c82c71f600159fa9e6c6540cb294df9d156f685bfe62b31a5f4", + 662249, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 640, l2_gas: 0 }, + 37, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 7, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 3, + }, + false + )] + #[test_case( + "0x06a09ffbf996178ac6e90101047e42fe29cb7108573b2ecf4b0ebd2cba544cb4", + 662248, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 384, l2_gas: 0 }, + 4, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 4, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 2, + }, + false + )] + #[test_case( + "0x026e04e96ba1b75bfd066c8e138e17717ecb654909e6ac24007b644ac23e4b47", + 536893, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 896, l2_gas: 0 }, + 24, + 4, + 0, + None, + StateChangesCount { + n_storage_updates: 10, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 4, + }, + false + )] + #[test_case( + "0x01351387ef63fd6fe5ec10fa57df9e006b2450b8c68d7eec8cfc7d220abc7eda", + 644700, + RpcChain::MainNet, + GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, + 8, + 2, + 0, + None, + StateChangesCount { + n_storage_updates: 1, + n_class_hash_updates: 0, + n_compiled_class_hash_updates: 0, + n_modified_contracts: 1, + }, + true + )] + #[allow(clippy::too_many_arguments)] + fn test_transaction_info( + hash: &str, + block_number: u64, + chain: RpcChain, + da_gas: GasVector, + calldata_length: usize, + signature_length: usize, + code_size: usize, + l1_handler_payload_size: Option, + starknet_chg: StateChangesCount, + is_reverted: bool, + ) { + let previous_block = BlockNumber(block_number - 1); + let (tx_info, _, _) = execute_tx(hash, chain, previous_block); + let tx_receipt = tx_info.receipt; + let starknet_resources = tx_receipt.resources.starknet_resources; + let callinfo_iter = match tx_info.execute_call_info { + Some(c) => vec![c], + None => vec![CallInfo::default()], // there's no call info, so we take the default value to have all of it's atributes set to 0 + }; + let starknet_rsc = StarknetResources::new( + calldata_length, + signature_length, + code_size, + starknet_chg, + l1_handler_payload_size, + callinfo_iter.iter(), + ); + + assert_eq!(is_reverted, tx_info.revert_error.is_some()); + assert_eq!(da_gas, tx_receipt.da_gas); + assert_eq!(starknet_rsc, starknet_resources); + } + + // Impl conversion for easier checking against RPC data + impl From<&CallInfo> for RpcCallInfo { + fn from(value: &CallInfo) -> Self { + Self { + result: Some(value.execution.retdata.0.clone()), + calldata: Some((*value.call.calldata.0).clone()), + calls: value.inner_calls.iter().map(|ci| ci.into()).collect(), + // We don't have the revert reason string in the trace so we just make sure it doesn't revert + revert_reason: value.execution.failed.then_some("Default String".into()), + } + } + } +} diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index 601f651..22b5d2f 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -1,3 +1,4 @@ +pub mod execution; pub mod objects; pub mod reader; From a041814d9e9a5802d856b46cce1a5ab4468be3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 19:05:41 -0300 Subject: [PATCH 14/31] Use kzg_da always --- rpc-state-reader/src/reader.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index d5f9c85..3e04601 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -12,7 +12,6 @@ use starknet::core::types::ContractClass as SNContractClass; use starknet_api::{ block::{BlockNumber, GasPrice}, core::{ChainId, ClassHash, CompiledClassHash, ContractAddress}, - data_availability::L1DataAvailabilityMode, state::StorageKey, transaction::{Transaction, TransactionHash}, }; @@ -122,7 +121,7 @@ impl RpcStateReader { // This function is inspired by sequencer's RpcStateReader::get_block_info fn parse_gas_price(price: GasPrice) -> NonZeroU128 { - NonZeroU128::new(price.0).unwrap_or(NonZeroU128::new(1).unwrap()) + NonZeroU128::new(price.0).unwrap_or(NonZeroU128::MIN) } let params = GetBlockWithTxHashesParams { @@ -147,7 +146,7 @@ impl RpcStateReader { NonZeroU128::MIN, NonZeroU128::MIN, ), - use_kzg_da: matches!(header.l1_da_mode, L1DataAvailabilityMode::Blob), + use_kzg_da: true, }) } From 4d35873fd19ce6d60b71fbc356da3e7438ebd5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 22 Oct 2024 19:20:40 -0300 Subject: [PATCH 15/31] Fix bug --- rpc-state-reader/src/utils.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rpc-state-reader/src/utils.rs b/rpc-state-reader/src/utils.rs index d78dca0..3986857 100644 --- a/rpc-state-reader/src/utils.rs +++ b/rpc-state-reader/src/utils.rs @@ -72,8 +72,19 @@ pub fn decode_reader(bytes: Vec) -> io::Result { /// Freestanding deserialize method to avoid a new type. pub fn deserialize_transaction_json( - transaction: serde_json::Value, + mut transaction: serde_json::Value, ) -> serde_json::Result { + if let Some(resource_bounds) = transaction.get_mut("resource_bounds") { + if let Some(l1_gas) = resource_bounds.get_mut("l1_gas") { + resource_bounds["L1_GAS"] = l1_gas.clone(); + resource_bounds.as_object_mut().unwrap().remove("l1_gas"); + } + if let Some(l2_gas) = resource_bounds.get_mut("l2_gas") { + resource_bounds["L2_GAS"] = l2_gas.clone(); + resource_bounds.as_object_mut().unwrap().remove("l2_gas"); + } + } + let tx_type: String = serde_json::from_value(transaction["type"].clone())?; let tx_version: String = serde_json::from_value(transaction["version"].clone())?; From 2fbed3a7b834fe2d00ef60c65df4444a8b6f231f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 11:50:23 -0300 Subject: [PATCH 16/31] Skip serialization of calls --- rpc-state-reader/src/objects.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs index 81940a9..bbb2c2d 100644 --- a/rpc-state-reader/src/objects.rs +++ b/rpc-state-reader/src/objects.rs @@ -27,6 +27,7 @@ pub struct RpcTransactionTrace { pub struct RpcCallInfo { pub result: Option>, pub calldata: Option>, + #[serde(skip_serializing_if = "Vec::is_empty", default)] pub calls: Vec, pub revert_reason: Option, } From e74330ca6ccd7819eb202dc8061dc1bd46a14933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 11:50:36 -0300 Subject: [PATCH 17/31] Add default if err on some rpc calls --- rpc-state-reader/src/reader.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index 3e04601..0a1d050 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -212,18 +212,27 @@ impl StateReader for RpcStateReader { contract_address: ContractAddress, key: StorageKey, ) -> StateResult { - self.inner.get_storage_at(contract_address, key) + Ok(self + .inner + .get_storage_at(contract_address, key) + .unwrap_or_default()) } fn get_nonce_at( &self, contract_address: ContractAddress, ) -> StateResult { - self.inner.get_nonce_at(contract_address) + Ok(self + .inner + .get_nonce_at(contract_address) + .unwrap_or_default()) } fn get_class_hash_at(&self, contract_address: ContractAddress) -> StateResult { - self.inner.get_class_hash_at(contract_address) + Ok(self + .inner + .get_class_hash_at(contract_address) + .unwrap_or_default()) } fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { From 5d27a6bceaf395fcd611ff6be6444824ca672741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 11:51:31 -0300 Subject: [PATCH 18/31] Remove old files --- .../src/blockifier_state_reader.rs | 1146 ----------------- rpc-state-reader/src/rpc_state.rs | 685 ---------- rpc-state-reader/src/rpc_state_errors.rs | 27 - 3 files changed, 1858 deletions(-) delete mode 100644 rpc-state-reader/src/blockifier_state_reader.rs delete mode 100644 rpc-state-reader/src/rpc_state.rs delete mode 100644 rpc-state-reader/src/rpc_state_errors.rs diff --git a/rpc-state-reader/src/blockifier_state_reader.rs b/rpc-state-reader/src/blockifier_state_reader.rs deleted file mode 100644 index 99245fb..0000000 --- a/rpc-state-reader/src/blockifier_state_reader.rs +++ /dev/null @@ -1,1146 +0,0 @@ -use blockifier::{ - blockifier::block::BlockInfo, - bouncer::BouncerConfig, - context::{BlockContext, ChainInfo, FeeTokenAddresses}, - execution::contract_class::{ - ClassInfo, ContractClass, ContractClassV0, ContractClassV0Inner, NativeContractClassV1, - }, - state::{ - cached_state::CachedState, - errors::StateError, - state_api::{StateReader, StateResult}, - }, - transaction::{ - account_transaction::AccountTransaction, - objects::{TransactionExecutionInfo, TransactionExecutionResult}, - transactions::{ - DeclareTransaction, DeployAccountTransaction, ExecutableTransaction, InvokeTransaction, - L1HandlerTransaction, - }, - }, - versioned_constants::VersionedConstants, -}; - -use cairo_vm::types::program::Program; -use starknet::core::types::ContractClass as SNContractClass; -use starknet_api::{ - block::BlockNumber, - core::{calculate_contract_address, ClassHash, CompiledClassHash, ContractAddress, Nonce}, - felt, - hash::StarkHash, - state::StorageKey, - transaction::{Transaction as SNTransaction, TransactionHash}, -}; -use std::sync::Arc; - -use crate::{ - rpc_state::{RpcBlockInfo, RpcChain, RpcState, RpcTransactionReceipt, TransactionTrace}, - utils::{self, get_native_executor}, -}; - -pub struct RpcStateReader(pub RpcState); - -impl RpcStateReader { - pub fn new(state: RpcState) -> Self { - Self(state) - } -} - -impl StateReader for RpcStateReader { - fn get_storage_at( - &self, - contract_address: starknet_api::core::ContractAddress, - key: StorageKey, - ) -> StateResult { - Ok(self.0.get_storage_at(&contract_address, &key)) - } - - fn get_nonce_at(&self, contract_address: ContractAddress) -> StateResult { - Ok(Nonce(self.0.get_nonce_at(&contract_address))) - } - - fn get_class_hash_at(&self, contract_address: ContractAddress) -> StateResult { - Ok(self.0.get_class_hash_at(&contract_address)) - } - - /// Returns the contract class of the given class hash. - fn get_compiled_contract_class( - &self, - class_hash: starknet_api::core::ClassHash, - ) -> StateResult { - Ok(match self.0.get_contract_class(&class_hash) { - Some(SNContractClass::Legacy(compressed_legacy_cc)) => { - let as_str = utils::decode_reader(compressed_legacy_cc.program).unwrap(); - let program = Program::from_bytes(as_str.as_bytes(), None).unwrap(); - let entry_points_by_type = utils::map_entry_points_by_type_legacy( - compressed_legacy_cc.entry_points_by_type, - ); - let inner = Arc::new(ContractClassV0Inner { - program, - entry_points_by_type, - }); - ContractClass::V0(ContractClassV0(inner)) - } - Some(SNContractClass::Sierra(flattened_sierra_cc)) => { - let middle_sierra: utils::MiddleSierraContractClass = { - let v = serde_json::to_value(flattened_sierra_cc).unwrap(); - serde_json::from_value(v).unwrap() - }; - let sierra_cc = cairo_lang_starknet_classes::contract_class::ContractClass { - sierra_program: middle_sierra.sierra_program, - contract_class_version: middle_sierra.contract_class_version, - entry_points_by_type: middle_sierra.entry_points_by_type, - sierra_program_debug_info: None, - abi: None, - }; - - if cfg!(feature = "only_casm") { - let casm_cc = - cairo_lang_starknet_classes::casm_contract_class::CasmContractClass::from_contract_class(sierra_cc, false, usize::MAX).unwrap(); - ContractClass::V1(casm_cc.try_into().unwrap()) - } else { - let program = sierra_cc.extract_sierra_program().unwrap(); - let executor = get_native_executor(program, class_hash); - - ContractClass::V1Native( - NativeContractClassV1::new(executor, sierra_cc).unwrap(), - ) - } - } - None => { - return Err(StateError::UndeclaredClassHash( - starknet_api::core::ClassHash(*class_hash), - )) - } - }) - } - - /// Returns the compiled class hash of the given class hash. - fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult { - Ok(CompiledClassHash( - self.0 - .get_class_hash_at(&ContractAddress(class_hash.0.try_into().unwrap())) - .0, - )) - } -} - -pub fn execute_tx( - tx_hash: &str, - network: RpcChain, - block_number: BlockNumber, -) -> ( - TransactionExecutionInfo, - TransactionTrace, - RpcTransactionReceipt, -) { - let tx_hash = tx_hash.strip_prefix("0x").unwrap(); - - // Instantiate the RPC StateReader and the CachedState - let rpc_reader = RpcStateReader(RpcState::new_rpc(network, block_number.into()).unwrap()); - let gas_price = rpc_reader.0.get_gas_price(block_number.0).unwrap(); - - // Get values for block context before giving ownership of the reader - let chain_id = rpc_reader.0.get_chain_name(); - let RpcBlockInfo { - block_number, - block_timestamp, - sequencer_address, - .. - } = rpc_reader.0.get_block_info().unwrap(); - - // Get transaction before giving ownership of the reader - let tx_hash = TransactionHash(StarkHash::from_hex(tx_hash).unwrap()); - let sn_api_tx = rpc_reader.0.get_transaction(&tx_hash); - - let trace = rpc_reader.0.get_transaction_trace(&tx_hash).unwrap(); - let receipt = rpc_reader.0.get_transaction_receipt(&tx_hash).unwrap(); - - // Create state from RPC reader - let mut state = CachedState::new(rpc_reader); - - let block_info = BlockInfo { - block_number, - block_timestamp, - sequencer_address, - gas_prices: gas_price, - use_kzg_da: true, - }; - - let fee_token_addresses = FeeTokenAddresses { - strk_fee_token_address: ContractAddress( - felt!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d") - .try_into() - .unwrap(), - ), - eth_fee_token_address: ContractAddress( - felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7") - .try_into() - .unwrap(), - ), - }; - let chain_info = ChainInfo { - chain_id, - fee_token_addresses, - }; - let mut versioned_constants = - VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); - versioned_constants.disable_cairo0_redeclaration = false; - - let block_context = BlockContext::new( - block_info, - chain_info, - versioned_constants, - BouncerConfig::empty(), - ); - - // Map starknet_api transaction to blockifier's - let blockifier_tx: AccountTransaction = match sn_api_tx.unwrap() { - SNTransaction::Invoke(tx) => { - let invoke = InvokeTransaction { - tx: starknet_api::executable_transaction::InvokeTransaction { tx, tx_hash }, - only_query: false, - }; - AccountTransaction::Invoke(invoke) - } - SNTransaction::DeployAccount(tx) => { - let contract_address = calculate_contract_address( - tx.contract_address_salt(), - tx.class_hash(), - &tx.constructor_calldata(), - ContractAddress::default(), - ) - .unwrap(); - AccountTransaction::DeployAccount(DeployAccountTransaction { - only_query: false, - tx: starknet_api::executable_transaction::DeployAccountTransaction { - tx, - tx_hash, - contract_address, - }, - }) - } - SNTransaction::Declare(tx) => { - // Fetch the contract_class from the next block (as we don't have it in the previous one) - let next_block_state_reader = RpcStateReader( - RpcState::new_rpc(network, (block_number.next()).unwrap().into()).unwrap(), - ); - let contract_class = next_block_state_reader - .get_compiled_contract_class(tx.class_hash()) - .unwrap(); - - let class_info = calculate_class_info_for_testing(contract_class); - - let declare = DeclareTransaction::new(tx, tx_hash, class_info).unwrap(); - AccountTransaction::Declare(declare) - } - SNTransaction::L1Handler(tx) => { - // As L1Hanlder is not an account transaction we execute it here and return the result - let blockifier_tx = L1HandlerTransaction { - tx, - tx_hash, - paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX), - }; - return ( - blockifier_tx - .execute(&mut state, &block_context, true, true) - .unwrap(), - trace, - receipt, - ); - } - _ => unimplemented!(), - }; - - ( - blockifier_tx - .execute(&mut state, &block_context, true, true) - .unwrap(), - trace, - receipt, - ) -} - -fn calculate_class_info_for_testing(contract_class: ContractClass) -> ClassInfo { - let sierra_program_length = match contract_class { - ContractClass::V0(_) => 0, - ContractClass::V1(_) => 100, - ContractClass::V1Native(_) => 100, - }; - ClassInfo::new(&contract_class, sierra_program_length, 100).unwrap() -} - -pub fn execute_tx_configurable_with_state( - tx_hash: &TransactionHash, - tx: SNTransaction, - block_info: BlockInfo, - _skip_validate: bool, - _skip_nonce_check: bool, - charge_fee: bool, - state: &mut CachedState, -) -> TransactionExecutionResult { - let fee_token_address = FeeTokenAddresses { - strk_fee_token_address: ContractAddress( - felt!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d") - .try_into() - .unwrap(), - ), - eth_fee_token_address: ContractAddress( - felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7") - .try_into() - .unwrap(), - ), - }; - - // Get values for block context before giving ownership of the reader - let chain_id = state.state.0.get_chain_name(); - - let chain_info = ChainInfo { - chain_id: chain_id.clone(), - fee_token_addresses: fee_token_address, - }; - let mut versioned_constants = - VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); - versioned_constants.disable_cairo0_redeclaration = false; - - let block_context = BlockContext::new( - block_info, - chain_info, - versioned_constants, - BouncerConfig::empty(), - ); - - // Get transaction before giving ownership of the reader - let blockifier_tx: AccountTransaction = match tx { - SNTransaction::Invoke(tx) => { - let invoke = InvokeTransaction { - tx: starknet_api::executable_transaction::InvokeTransaction { - tx, - tx_hash: *tx_hash, - }, - only_query: false, - }; - AccountTransaction::Invoke(invoke) - } - SNTransaction::DeployAccount(tx) => { - let contract_address = calculate_contract_address( - tx.contract_address_salt(), - tx.class_hash(), - &tx.constructor_calldata(), - ContractAddress::default(), - ) - .unwrap(); - AccountTransaction::DeployAccount(DeployAccountTransaction { - only_query: false, - tx: starknet_api::executable_transaction::DeployAccountTransaction { - tx, - tx_hash: *tx_hash, - contract_address, - }, - }) - } - SNTransaction::Declare(tx) => { - let block_number = block_context.block_info().block_number; - let network = parse_to_rpc_chain(&chain_id.to_string()); - // we need to retrieve the next block in order to get the contract_class - let next_block_state_reader = RpcStateReader( - RpcState::new_rpc(network, (block_number.next()).unwrap().into()).unwrap(), - ); - let contract_class = next_block_state_reader - .get_compiled_contract_class(tx.class_hash()) - .unwrap(); - let class_info = calculate_class_info_for_testing(contract_class); - - let declare = DeclareTransaction::new(tx, *tx_hash, class_info).unwrap(); - AccountTransaction::Declare(declare) - } - SNTransaction::L1Handler(tx) => { - // As L1Hanlder is not an account transaction we execute it here and return the result - let blockifier_tx = L1HandlerTransaction { - tx, - tx_hash: *tx_hash, - paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX), - }; - return blockifier_tx.execute(state, &block_context, charge_fee, true); - } - _ => unimplemented!(), - }; - - blockifier_tx.execute(state, &block_context, charge_fee, true) -} - -pub fn execute_tx_configurable( - state: &mut CachedState, - tx_hash: &str, - block_number: BlockNumber, - skip_validate: bool, - skip_nonce_check: bool, - charge_fee: bool, -) -> TransactionExecutionResult<( - TransactionExecutionInfo, - TransactionTrace, - RpcTransactionReceipt, -)> { - let tx_hash = TransactionHash(StarkHash::from_hex(tx_hash).unwrap()); - let tx = state.state.0.get_transaction(&tx_hash).unwrap(); - let gas_price = state.state.0.get_gas_price(block_number.0).unwrap(); - let RpcBlockInfo { - block_timestamp, - sequencer_address, - .. - } = state.state.0.get_block_info().unwrap(); - - let block_info = BlockInfo { - block_number, - block_timestamp, - sequencer_address, - gas_prices: gas_price, - use_kzg_da: true, - }; - let blockifier_exec_info = execute_tx_configurable_with_state( - &tx_hash, - tx, - block_info, - skip_validate, - skip_nonce_check, - charge_fee, - state, - )?; - let trace = state.state.0.get_transaction_trace(&tx_hash).unwrap(); - let receipt = state.state.0.get_transaction_receipt(&tx_hash).unwrap(); - Ok((blockifier_exec_info, trace, receipt)) -} - -/// Executes a transaction with blockifier -/// -/// Unlike `execute_tx_configurable`, it does not depend on our state reader -/// and can be used with any cached state. It already receives all context information -/// needed to execute the transaction. -pub fn execute_tx_with_blockifier( - state: &mut CachedState, - context: BlockContext, - transaction: SNTransaction, - transaction_hash: TransactionHash, -) -> TransactionExecutionResult { - let account_transaction: AccountTransaction = match transaction { - SNTransaction::Invoke(tx) => { - let invoke = InvokeTransaction { - tx: starknet_api::executable_transaction::InvokeTransaction { - tx, - tx_hash: transaction_hash, - }, - only_query: false, - }; - AccountTransaction::Invoke(invoke) - } - SNTransaction::DeployAccount(tx) => { - let contract_address = calculate_contract_address( - tx.contract_address_salt(), - tx.class_hash(), - &tx.constructor_calldata(), - ContractAddress::default(), - ) - .unwrap(); - AccountTransaction::DeployAccount(DeployAccountTransaction { - only_query: false, - tx: starknet_api::executable_transaction::DeployAccountTransaction { - tx, - tx_hash: transaction_hash, - contract_address, - }, - }) - } - SNTransaction::Declare(tx) => { - let contract_class = state - .state - .get_compiled_contract_class(tx.class_hash()) - .unwrap(); - - let class_info = calculate_class_info_for_testing(contract_class); - - let declare = DeclareTransaction::new(tx, transaction_hash, class_info).unwrap(); - AccountTransaction::Declare(declare) - } - SNTransaction::L1Handler(tx) => { - // As L1Hanlder is not an account transaction we execute it here and return the result - let account_transaction = L1HandlerTransaction { - tx, - tx_hash: transaction_hash, - paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX), - }; - - return account_transaction.execute(state, &context, true, true); - } - _ => unimplemented!(), - }; - - account_transaction.execute(state, &context, true, true) -} - -fn parse_to_rpc_chain(network: &str) -> RpcChain { - match network { - "alpha-mainnet" => RpcChain::MainNet, - "alpha4" => RpcChain::TestNet, - "alpha4-2" => RpcChain::TestNet2, - _ => panic!("Invalid network name {}", network), - } -} - -pub fn fetch_block_context(state: &RpcState, block_number: BlockNumber) -> BlockContext { - let rpc_block_info = state.get_block_info().unwrap(); - let gas_price = state.get_gas_price(block_number.0).unwrap(); - let mut versioned_constants = - VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); - versioned_constants.disable_cairo0_redeclaration = false; - - let fee_token_addresses = FeeTokenAddresses { - strk_fee_token_address: ContractAddress( - felt!("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d") - .try_into() - .unwrap(), - ), - eth_fee_token_address: ContractAddress( - felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7") - .try_into() - .unwrap(), - ), - }; - - BlockContext::new( - BlockInfo { - block_number, - block_timestamp: rpc_block_info.block_timestamp, - sequencer_address: rpc_block_info.sequencer_address, - gas_prices: gas_price, - use_kzg_da: false, - }, - ChainInfo { - chain_id: state.get_chain_name(), - fee_token_addresses, - }, - versioned_constants, - BouncerConfig::empty(), - ) -} - -#[cfg(test)] -mod tests { - - use std::num::NonZeroU128; - - use crate::rpc_state::{BlockValue, RpcCallInfo}; - - use super::*; - use blockifier::{ - execution::call_info::CallInfo, - state::cached_state::StateChangesCount, - transaction::objects::{GasVector, StarknetResources}, - }; - use pretty_assertions_sorted::assert_eq_sorted; - use test_case::test_case; - #[test] - fn test_get_gas_price() { - let block = BlockValue::Number(BlockNumber(169928)); - let rpc_state = RpcState::new_rpc(RpcChain::MainNet, block).unwrap(); - - let price = rpc_state.get_gas_price(169928).unwrap(); - assert_eq!( - price.get_l1_gas_price_by_fee_type(&blockifier::transaction::objects::FeeType::Eth), - NonZeroU128::new(22804578690).unwrap() - ); - } - - #[test_case( - "0x00b6d59c19d5178886b4c939656167db0660fe325345138025a3cc4175b21897", - 200304, - RpcChain::MainNet - => ignore["Doesn't revert in newest blockifier version"] - )] - #[test_case( - "0x02b28b4846a756e0cec6385d6d13f811e745a88c7e75a3ebc5fead5b4af152a3", - 200303, - RpcChain::MainNet - => ignore["broken on both due to a cairo-vm error"] - )] - fn blockifier_test_case_reverted_tx(hash: &str, block_number: u64, chain: RpcChain) { - // To reexecute a transaction, we must use the state from its previous block - let previous_block = BlockNumber(block_number - 1); - let (tx_info, trace, _) = execute_tx(hash, chain, previous_block); - - assert_eq!( - tx_info.revert_error, - trace.execute_invocation.unwrap().revert_reason - ); - - // We can't currently compare fee values - } - - #[test_case( - // Declare tx - "0x60506c49e65d84e2cdd0e9142dc43832a0a59cb6a9cbcce1ab4f57c20ba4afb", - 347900, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x014640564509873cf9d24a311e1207040c8b60efd38d96caef79855f0b0075d5", - 90007, - RpcChain::MainNet - )] - #[test_case( - "0x025844447697eb7d5df4d8268b23aef6c11de4087936048278c2559fc35549eb", - 197001, - RpcChain::MainNet - )] - #[test_case( - "0x00164bfc80755f62de97ae7c98c9d67c1767259427bcf4ccfcc9683d44d54676", - 197001, - RpcChain::MainNet - )] - #[test_case( - "0x05d200ef175ba15d676a68b36f7a7b72c17c17604eda4c1efc2ed5e4973e2c91", - 169929, - RpcChain::MainNet - )] - #[test_case( - "0x0528ec457cf8757f3eefdf3f0728ed09feeecc50fd97b1e4c5da94e27e9aa1d6", - 169929, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x0737677385a30ec4cbf9f6d23e74479926975b74db3d55dc5e46f4f8efee41cf", - 169929, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x026c17728b9cd08a061b1f17f08034eb70df58c1a96421e73ee6738ad258a94c", - 169929, - RpcChain::MainNet - )] - #[test_case( - // review later - "0x0743092843086fa6d7f4a296a226ee23766b8acf16728aef7195ce5414dc4d84", - 186549, - RpcChain::MainNet - )] - #[test_case( - // fails in blockifier - "0x00724fc4a84f489ed032ebccebfc9541eb8dc64b0e76b933ed6fc30cd6000bd1", - 186552, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x176a92e8df0128d47f24eebc17174363457a956fa233cc6a7f8561bfbd5023a", - 317093, - RpcChain::MainNet - )] - #[test_case( - "0x04db9b88e07340d18d53b8b876f28f449f77526224afb372daaf1023c8b08036", - 398052, - RpcChain::MainNet - )] - #[test_case( - "0x5a5de1f42f6005f3511ea6099daed9bcbcf9de334ee714e8563977e25f71601", - 281514, - RpcChain::MainNet - )] - #[test_case( - "0x26be3e906db66973de1ca5eec1ddb4f30e3087dbdce9560778937071c3d3a83", - 351269, - RpcChain::MainNet - )] - #[test_case( - "0x4f552c9430bd21ad300db56c8f4cae45d554a18fac20bf1703f180fac587d7e", - 351226, - RpcChain::MainNet - )] - // DeployAccount for different account providers: - - // OpenZeppelin (v0.7.0) - #[test_case( - "0x04df8a364233d995c33c7f4666a776bf458631bec2633e932b433a783db410f8", - 422882, - RpcChain::MainNet - )] - // Argent X (v5.7.0) - #[test_case( - "0x74820d4a1ac6e832a51a8938959e6f15a247f7d34daea2860d4880c27bc2dfd", - 475946, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x41497e62fb6798ff66e4ad736121c0164cdb74005aa5dab025be3d90ad4ba06", - 638867, - RpcChain::MainNet - )] - #[test_case( - "0x7805c2bf5abaf4fe0eb1db7b7be0486a14757b4bf96634c828d11c07e4a763c", - 641976, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x73ef9cde09f005ff6f411de510ecad4cdcf6c4d0dfc59137cff34a4fc74dfd", - 654001, - RpcChain::MainNet - )] - #[test_case( - "0x75d7ef42a815e4d9442efcb509baa2035c78ea6a6272ae29e87885788d4c85e", - 654001, - RpcChain::MainNet - )] - #[test_case( - "0x1ecb4b825f629eeb9816ddfd6905a85f6d2c89995907eacaf6dc64e27a2c917", - 654001, - RpcChain::MainNet - )] - #[test_case( - "0x70d83cb9e25f1e9f7be2608f72c7000796e4a222c1ed79a0ea81abe5172557b", - 654001, - RpcChain::MainNet - )] - #[test_case( - "0x670321c71835004fcab639e871ef402bb807351d126ccc4d93075ff2c31519d", - 654001, - RpcChain::MainNet - )] - #[test_case( - "0x5896b4db732cfc57ce5d56ece4dfa4a514bd435a0ee80dc79b37e60cdae5dd6", - 653001, - RpcChain::MainNet - => ignore["takes to long"] - )] - #[test_case( - "0x5a030fd81f14a1cf29a2e5259d3f2c9960018ade2d135269760e6fb4802ac02", - 653001, - RpcChain::MainNet - => ignore["halts execution"] - )] - #[test_case( - "0x2d2bed435d0b43a820443aad2bc9e3d4fa110c428e65e422101dfa100ba5664", - 653001, - RpcChain::MainNet - => ignore - )] - #[test_case( - "0x3330b29e8b99dedef79f5c7cdc2b510c590155add29dcc5e2f92d176d8e19d", - 653001, - RpcChain::MainNet - => ignore - )] - fn blockifier_tx(hash: &str, block_number: u64, chain: RpcChain) { - // To reexecute a transaction, we must use the state from its previous block - let previous_block = BlockNumber(block_number - 1); - let (tx_info, trace, _receipt) = execute_tx(hash, chain, previous_block); - - // We cannot currently check fee & resources - - // Compare tx CallInfos against trace RpcCallInfos - // Note: This will check calldata, retdata, internal calls and make sure the tx is not reverted. - // It will not chekced accessed or modified storage, messanges, and events (as they are not currenlty part of the RpcCallInfo) - assert_eq_sorted!( - tx_info.validate_call_info.map(|ref ci| ci.into()), - trace.validate_invocation - ); - assert_eq_sorted!( - tx_info.execute_call_info.map(|ref ci| ci.into()), - trace.execute_invocation - ); - //assert_eq!(tx_info.fee_transfer_call_info.map(|ref ci| ci.into()), trace.fee_transfer_invocation); TODO: fix charge_fee - } - - // test cairo-vm's tx execution against cairo-native, using only_cairo_vm feature - #[test_case( - "0x04ba569a40a866fd1cbb2f3d3ba37ef68fb91267a4931a377d6acc6e5a854f9a", - 648462, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 192, l2_gas: 0 }, - 7, - 3, - 0, - None, - StateChangesCount { - n_storage_updates: 2, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 1, - }, - false - )] - #[test_case( - "0x0355059efee7a38ba1fd5aef13d261914608dce7bdfacad92a71e396f0ad7a77", - 661815, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, - 9, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 3, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x05324bac55fb9fb53e738195c2dcc1e7fed1334b6db824665e3e984293bec95e", - 662246, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, - 9, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 3, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x670321c71835004fcab639e871ef402bb807351d126ccc4d93075ff2c31519d", - 654001, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, - 7, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 3, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x06962f11a96849ebf05cd222313858a93a8c5f300493ed6c5859dd44f5f2b4e3", - 654770, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 320, l2_gas: 0 }, - 7, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 3, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x078b81326882ecd2dc6c5f844527c3f33e0cdb52701ded7b1aa4d220c5264f72", - 653019, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 640, l2_gas: 0 }, - 28, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 7, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 3, - }, - false - )] - #[test_case( - "0x0780e3a498b4fd91ab458673891d3e8ee1453f9161f4bfcb93dd1e2c91c52e10", - 650558, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 448, l2_gas: 0 }, - 24, - 3, - 0, - None, - StateChangesCount { - n_storage_updates: 4, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 3, - }, - false - )] - #[test_case( - "0x4f552c9430bd21ad300db56c8f4cae45d554a18fac20bf1703f180fac587d7e", - 351226, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 3, - 0, - 0, - Some(3), - StateChangesCount { - n_storage_updates: 2, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 0, - }, - false - )] - #[test_case( - "0x176a92e8df0128d47f24eebc17174363457a956fa233cc6a7f8561bfbd5023a", - 317093, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 6, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 1, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 1, - }, - false - )] - #[test_case( - "0x026c17728b9cd08a061b1f17f08034eb70df58c1a96421e73ee6738ad258a94c", - 169929, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 8, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 1, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 1, - }, - false - )] - #[test_case( - "0x73ef9cde09f005ff6f411de510ecad4cdcf6c4d0dfc59137cff34a4fc74dfd", - 654001, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 5, - 0, - 0, - Some(5), - StateChangesCount { - n_storage_updates: 2, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 0, - }, - false - )] - #[test_case( - "0x0743092843086fa6d7f4a296a226ee23766b8acf16728aef7195ce5414dc4d84", - 186549, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 384, l2_gas: 0 }, - 7, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 4, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x066e1f01420d8e433f6ef64309adb1a830e5af0ea67e3d935de273ca57b3ae5e", - 662252, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 448, l2_gas: 0 }, - 18, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 5, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - // Check this tx, l1_data_gas should be 384 - // https://starkscan.co/tx/0x04756d898323a8f884f5a6aabd6834677f4bbaeecc2522f18b3ae45b3f99cd1e - #[test_case( - "0x04756d898323a8f884f5a6aabd6834677f4bbaeecc2522f18b3ae45b3f99cd1e", - 662250, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 10, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 1, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 1, - }, - false - )] - #[test_case( - "0x00f390691fd9e865f5aef9c7cc99889fb6c2038bc9b7e270e8a4fe224ccd404d", - 662251, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 256, l2_gas: 0 }, - 12, - 5, - 0, - None, - StateChangesCount { - n_storage_updates: 2, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x26be3e906db66973de1ca5eec1ddb4f30e3087dbdce9560778937071c3d3a83", - 351269, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 3, - 0, - 0, - Some(3), - StateChangesCount { - n_storage_updates: 2, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 0, - }, - false - )] - #[test_case( - "0x0310c46edc795c82c71f600159fa9e6c6540cb294df9d156f685bfe62b31a5f4", - 662249, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 640, l2_gas: 0 }, - 37, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 7, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 3, - }, - false - )] - #[test_case( - "0x06a09ffbf996178ac6e90101047e42fe29cb7108573b2ecf4b0ebd2cba544cb4", - 662248, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 384, l2_gas: 0 }, - 4, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 4, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 2, - }, - false - )] - #[test_case( - "0x026e04e96ba1b75bfd066c8e138e17717ecb654909e6ac24007b644ac23e4b47", - 536893, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 896, l2_gas: 0 }, - 24, - 4, - 0, - None, - StateChangesCount { - n_storage_updates: 10, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 4, - }, - false - )] - #[test_case( - "0x01351387ef63fd6fe5ec10fa57df9e006b2450b8c68d7eec8cfc7d220abc7eda", - 644700, - RpcChain::MainNet, - GasVector { l1_gas: 0, l1_data_gas: 128, l2_gas: 0 }, - 8, - 2, - 0, - None, - StateChangesCount { - n_storage_updates: 1, - n_class_hash_updates: 0, - n_compiled_class_hash_updates: 0, - n_modified_contracts: 1, - }, - true - )] - #[allow(clippy::too_many_arguments)] - fn test_transaction_info( - hash: &str, - block_number: u64, - chain: RpcChain, - da_gas: GasVector, - calldata_length: usize, - signature_length: usize, - code_size: usize, - l1_handler_payload_size: Option, - starknet_chg: StateChangesCount, - is_reverted: bool, - ) { - let previous_block = BlockNumber(block_number - 1); - let (tx_info, _, _) = execute_tx(hash, chain, previous_block); - let tx_receipt = tx_info.receipt; - let starknet_resources = tx_receipt.resources.starknet_resources; - let callinfo_iter = match tx_info.execute_call_info { - Some(c) => vec![c], - None => vec![CallInfo::default()], // there's no call info, so we take the default value to have all of it's atributes set to 0 - }; - let starknet_rsc = StarknetResources::new( - calldata_length, - signature_length, - code_size, - starknet_chg, - l1_handler_payload_size, - callinfo_iter.iter(), - ); - - assert_eq!(is_reverted, tx_info.revert_error.is_some()); - assert_eq!(da_gas, tx_receipt.da_gas); - assert_eq!(starknet_rsc, starknet_resources); - } - - // Impl conversion for easier checking against RPC data - impl From<&CallInfo> for RpcCallInfo { - fn from(value: &CallInfo) -> Self { - Self { - retdata: Some(value.execution.retdata.0.clone()), - calldata: Some((*value.call.calldata.0).clone()), - internal_calls: value.inner_calls.iter().map(|ci| ci.into()).collect(), - // We don't have the revert reason string in the trace so we just make sure it doesn't revert - revert_reason: value.execution.failed.then_some("Default String".into()), - } - } - } -} diff --git a/rpc-state-reader/src/rpc_state.rs b/rpc-state-reader/src/rpc_state.rs deleted file mode 100644 index 8c641cc..0000000 --- a/rpc-state-reader/src/rpc_state.rs +++ /dev/null @@ -1,685 +0,0 @@ -use blockifier::blockifier::block::GasPrices; -use cairo_vm::{ - types::builtin_name::BuiltinName, - vm::runners::cairo_runner::ExecutionResources as VmExecutionResources, -}; -use core::fmt; -use dotenv::dotenv; -use serde::{Deserialize, Deserializer}; -use serde_json::json; -use starknet::core::types::ContractClass as SNContractClass; -use starknet_api::{ - block::{BlockNumber, BlockTimestamp}, - core::{ChainId, ClassHash, ContractAddress}, - hash::StarkHash, - state::StorageKey, - transaction::{Transaction as SNTransaction, TransactionHash}, -}; -use std::{collections::HashMap, env, fmt::Display, num::NonZeroU128}; -use tracing::debug; - -use crate::{rpc_state_errors::RpcStateError, utils}; - -/// Starknet chains supported in Infura. -#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub enum RpcChain { - MainNet, - TestNet, - TestNet2, -} - -impl fmt::Display for RpcChain { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - RpcChain::MainNet => write!(f, "starknet-mainnet"), - RpcChain::TestNet => write!(f, "starknet-goerli"), - RpcChain::TestNet2 => write!(f, "starknet-goerli2"), - } - } -} - -impl From for ChainId { - fn from(value: RpcChain) -> Self { - ChainId::Other(match value { - RpcChain::MainNet => "alpha-mainnet".to_string(), - RpcChain::TestNet => "alpha4".to_string(), - RpcChain::TestNet2 => "alpha4-2".to_string(), - }) - } -} - -/// A [StateReader] that holds all the data in memory. -/// -/// This implementation is uses HTTP requests to call the RPC endpoint, -/// using Infura. -/// In order to use it an Infura API key is necessary. -#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub struct RpcState { - /// Enum with one of the supported Infura chains/ - pub chain: RpcChain, - /// RPC Endpoint URL. - rpc_endpoint: String, - /// Struct that holds information on the block where we are going to use to read the state. - pub block: BlockValue, -} - -/// Represents the tag of a block value. -#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub enum BlockTag { - Latest, - Pending, -} - -impl Display for BlockTag { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let string = match self { - BlockTag::Latest => "latest", - BlockTag::Pending => "pending", - }; - write!(f, "{}", string) - } -} - -/// [`BlockValue`] is an Enum that represent which block we are going to use to retrieve information. -#[allow(dead_code)] -#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub enum BlockValue { - /// String one of: ["latest", "pending"] - Tag(BlockTag), - /// Integer - Number(BlockNumber), - /// String with format: 0x{felt252} - Hash(StarkHash), -} - -impl From for BlockValue { - fn from(value: BlockTag) -> Self { - BlockValue::Tag(value) - } -} - -impl From for BlockValue { - fn from(value: BlockNumber) -> Self { - BlockValue::Number(value) - } -} - -impl From for BlockValue { - fn from(value: StarkHash) -> Self { - BlockValue::Hash(value) - } -} - -impl BlockValue { - fn to_value(self) -> Result { - serde_json::to_value(match self { - BlockValue::Tag(block_tag) => block_tag.to_string().into(), - BlockValue::Number(block_number) => json!({ "block_number": block_number }), - BlockValue::Hash(block_hash) => json!({ "block_hash": block_hash }), - }) - } -} - -/// The RPC block info. -#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub struct RpcBlockInfo { - /// The sequence number of the last block created. - pub block_number: BlockNumber, - /// Timestamp of the beginning of the last block creation attempt. - pub block_timestamp: BlockTimestamp, - /// The sequencer address of this block. - pub sequencer_address: ContractAddress, - /// The transactions of this block. - pub transactions: Vec, -} - -/// A RPC response. -#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub struct RpcResponse { - result: T, -} - -#[derive(Debug, Deserialize, Clone, Eq, PartialEq)] -pub struct TransactionTrace { - pub validate_invocation: Option, - #[serde( - alias = "execute_invocation", - alias = "constructor_invocation", - alias = "function_invocation" - )] - pub execute_invocation: Option, - pub fee_transfer_invocation: Option, -} - -#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] -pub struct RpcExecutionResources { - pub n_steps: usize, - pub n_memory_holes: usize, - pub builtin_instance_counter: HashMap, -} - -#[derive(Debug, Clone, Eq, PartialEq, Default)] -pub struct RpcCallInfo { - pub retdata: Option>, - pub calldata: Option>, - pub internal_calls: Vec, - pub revert_reason: Option, -} - -#[derive(Debug, Deserialize)] -pub struct RpcTransactionReceipt { - pub actual_fee: FeePayment, - pub block_hash: StarkHash, - pub block_number: u64, - pub execution_status: String, - pub events: Vec, - pub messages_sent: Vec, - #[serde(rename = "type")] - pub tx_type: String, - #[serde(deserialize_with = "vm_execution_resources_deser")] - pub execution_resources: VmExecutionResources, -} - -#[allow(unused)] -#[derive(Debug, Deserialize)] -pub struct FeePayment { - #[serde(deserialize_with = "fee_amount_deser")] - pub amount: u128, - pub unit: String, -} - -#[allow(unused)] -#[derive(Debug, Deserialize)] -pub struct Event { - from_address: StarkHash, - keys: Vec, - data: Vec, -} - -#[allow(unused)] -#[derive(Debug, Deserialize)] -pub struct ToL1Msg { - from_address: StarkHash, - to_address: StarkHash, - payload: Vec, -} - -fn fee_amount_deser<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let hex: String = Deserialize::deserialize(deserializer)?; - u128::from_str_radix(&hex[2..], 16).map_err(serde::de::Error::custom) -} - -fn vm_execution_resources_deser<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let value: serde_json::Value = Deserialize::deserialize(deserializer)?; - // Parse n_steps - let n_steps: usize = serde_json::from_value( - value - .get("steps") - .ok_or(serde::de::Error::custom( - RpcStateError::MissingRpcResponseField("steps".to_string()), - ))? - .clone(), - ) - .map_err(|e| serde::de::Error::custom(e.to_string()))?; - - // Parse n_memory_holes - let n_memory_holes: usize = if let Some(memory_holes) = value.get("memory_holes") { - serde_json::from_value(memory_holes.clone()) - .map_err(|e| serde::de::Error::custom(e.to_string()))? - } else { - 0 - }; - // Parse builtin instance counter - let builtn_names: [BuiltinName; 8] = [ - BuiltinName::output, - BuiltinName::range_check, - BuiltinName::pedersen, - BuiltinName::ecdsa, - BuiltinName::keccak, - BuiltinName::bitwise, - BuiltinName::ec_op, - BuiltinName::poseidon, - ]; - let mut builtin_instance_counter = HashMap::new(); - for name in builtn_names { - let builtin_counter: Option = value - .get(format!("{}_applications", name.to_str())) - .and_then(|a| serde_json::from_value(a.clone()).ok()); - if let Some(builtin_counter) = builtin_counter { - if builtin_counter > 0 { - builtin_instance_counter.insert(name, builtin_counter); - } - }; - } - Ok(VmExecutionResources { - n_steps, - n_memory_holes, - builtin_instance_counter, - }) -} - -impl<'de> Deserialize<'de> for RpcCallInfo { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let value: serde_json::Value = Deserialize::deserialize(deserializer)?; - - // In case of a revert error, the struct will only contain the revert_reason field - if let Some(revert_error) = value.get("revert_reason") { - return Ok(RpcCallInfo { - revert_reason: serde_json::from_value(revert_error.clone()) - .map_err(|e| serde::de::Error::custom(e.to_string()))?, - ..Default::default() - }); - } - // Parse retdata - let retdata_value = value - .get("result") - .ok_or(serde::de::Error::custom( - RpcStateError::MissingRpcResponseField("result".to_string()), - ))? - .clone(); - let retdata = serde_json::from_value(retdata_value) - .map_err(|e| serde::de::Error::custom(e.to_string()))?; - - // Parse calldata - let calldata_value = value - .get("calldata") - .ok_or(serde::de::Error::custom( - RpcStateError::MissingRpcResponseField("calldata".to_string()), - ))? - .clone(); - let calldata = serde_json::from_value(calldata_value) - .map_err(|e| serde::de::Error::custom(e.to_string()))?; - - // Parse internal calls - let internal_calls_value = value - .get("calls") - .ok_or(serde::de::Error::custom( - RpcStateError::MissingRpcResponseField("calls".to_string()), - ))? - .clone(); - let mut internal_calls = vec![]; - - for call in internal_calls_value - .as_array() - .ok_or(serde::de::Error::custom( - RpcStateError::RpcResponseWrongType("internal_calls".to_string()), - ))? - { - internal_calls - .push(serde_json::from_value(call.clone()).map_err(serde::de::Error::custom)?); - } - - Ok(RpcCallInfo { - retdata, - calldata, - internal_calls, - revert_reason: None, - }) - } -} - -impl RpcState { - pub fn new(chain: RpcChain, block: BlockValue, rpc_endpoint: &str) -> Self { - Self { - chain, - rpc_endpoint: rpc_endpoint.to_string(), - block, - } - } - - pub fn new_rpc(chain: RpcChain, block: BlockValue) -> Result { - if env::var("RPC_ENDPOINT_MAINNET").is_err() || env::var("RPC_ENDPOINT_TESTNET").is_err() { - dotenv().map_err(|_| RpcStateError::MissingEnvFile)?; - } - - let rpc_endpoint = - match chain { - RpcChain::MainNet => env::var("RPC_ENDPOINT_MAINNET") - .map_err(|_| RpcStateError::MissingRpcEndpoints)?, - RpcChain::TestNet => env::var("RPC_ENDPOINT_TESTNET") - .map_err(|_| RpcStateError::MissingRpcEndpoints)?, - RpcChain::TestNet2 => unimplemented!(), - }; - - Ok(Self::new(chain, block, &rpc_endpoint)) - } - - fn rpc_call_result Deserialize<'a>>( - &self, - method: &str, - params: &serde_json::Value, - ) -> Result { - Ok(self.rpc_call::>(method, params)?.result) - } - - fn rpc_call Deserialize<'a>>( - &self, - method: &str, - params: &serde_json::Value, - ) -> Result { - debug!(method, "rpc call"); - - let payload = serde_json::json!({ - "jsonrpc": "2.0", - "method": method, - "params": params, - "id": 1 - }); - let response = self.rpc_call_no_deserialize(&payload)?.into_json()?; - Self::deserialize_call(response) - } - - fn rpc_call_no_deserialize( - &self, - params: &serde_json::Value, - ) -> Result { - ureq::post(&self.rpc_endpoint) - .set("Content-Type", "application/json") - .set("accept", "application/json") - .send_json(params) - .map_err(|err| { - if err - .to_string() - .contains("request failed or timed out through") - { - RpcStateError::RpcConnectionNotAvailable - } else { - RpcStateError::Request(err.to_string()) - } - }) - } - - fn deserialize_call Deserialize<'a>>( - response: serde_json::Value, - ) -> Result { - serde_json::from_value(response).map_err(|err| RpcStateError::RpcCall(err.to_string())) - } - - /// Requests the transaction trace to the Feeder Gateway API. - /// It's useful for testing the transaction outputs like: - /// - execution resources - /// - actual fee - /// - events - /// - return data - pub fn get_transaction_trace( - &self, - hash: &TransactionHash, - ) -> Result { - let result = self - .rpc_call::("starknet_traceTransaction", &json!([hash.to_string()]))? - .get("result") - .ok_or(RpcStateError::MissingRpcResponseField("result".into()))? - .clone(); - serde_json::from_value(result).map_err(|e| RpcStateError::Request(e.to_string())) - } - - /// Requests the given transaction to the Feeder Gateway API. - pub fn get_transaction(&self, hash: &TransactionHash) -> Result { - let mut result = self - .rpc_call::( - "starknet_getTransactionByHash", - &json!([hash.to_string()]), - )? - .get("result") - .ok_or(RpcStateError::MissingRpcResponseField("result".into()))? - .clone(); - - if let Some(resource_bounds) = result.get_mut("resource_bounds") { - if let Some(l1_gas) = resource_bounds.get_mut("l1_gas") { - resource_bounds["L1_GAS"] = l1_gas.clone(); - resource_bounds.as_object_mut().unwrap().remove("l1_gas"); - } - if let Some(l2_gas) = resource_bounds.get_mut("l2_gas") { - resource_bounds["L2_GAS"] = l2_gas.clone(); - resource_bounds.as_object_mut().unwrap().remove("l2_gas"); - } - } - - utils::deserialize_transaction_json(result).map_err(RpcStateError::SerdeJson) - } - - /// Gets the gas price of a given block. - pub fn get_gas_price(&self, block_number: u64) -> Result { - let res = self - .rpc_call::( - "starknet_getBlockWithTxHashes", - &json!({"block_id" : { "block_number": block_number }}), - )? - .get("result") - .ok_or(RpcStateError::MissingRpcResponseField("result".into()))? - .clone(); - - let gas_price_eth = u128::from_str_radix( - res.get("l1_gas_price") - .and_then(|gp| gp.get("price_in_wei")) - .and_then(|gp| gp.as_str()) - .ok_or(RpcStateError::MissingRpcResponseField( - "gas_price.price_in_wei".to_string(), - ))? - .trim_start_matches("0x"), - 16, - ) - .map_err(|_| RpcStateError::RpcResponseWrongType("gas_price".to_string()))?; - - let gas_price_strk = u128::from_str_radix( - res.get("l1_gas_price") - .and_then(|gp| gp.get("price_in_fri")) - .and_then(|gp| gp.as_str()) - .ok_or(RpcStateError::MissingRpcResponseField( - "gas_price.price_in_fri".to_string(), - ))? - .trim_start_matches("0x"), - 16, - ) - .map_err(|_| RpcStateError::RpcResponseWrongType("gas_price".to_string()))?; - - let l1_data_gas_price_strk = u128::from_str_radix( - res.get("l1_data_gas_price") - .and_then(|gp| gp.get("price_in_fri")) - .and_then(|gp| gp.as_str()) - .ok_or(RpcStateError::MissingRpcResponseField( - "l1_data_gas_price.price_in_fri".to_string(), - ))? - .trim_start_matches("0x"), - 16, - ) - .map_err(|_| RpcStateError::RpcResponseWrongType("l1_data_gas_price".to_string()))?; - - let l1_data_gas_price_wei = u128::from_str_radix( - res.get("l1_data_gas_price") - .and_then(|gp| gp.get("price_in_wei")) - .and_then(|gp| gp.as_str()) - .ok_or(RpcStateError::MissingRpcResponseField( - "l1_data_gas_price.l1_data_gas_price_wei".to_string(), - ))? - .trim_start_matches("0x"), - 16, - ) - .map_err(|_| RpcStateError::RpcResponseWrongType("l1_data_gas_price".to_string()))?; - - // TODO check 0 wei/strk - Ok(GasPrices::new( - NonZeroU128::new(gas_price_eth).unwrap_or(NonZeroU128::new(1).unwrap()), - NonZeroU128::new(gas_price_strk).unwrap_or(NonZeroU128::new(1).unwrap()), - NonZeroU128::new(l1_data_gas_price_wei).unwrap_or(NonZeroU128::new(1).unwrap()), - NonZeroU128::new(l1_data_gas_price_strk).unwrap_or(NonZeroU128::new(1).unwrap()), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - )) - } - - pub fn get_chain_name(&self) -> ChainId { - self.chain.into() - } - - pub fn get_block_info(&self) -> Result { - let block_info: serde_json::Value = self - .rpc_call("starknet_getBlockWithTxs", &json!([self.block.to_value()?])) - .map_err(|e| RpcStateError::RpcCall(e.to_string()))?; - - let sequencer_address: StarkHash = block_info - .get("result") - .and_then(|result| result.get("sequencer_address")) - .and_then(|sa| serde_json::from_value(sa.clone()).ok()) - .ok_or_else(|| { - RpcStateError::RpcObjectHasNoField("block_info".into(), "sequencer_address".into()) - })?; - - let transactions: Vec<_> = block_info - .get("result") - .and_then(|result| result.get("transactions")) - .and_then(|txs| txs.as_array()) - .map(|arr| { - arr.iter() - .filter_map(|result| utils::deserialize_transaction_json(result.clone()).ok()) - .collect() - }) - .ok_or_else(|| { - RpcStateError::RpcObjectHasNoField("block_info".into(), "transactions".into()) - })?; - - Ok(RpcBlockInfo { - block_number: BlockNumber( - block_info - .get("result") - .and_then(|result| result.get("block_number")) - .and_then(|v| v.to_string().parse::().ok()) - .ok_or_else(|| { - RpcStateError::RpcObjectHasNoField( - "block_info".into(), - "block_number".into(), - ) - })?, - ), - block_timestamp: BlockTimestamp( - block_info - .get("result") - .and_then(|result| result.get("timestamp")) - .and_then(|v| v.to_string().parse::().ok()) - .ok_or_else(|| { - RpcStateError::RpcObjectHasNoField("block_info".into(), "timestamp".into()) - })?, - ), - sequencer_address: ContractAddress( - sequencer_address - .try_into() - .map_err(|_| RpcStateError::StarkFeltToParticiaKeyConversion)?, - ), - transactions, - }) - } - - pub fn get_contract_class(&self, class_hash: &ClassHash) -> Option { - self.block.to_value().ok().and_then(|block| { - self.rpc_call_result( - "starknet_getClass", - &json!([block, class_hash.0.to_string()]), - ) - .ok() - }) - } - - pub fn get_class_hash_at(&self, contract_address: &ContractAddress) -> ClassHash { - let hash = self - .block - .to_value() - .ok() - .and_then(|block| { - self.rpc_call_result( - "starknet_getClassHashAt", - &json!([block, contract_address.0.key().clone().to_string()]), - ) - .ok() - }) - .unwrap_or_default(); - - ClassHash(hash) - } - - pub fn get_nonce_at(&self, contract_address: &ContractAddress) -> StarkHash { - self.block - .to_value() - .ok() - .and_then(|block| { - self.rpc_call_result( - "starknet_getNonce", - &json!([block, contract_address.0.key().clone().to_string()]), - ) - .ok() - }) - // When running deploy_account transactions, the nonce doesn't exist on the previous block so we return 0 - .unwrap_or_default() - } - - pub fn get_storage_at( - &self, - contract_address: &ContractAddress, - key: &StorageKey, - ) -> StarkHash { - let contract_address = contract_address.0.key(); - let key = key.0.key(); - self.block - .to_value() - .ok() - .and_then(|block| { - self.rpc_call_result( - "starknet_getStorageAt", - &json!([contract_address.to_string(), key.to_string(), block]), - ) - .ok() - }) - .unwrap_or_default() - } - - /// Requests the given transaction to the Feeder Gateway API. - pub fn get_transaction_receipt( - &self, - hash: &TransactionHash, - ) -> Result { - self.rpc_call_result("starknet_getTransactionReceipt", &json!([hash.to_string()])) - .map_err(|e| RpcStateError::RpcCall(e.to_string())) - } - - pub fn get_transaction_hashes(&self) -> Result, RpcStateError> { - let params = &json![vec![self.block.to_value()?]]; - let payload = serde_json::json!({ - "jsonrpc": "2.0", - "method": "starknet_getBlockWithTxHashes", - "params": params, - "id": 1 - }); - let response: serde_json::Value = self - .rpc_call_no_deserialize(&payload) - .unwrap() - .into_json()?; - let hashes: Vec = response - .get("result") - .and_then(|res| res.get("transactions")) - .and_then(|txs| txs.as_array()) - .map(|arr| { - arr.iter() - .filter_map(|tx| tx.as_str().map(|x| x.to_string())) - .collect() - }) - .unwrap_or_default(); - Ok(hashes) - } -} - -#[test] -fn test_tx_hashes() { - let rpc_state = - RpcState::new_rpc(RpcChain::MainNet, BlockValue::Number(BlockNumber(397709))).unwrap(); - - let hashes = rpc_state.get_transaction_hashes().unwrap(); - assert_eq!(hashes.len(), 211); -} diff --git a/rpc-state-reader/src/rpc_state_errors.rs b/rpc-state-reader/src/rpc_state_errors.rs deleted file mode 100644 index 6c1fe78..0000000 --- a/rpc-state-reader/src/rpc_state_errors.rs +++ /dev/null @@ -1,27 +0,0 @@ -use thiserror::Error; - -#[derive(Debug, Error)] -pub enum RpcStateError { - #[error("Missing .env file")] - MissingEnvFile, - #[error("Missing rpc endpoints")] - MissingRpcEndpoints, - #[error("RPC call failed with error: {0}")] - RpcCall(String), - #[error("Request failed with error: {0}")] - Request(String), - #[error(transparent)] - Io(#[from] std::io::Error), - #[error(transparent)] - SerdeJson(#[from] serde_json::Error), - #[error("Object {0} obtained from rpc call has no field {1}")] - RpcObjectHasNoField(String, String), - #[error("Failed to convert StarkFelt to PatriciaKey")] - StarkFeltToParticiaKeyConversion, - #[error("The service is down")] - RpcConnectionNotAvailable, - #[error("The response does not have a field named '{0}'")] - MissingRpcResponseField(String), - #[error("Wrong type for response field '{0}'")] - RpcResponseWrongType(String), -} From 0e52e025eb0bd4d3e6aaa55e4ee4adcc81eb13c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 12:02:08 -0300 Subject: [PATCH 19/31] Remove old mods --- rpc-state-reader/src/execution.rs | 1 - rpc-state-reader/src/lib.rs | 5 ----- 2 files changed, 6 deletions(-) diff --git a/rpc-state-reader/src/execution.rs b/rpc-state-reader/src/execution.rs index b49e898..7925b6f 100644 --- a/rpc-state-reader/src/execution.rs +++ b/rpc-state-reader/src/execution.rs @@ -26,7 +26,6 @@ use starknet_api::{ use crate::{ objects::{RpcTransactionReceipt, RpcTransactionTrace}, reader::{RpcChain, RpcStateReader}, - rpc_state::RpcState, }; pub fn execute_tx( diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index 22b5d2f..5c185d6 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -1,13 +1,8 @@ pub mod execution; pub mod objects; pub mod reader; - -pub mod rpc_state; -pub mod rpc_state_errors; pub mod utils; -pub mod blockifier_state_reader; - #[cfg(test)] mod tests1 { use blockifier::state::state_api::StateReader; From 50485eb7cab68136657e3f913d628f40f89ea36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 12:02:34 -0300 Subject: [PATCH 20/31] Rename test module --- rpc-state-reader/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index 5c185d6..cdbcca9 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -4,7 +4,7 @@ pub mod reader; pub mod utils; #[cfg(test)] -mod tests1 { +mod tests { use blockifier::state::state_api::StateReader; use pretty_assertions_sorted::{assert_eq, assert_eq_sorted}; use starknet_api::{ From b48f36afabc26faa256bf9bdb8b57250b206842e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 12:04:39 -0300 Subject: [PATCH 21/31] Remove old test --- rpc-state-reader/src/lib.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/rpc-state-reader/src/lib.rs b/rpc-state-reader/src/lib.rs index cdbcca9..bff2b19 100644 --- a/rpc-state-reader/src/lib.rs +++ b/rpc-state-reader/src/lib.rs @@ -96,17 +96,6 @@ mod tests { .unwrap(), ); - assert!(rpc_state.get_transaction(&tx_hash).is_ok()); - } - - #[test] - fn test_try_from_invoke() { - let rpc_state = RpcStateReader::new_latest(RpcChain::MainNet); - let tx_hash = TransactionHash( - StarkHash::from_hex("06da92cfbdceac5e5e94a1f40772d6c79d34f011815606742658559ec77b6955") - .unwrap(), - ); - rpc_state.get_transaction(&tx_hash).unwrap(); } From 91aa95a4330462b0fba17ffcbb84b8414369c5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 14:26:20 -0300 Subject: [PATCH 22/31] Fix some errors --- replay/src/benchmark.rs | 61 +++++++++------------ replay/src/main.rs | 63 ++++++++++++--------- rpc-state-reader/src/execution.rs | 15 ++--- rpc-state-reader/src/objects.rs | 91 +++++++++++++++++++++++++++++-- rpc-state-reader/src/reader.rs | 9 ++- rpc-state-reader/src/utils.rs | 69 ----------------------- 6 files changed, 156 insertions(+), 152 deletions(-) diff --git a/replay/src/benchmark.rs b/replay/src/benchmark.rs index 55f7013..1e9e7ff 100644 --- a/replay/src/benchmark.rs +++ b/replay/src/benchmark.rs @@ -5,20 +5,17 @@ use blockifier::{ state::{cached_state::CachedState, state_api::StateReader}, }; use rpc_state_reader::{ - blockifier_state_reader::{execute_tx_with_blockifier, fetch_block_context, RpcStateReader}, - rpc_state::{RpcChain, RpcState}, -}; -use starknet_api::{ - block::BlockNumber, - hash::StarkHash, - transaction::{Transaction as SNTransaction, TransactionHash}, + execution::{execute_tx_with_blockifier, fetch_block_context}, + objects::TransactionWithHash, + reader::{RpcChain, RpcStateReader}, }; +use starknet_api::{block::BlockNumber, hash::StarkHash, transaction::TransactionHash}; use tracing::{error, info, info_span}; pub type BlockCachedData = ( CachedState>, BlockContext, - Vec<(TransactionHash, SNTransaction)>, + Vec, ); /// Fetches context data to execute the given block range @@ -39,32 +36,17 @@ pub fn fetch_block_range_data( // For each block let block_number = BlockNumber(block_number); - let rpc_state = RpcState::new_rpc(chain, block_number.into()).unwrap(); + let reader = RpcStateReader::new(chain, block_number); // Fetch block context - let block_context = fetch_block_context(&rpc_state, block_number); + let block_context = fetch_block_context(&reader); // Fetch transactions for the block - let transactions = rpc_state - .get_transaction_hashes() - .unwrap() - .into_iter() - .map(|transaction_hash| { - let transaction_hash = - TransactionHash(StarkHash::from_hex(&transaction_hash).unwrap()); - - // Fetch transaction - let transaction = rpc_state.get_transaction(&transaction_hash).unwrap(); - - (transaction_hash, transaction) - }) - .collect::>(); + let transactions = reader.get_block_with_txs().unwrap().transactions; // Create cached state - let previous_rpc_state = - RpcState::new_rpc(chain, block_number.prev().unwrap().into()).unwrap(); - let previous_rpc_state_reader = RpcStateReader::new(previous_rpc_state); - let cached_state = CachedState::new(OptionalStateReader::new(previous_rpc_state_reader)); + let previous_reader = RpcStateReader::new(chain, block_number.prev().unwrap()); + let cached_state = CachedState::new(OptionalStateReader::new(previous_reader)); block_caches.push((cached_state, block_context, transactions)); } @@ -88,7 +70,11 @@ pub fn execute_block_range(block_range_data: &mut Vec) { // The transactional state is used to execute a transaction while discarding state changes applied to it. let mut transactional_state = CachedState::create_transactional(state); - for (transaction_hash, transaction) in transactions { + for TransactionWithHash { + transaction_hash, + transaction, + } in transactions + { // Execute each transaction let _tx_span = info_span!( "tx execution", @@ -125,20 +111,23 @@ pub fn execute_block_range(block_range_data: &mut Vec) { } pub fn fetch_transaction_data(tx: &str, block: BlockNumber, chain: RpcChain) -> BlockCachedData { - let rpc_state = RpcState::new_rpc(chain, block.into()).unwrap(); + let reader = RpcStateReader::new(chain, block); // Fetch block context - let block_context = fetch_block_context(&rpc_state, block); + let block_context = fetch_block_context(&reader); // Fetch transactions for the block let transaction_hash = TransactionHash(StarkHash::from_hex(tx).unwrap()); - let transaction = rpc_state.get_transaction(&transaction_hash).unwrap(); - let transactions = vec![(transaction_hash, transaction)]; + let transaction = reader.get_transaction(&transaction_hash).unwrap(); + let transactions = vec![TransactionWithHash { + transaction_hash, + transaction, + }]; // Create cached state - let previous_rpc_state = RpcState::new_rpc(chain, block.prev().unwrap().into()).unwrap(); - let previous_rpc_state_reader = RpcStateReader::new(previous_rpc_state); - let cached_state = CachedState::new(OptionalStateReader::new(previous_rpc_state_reader)); + let previous_reader = RpcStateReader::new(chain, block.prev().unwrap()); + + let cached_state = CachedState::new(OptionalStateReader::new(previous_reader)); (cached_state, block_context, transactions) } diff --git a/replay/src/main.rs b/replay/src/main.rs index 2a36bda..b4ffeec 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -1,15 +1,13 @@ use std::str::FromStr; use blockifier::state::cached_state::CachedState; +use blockifier::state::errors::StateError; use clap::{Parser, Subcommand}; -use rpc_state_reader::{ - blockifier_state_reader::RpcStateReader, - rpc_state::{BlockValue, RpcChain, RpcState}, - rpc_state_errors::RpcStateError, -}; -use rpc_state_reader::blockifier_state_reader::execute_tx_configurable; +use rpc_state_reader::execution::execute_tx_configurable; +use rpc_state_reader::reader::{RpcChain, RpcStateReader}; use starknet_api::block::BlockNumber; +use starknet_api::transaction::{TransactionExecutionStatus, TransactionHash}; use tracing::{debug, error, info, info_span}; use tracing_subscriber::filter::Directive; use tracing_subscriber::{util::SubscriberInitExt, EnvFilter}; @@ -106,7 +104,13 @@ fn main() { let transaction_hashes = get_transaction_hashes(&chain, block_number) .expect("Unable to fetch the transaction hashes."); for tx_hash in transaction_hashes { - show_execution_data(&mut state, tx_hash, &chain, block_number, charge_fee); + show_execution_data( + &mut state, + tx_hash.to_string(), + &chain, + block_number, + charge_fee, + ); } } ReplayExecute::BlockRange { @@ -126,7 +130,13 @@ fn main() { .expect("Unable to fetch the transaction hashes."); for tx_hash in transaction_hashes { - show_execution_data(&mut state, tx_hash, &chain, block_number, charge_fee); + show_execution_data( + &mut state, + tx_hash.to_string(), + &chain, + block_number, + charge_fee, + ); } } } @@ -249,10 +259,7 @@ fn parse_network(network: &str) -> RpcChain { fn build_cached_state(network: &str, block_number: u64) -> CachedState { let previous_block_number = BlockNumber(block_number); let rpc_chain = parse_network(network); - let rpc_reader = RpcStateReader( - RpcState::new_rpc(rpc_chain, previous_block_number.into()) - .expect("failed to create state reader"), - ); + let rpc_reader = RpcStateReader::new(rpc_chain, previous_block_number); CachedState::new(rpc_reader) } @@ -285,12 +292,13 @@ fn show_execution_data( } }; - let execution_status = match &execution_info.revert_error { - Some(_) => "REVERTED", - None => "SUCCEEDED", - }; - let rpc_execution_status = rpc_receipt.execution_status; - let status_matches = execution_status == rpc_execution_status; + let reverted = execution_info.is_reverted(); + let rpc_reverted = matches!( + rpc_receipt.execution_status, + TransactionExecutionStatus::Reverted(_) + ); + + let status_matches = reverted == rpc_reverted; let da_gas = &execution_info.receipt.da_gas; let da_gas_str = format!( @@ -342,8 +350,8 @@ fn show_execution_data( error!( transaction_hash = tx_hash, chain = chain, - execution_status, - rpc_execution_status, + reverted, + rpc_reverted, root_of_error = root_of_error, execution_error_message = execution_info.revert_error, n_events_and_messages = events_and_msgs, @@ -356,8 +364,8 @@ fn show_execution_data( info!( transaction_hash = tx_hash, chain = chain, - execution_status, - rpc_execution_status, + reverted, + rpc_reverted, execution_error_message = execution_info.revert_error, n_events_and_messages = events_and_msgs, rpc_n_events_and_msgs = rpc_events_and_msgs, @@ -387,11 +395,14 @@ fn show_execution_data( debug!(?execution_gas, ?rpc_gas, "execution actual fee"); } -fn get_transaction_hashes(network: &str, block_number: u64) -> Result, RpcStateError> { +fn get_transaction_hashes( + network: &str, + block_number: u64, +) -> Result, StateError> { let network = parse_network(network); - let block_value = BlockValue::Number(BlockNumber(block_number)); - let rpc_state = RpcState::new_rpc(network, block_value)?; - rpc_state.get_transaction_hashes() + let block_value = BlockNumber(block_number); + let rpc_state = RpcStateReader::new(network, block_value); + Ok(rpc_state.get_block_with_tx_hashes()?.transactions) } fn set_global_subscriber() { diff --git a/rpc-state-reader/src/execution.rs b/rpc-state-reader/src/execution.rs index 7925b6f..92e8dc3 100644 --- a/rpc-state-reader/src/execution.rs +++ b/rpc-state-reader/src/execution.rs @@ -352,9 +352,8 @@ fn parse_to_rpc_chain(network: &str) -> RpcChain { } } -pub fn fetch_block_context(state: &RpcState, block_number: BlockNumber) -> BlockContext { - let rpc_block_info = state.get_block_info().unwrap(); - let gas_price = state.get_gas_price(block_number.0).unwrap(); +pub fn fetch_block_context(reader: &RpcStateReader) -> BlockContext { + let block_info = reader.get_block_info().unwrap(); let mut versioned_constants = VersionedConstants::latest_constants_with_overrides(u32::MAX, usize::MAX); versioned_constants.disable_cairo0_redeclaration = false; @@ -373,15 +372,9 @@ pub fn fetch_block_context(state: &RpcState, block_number: BlockNumber) -> Block }; BlockContext::new( - BlockInfo { - block_number, - block_timestamp: rpc_block_info.block_timestamp, - sequencer_address: rpc_block_info.sequencer_address, - gas_prices: gas_price, - use_kzg_da: false, - }, + block_info, ChainInfo { - chain_id: state.get_chain_name(), + chain_id: reader.get_chain_id(), fee_token_addresses, }, versioned_constants, diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs index bbb2c2d..dd8df56 100644 --- a/rpc-state-reader/src/objects.rs +++ b/rpc-state-reader/src/objects.rs @@ -1,10 +1,11 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use serde::{Deserialize, Serialize}; -use starknet::core::types::Transaction; use starknet_api::{ block::BlockStatus, hash::StarkHash, - transaction::{Event, Fee, MessageToL1, TransactionExecutionStatus, TransactionHash}, + transaction::{ + Event, Fee, MessageToL1, Transaction, TransactionExecutionStatus, TransactionHash, + }, }; use starknet_gateway::rpc_objects::BlockHeader; @@ -44,7 +45,7 @@ pub struct RpcTransactionReceipt { pub events: Vec, #[serde(flatten)] pub execution_status: TransactionExecutionStatus, - #[serde(deserialize_with = "deser::vm_execution_resources_deser")] + #[serde(deserialize_with = "deser::deserialize_execution_resources")] pub execution_resources: ExecutionResources, } @@ -79,18 +80,22 @@ pub struct BlockWithTxs { pub struct TransactionWithHash { pub transaction_hash: TransactionHash, #[serde(flatten)] + #[serde(deserialize_with = "deser::deserialize_transaction")] pub transaction: Transaction, } -mod deser { +pub mod deser { use std::collections::HashMap; use cairo_vm::{ types::builtin_name::BuiltinName, vm::runners::cairo_runner::ExecutionResources, }; use serde::{Deserialize, Deserializer}; + use starknet_api::transaction::{ + DeclareTransaction, DeployAccountTransaction, InvokeTransaction, Transaction, + }; - pub fn vm_execution_resources_deser<'de, D>( + pub fn deserialize_execution_resources<'de, D>( deserializer: D, ) -> Result where @@ -144,4 +149,80 @@ mod deser { builtin_instance_counter, }) } + + pub fn deserialize_transaction<'de, D>(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let transaction: serde_json::Value = Deserialize::deserialize(deserializer)?; + transaction_from_json(transaction).map_err(|err| serde::de::Error::custom(err.to_string())) + } + + /// Freestanding deserialize method to avoid a new type. + pub fn transaction_from_json( + mut transaction: serde_json::Value, + ) -> serde_json::Result { + if let Some(resource_bounds) = transaction.get_mut("resource_bounds") { + if let Some(l1_gas) = resource_bounds.get_mut("l1_gas") { + resource_bounds["L1_GAS"] = l1_gas.clone(); + resource_bounds.as_object_mut().unwrap().remove("l1_gas"); + } + if let Some(l2_gas) = resource_bounds.get_mut("l2_gas") { + resource_bounds["L2_GAS"] = l2_gas.clone(); + resource_bounds.as_object_mut().unwrap().remove("l2_gas"); + } + } + + let tx_type: String = serde_json::from_value(transaction["type"].clone())?; + let tx_version: String = serde_json::from_value(transaction["version"].clone())?; + + match tx_type.as_str() { + "INVOKE" => match tx_version.as_str() { + "0x0" => Ok(Transaction::Invoke(InvokeTransaction::V0( + serde_json::from_value(transaction)?, + ))), + "0x1" => Ok(Transaction::Invoke(InvokeTransaction::V1( + serde_json::from_value(transaction)?, + ))), + "0x3" => Ok(Transaction::Invoke(InvokeTransaction::V3( + serde_json::from_value(transaction)?, + ))), + x => Err(serde::de::Error::custom(format!( + "unimplemented invoke version: {x}" + ))), + }, + "DEPLOY_ACCOUNT" => match tx_version.as_str() { + "0x1" => Ok(Transaction::DeployAccount(DeployAccountTransaction::V1( + serde_json::from_value(transaction)?, + ))), + "0x3" => Ok(Transaction::DeployAccount(DeployAccountTransaction::V3( + serde_json::from_value(transaction)?, + ))), + x => Err(serde::de::Error::custom(format!( + "unimplemented declare version: {x}" + ))), + }, + "DECLARE" => match tx_version.as_str() { + "0x0" => Ok(Transaction::Declare(DeclareTransaction::V0( + serde_json::from_value(transaction)?, + ))), + "0x1" => Ok(Transaction::Declare(DeclareTransaction::V1( + serde_json::from_value(transaction)?, + ))), + "0x2" => Ok(Transaction::Declare(DeclareTransaction::V2( + serde_json::from_value(transaction)?, + ))), + "0x3" => Ok(Transaction::Declare(DeclareTransaction::V3( + serde_json::from_value(transaction)?, + ))), + x => Err(serde::de::Error::custom(format!( + "unimplemented declare version: {x}" + ))), + }, + "L1_HANDLER" => Ok(Transaction::L1Handler(serde_json::from_value(transaction)?)), + x => Err(serde::de::Error::custom(format!( + "unimplemented transaction type deserialization: {x}" + ))), + } + } } diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index 0a1d050..d84b50a 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -24,7 +24,7 @@ use starknet_gateway::{ use ureq::json; use crate::{ - objects::{BlockWithTxHahes, BlockWithTxs, RpcTransactionReceipt, RpcTransactionTrace}, + objects::{self, BlockWithTxHahes, BlockWithTxs, RpcTransactionReceipt, RpcTransactionTrace}, utils, }; @@ -114,7 +114,7 @@ impl RpcStateReader { .inner .send_rpc_request("starknet_getTransactionByHash", params)?; - utils::deserialize_transaction_json(tx).map_err(serde_err_to_state_err) + objects::deser::transaction_from_json(tx).map_err(serde_err_to_state_err) } pub fn get_block_info(&self) -> StateResult { @@ -199,11 +199,10 @@ fn build_config(chain: RpcChain) -> RpcStateReaderConfig { RpcChain::TestNet2 => unimplemented!(), }; - let config = RpcStateReaderConfig { + RpcStateReaderConfig { url, json_rpc_version: "2.0".to_string(), - }; - config + } } impl StateReader for RpcStateReader { diff --git a/rpc-state-reader/src/utils.rs b/rpc-state-reader/src/utils.rs index 3986857..6aa5e8f 100644 --- a/rpc-state-reader/src/utils.rs +++ b/rpc-state-reader/src/utils.rs @@ -15,7 +15,6 @@ use starknet_api::{ core::{ClassHash, EntryPointSelector}, deprecated_contract_class::{EntryPoint, EntryPointOffset, EntryPointType}, hash::StarkHash, - transaction::{DeclareTransaction, DeployAccountTransaction, InvokeTransaction, Transaction}, }; #[derive(Debug, Deserialize)] @@ -70,74 +69,6 @@ pub fn decode_reader(bytes: Vec) -> io::Result { Ok(s) } -/// Freestanding deserialize method to avoid a new type. -pub fn deserialize_transaction_json( - mut transaction: serde_json::Value, -) -> serde_json::Result { - if let Some(resource_bounds) = transaction.get_mut("resource_bounds") { - if let Some(l1_gas) = resource_bounds.get_mut("l1_gas") { - resource_bounds["L1_GAS"] = l1_gas.clone(); - resource_bounds.as_object_mut().unwrap().remove("l1_gas"); - } - if let Some(l2_gas) = resource_bounds.get_mut("l2_gas") { - resource_bounds["L2_GAS"] = l2_gas.clone(); - resource_bounds.as_object_mut().unwrap().remove("l2_gas"); - } - } - - let tx_type: String = serde_json::from_value(transaction["type"].clone())?; - let tx_version: String = serde_json::from_value(transaction["version"].clone())?; - - match tx_type.as_str() { - "INVOKE" => match tx_version.as_str() { - "0x0" => Ok(Transaction::Invoke(InvokeTransaction::V0( - serde_json::from_value(transaction)?, - ))), - "0x1" => Ok(Transaction::Invoke(InvokeTransaction::V1( - serde_json::from_value(transaction)?, - ))), - "0x3" => Ok(Transaction::Invoke(InvokeTransaction::V3( - serde_json::from_value(transaction)?, - ))), - x => Err(serde::de::Error::custom(format!( - "unimplemented invoke version: {x}" - ))), - }, - "DEPLOY_ACCOUNT" => match tx_version.as_str() { - "0x1" => Ok(Transaction::DeployAccount(DeployAccountTransaction::V1( - serde_json::from_value(transaction)?, - ))), - "0x3" => Ok(Transaction::DeployAccount(DeployAccountTransaction::V3( - serde_json::from_value(transaction)?, - ))), - x => Err(serde::de::Error::custom(format!( - "unimplemented declare version: {x}" - ))), - }, - "DECLARE" => match tx_version.as_str() { - "0x0" => Ok(Transaction::Declare(DeclareTransaction::V0( - serde_json::from_value(transaction)?, - ))), - "0x1" => Ok(Transaction::Declare(DeclareTransaction::V1( - serde_json::from_value(transaction)?, - ))), - "0x2" => Ok(Transaction::Declare(DeclareTransaction::V2( - serde_json::from_value(transaction)?, - ))), - "0x3" => Ok(Transaction::Declare(DeclareTransaction::V3( - serde_json::from_value(transaction)?, - ))), - x => Err(serde::de::Error::custom(format!( - "unimplemented declare version: {x}" - ))), - }, - "L1_HANDLER" => Ok(Transaction::L1Handler(serde_json::from_value(transaction)?)), - x => Err(serde::de::Error::custom(format!( - "unimplemented transaction type deserialization: {x}" - ))), - } -} - pub fn get_native_executor(program: Program, class_hash: ClassHash) -> Arc { let cache_lock = AOT_PROGRAM_CACHE.get_or_init(|| RwLock::new(HashMap::new())); From 1e4c93d605a2a7b5b88d33e30b84cabe2bccebfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 14:33:50 -0300 Subject: [PATCH 23/31] Add comments --- rpc-state-reader/src/objects.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs index dd8df56..f60dc4d 100644 --- a/rpc-state-reader/src/objects.rs +++ b/rpc-state-reader/src/objects.rs @@ -162,6 +162,7 @@ pub mod deser { pub fn transaction_from_json( mut transaction: serde_json::Value, ) -> serde_json::Result { + // uppercase fields to make it starknet compatible if let Some(resource_bounds) = transaction.get_mut("resource_bounds") { if let Some(l1_gas) = resource_bounds.get_mut("l1_gas") { resource_bounds["L1_GAS"] = l1_gas.clone(); From cbfaaa1d7059a242a96f2f20fe53e562f4a739b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 14:36:12 -0300 Subject: [PATCH 24/31] Add comments --- rpc-state-reader/src/objects.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs index f60dc4d..c8c331d 100644 --- a/rpc-state-reader/src/objects.rs +++ b/rpc-state-reader/src/objects.rs @@ -1,3 +1,6 @@ +//! This module contains custom objects +//! and how to deserialize them from RPC calls + use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use serde::{Deserialize, Serialize}; use starknet_api::{ @@ -9,9 +12,6 @@ use starknet_api::{ }; use starknet_gateway::rpc_objects::BlockHeader; -// The following are not used right now -// We are keeping them just in case - #[derive(Debug, Deserialize, Clone, Eq, PartialEq)] pub struct RpcTransactionTrace { pub validate_invocation: Option, @@ -84,6 +84,8 @@ pub struct TransactionWithHash { pub transaction: Transaction, } +/// Some types require their own deserializer, as their ir shape is slightly different +/// from the ones in starknet. This module contains such deserializaction functions. pub mod deser { use std::collections::HashMap; From a3a1d7a6164eadc82287a9eac30a868f66156967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 14:49:55 -0300 Subject: [PATCH 25/31] Fix bug --- replay/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replay/src/main.rs b/replay/src/main.rs index b4ffeec..62555cb 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -106,7 +106,7 @@ fn main() { for tx_hash in transaction_hashes { show_execution_data( &mut state, - tx_hash.to_string(), + tx_hash.0.to_hex_string(), &chain, block_number, charge_fee, From 5032d636324d4f29e70a07d459da831478f4bdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 14:54:21 -0300 Subject: [PATCH 26/31] Abstract into functions --- rpc-state-reader/src/reader.rs | 78 +++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/rpc-state-reader/src/reader.rs b/rpc-state-reader/src/reader.rs index d84b50a..9442846 100644 --- a/rpc-state-reader/src/reader.rs +++ b/rpc-state-reader/src/reader.rs @@ -237,42 +237,10 @@ impl StateReader for RpcStateReader { fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { Ok(match self.get_contract_class(&class_hash)? { SNContractClass::Legacy(compressed_legacy_cc) => { - let as_str = utils::decode_reader(compressed_legacy_cc.program).unwrap(); - let program = Program::from_bytes(as_str.as_bytes(), None).unwrap(); - let entry_points_by_type = utils::map_entry_points_by_type_legacy( - compressed_legacy_cc.entry_points_by_type, - ); - let inner = Arc::new(ContractClassV0Inner { - program, - entry_points_by_type, - }); - ContractClass::V0(ContractClassV0(inner)) + compile_legacy_cc(compressed_legacy_cc) } SNContractClass::Sierra(flattened_sierra_cc) => { - let middle_sierra: utils::MiddleSierraContractClass = { - let v = serde_json::to_value(flattened_sierra_cc).unwrap(); - serde_json::from_value(v).unwrap() - }; - let sierra_cc = cairo_lang_starknet_classes::contract_class::ContractClass { - sierra_program: middle_sierra.sierra_program, - contract_class_version: middle_sierra.contract_class_version, - entry_points_by_type: middle_sierra.entry_points_by_type, - sierra_program_debug_info: None, - abi: None, - }; - - if cfg!(feature = "only_casm") { - let casm_cc = - cairo_lang_starknet_classes::casm_contract_class::CasmContractClass::from_contract_class(sierra_cc, false, usize::MAX).unwrap(); - ContractClass::V1(casm_cc.try_into().unwrap()) - } else { - let program = sierra_cc.extract_sierra_program().unwrap(); - let executor = utils::get_native_executor(program, class_hash); - - ContractClass::V1Native( - NativeContractClassV1::new(executor, sierra_cc).unwrap(), - ) - } + compile_sierra_cc(flattened_sierra_cc, class_hash) } }) } @@ -282,6 +250,48 @@ impl StateReader for RpcStateReader { } } +fn compile_sierra_cc( + flattened_sierra_cc: starknet::core::types::FlattenedSierraClass, + class_hash: ClassHash, +) -> ContractClass { + let middle_sierra: utils::MiddleSierraContractClass = { + let v = serde_json::to_value(flattened_sierra_cc).unwrap(); + serde_json::from_value(v).unwrap() + }; + let sierra_cc = cairo_lang_starknet_classes::contract_class::ContractClass { + sierra_program: middle_sierra.sierra_program, + contract_class_version: middle_sierra.contract_class_version, + entry_points_by_type: middle_sierra.entry_points_by_type, + sierra_program_debug_info: None, + abi: None, + }; + + if cfg!(feature = "only_casm") { + let casm_cc = + cairo_lang_starknet_classes::casm_contract_class::CasmContractClass::from_contract_class(sierra_cc, false, usize::MAX).unwrap(); + ContractClass::V1(casm_cc.try_into().unwrap()) + } else { + let program = sierra_cc.extract_sierra_program().unwrap(); + let executor = utils::get_native_executor(program, class_hash); + + ContractClass::V1Native(NativeContractClassV1::new(executor, sierra_cc).unwrap()) + } +} + +fn compile_legacy_cc( + compressed_legacy_cc: starknet::core::types::CompressedLegacyContractClass, +) -> ContractClass { + let as_str = utils::decode_reader(compressed_legacy_cc.program).unwrap(); + let program = Program::from_bytes(as_str.as_bytes(), None).unwrap(); + let entry_points_by_type = + utils::map_entry_points_by_type_legacy(compressed_legacy_cc.entry_points_by_type); + let inner = Arc::new(ContractClassV0Inner { + program, + entry_points_by_type, + }); + ContractClass::V0(ContractClassV0(inner)) +} + #[cfg(test)] mod tests { use std::num::NonZeroU128; From 19373d13946a3a41e672cbc74dc948adc9bdcedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 15:29:19 -0300 Subject: [PATCH 27/31] Fix bug --- replay/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replay/src/main.rs b/replay/src/main.rs index 62555cb..ba63dd2 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -132,7 +132,7 @@ fn main() { for tx_hash in transaction_hashes { show_execution_data( &mut state, - tx_hash.to_string(), + tx_hash.0.to_hex_string(), &chain, block_number, charge_fee, From c06b11a1e349ad9c842f90f900920aa0fddf957c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 16:31:16 -0300 Subject: [PATCH 28/31] Make transaction deser clearer --- rpc-state-reader/src/objects.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rpc-state-reader/src/objects.rs b/rpc-state-reader/src/objects.rs index c8c331d..e9757fd 100644 --- a/rpc-state-reader/src/objects.rs +++ b/rpc-state-reader/src/objects.rs @@ -176,8 +176,15 @@ pub mod deser { } } - let tx_type: String = serde_json::from_value(transaction["type"].clone())?; - let tx_version: String = serde_json::from_value(transaction["version"].clone())?; + #[derive(Deserialize)] + struct Header { + r#type: String, + version: String, + } + let Header { + r#type: tx_type, + version: tx_version, + } = serde_json::from_value(transaction.clone())?; match tx_type.as_str() { "INVOKE" => match tx_version.as_str() { From c8460febc1bc3cf2bd8630d5280e18169530e598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 17:23:51 -0300 Subject: [PATCH 29/31] Remove unsued dep --- rpc-state-reader/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/rpc-state-reader/Cargo.toml b/rpc-state-reader/Cargo.toml index 43e71c2..bd84136 100644 --- a/rpc-state-reader/Cargo.toml +++ b/rpc-state-reader/Cargo.toml @@ -24,7 +24,6 @@ cairo-native = { workspace = true } starknet = "0.7.0" thiserror = { workspace = true } flate2 = "1.0.25" -dotenv = "0.15.0" cairo-vm = "1.0.0-rc5" blockifier = { workspace = true } starknet_gateway = { workspace = true } From fac32bb866ca7691a95c6767910f729c49951b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 17:24:11 -0300 Subject: [PATCH 30/31] Reorder deps --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2fcba78..847a0fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,7 @@ tracing = "0.1" serde_json = "1.0.116" serde_with = "3.9.0" serde = "1.0.197" - cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "355c250f37cf0977ef2776b1aae2cb2e87c9da3d" } - # Sequencer Dependencies starknet_api = { git = "https://github.com/lambdaclass/sequencer", rev = "1b1b95cae7ae07b9bc778443ca75ee18008a6bc8"} blockifier = { git = "https://github.com/lambdaclass/sequencer", rev = "1b1b95cae7ae07b9bc778443ca75ee18008a6bc8"} From 77bd3a082c2d7efec008a4715fa3e14ab9e301e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Wed, 23 Oct 2024 18:23:45 -0300 Subject: [PATCH 31/31] Update lock --- Cargo.lock | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c919305..14aa128 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2023,12 +2023,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "dotenv" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" - [[package]] name = "downcast" version = "0.11.0" @@ -5144,7 +5138,6 @@ dependencies = [ "cairo-lang-utils", "cairo-native", "cairo-vm", - "dotenv", "flate2", "pretty_assertions_sorted", "serde",