From 33f68b2636ba8ecda9a57b2e140212d950bb57e6 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Wed, 20 Sep 2023 09:12:32 +0700 Subject: [PATCH 1/9] implement blockifier --- Cargo.lock | 1 + Cargo.toml | 1 + crates/sequencer/Cargo.toml | 3 + crates/sequencer/src/state.rs | 232 ++++++++++++++++++++++++++++++++++ 4 files changed, 237 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b94b1a5d..057e83d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7918,6 +7918,7 @@ name = "sequencer" version = "0.1.0" dependencies = [ "blockifier", + "lazy_static", "rustc-hash", "starknet_api", ] diff --git a/Cargo.toml b/Cargo.toml index 1a6b1725..6c5006de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ chrono = { version = "0.4.26", features = ["serde"] } ctor = "0.2.4" dotenv = "0.15.0" eyre = "0.6.8" +lazy_static = "1.4.0" regex = "1.9.3" reqwest = { version = "0.11.20", features = ["gzip"] } rstest = "0.18.1" diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index 9abd6584..697b84d5 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -18,3 +18,6 @@ starknet_api = { workspace = true } # Other rustc-hash = "1.1.0" + +[dev-dependencies] +lazy_static = { workspace = true } diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index 1a375d97..672ba9d3 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -1,8 +1,14 @@ +use blockifier::state::cached_state::CommitmentStateDiff; +use blockifier::state::errors::StateError; +use blockifier::state::state_api::{ + State as BlockifierState, StateReader as BlockifierStateReader, StateResult, +}; use blockifier::{ execution::contract_class::ContractClass, state::cached_state::ContractStorageKey, }; use rustc_hash::FxHashMap; use starknet_api::core::CompiledClassHash; +use starknet_api::state::StorageKey; use starknet_api::{ core::{ClassHash, ContractAddress, Nonce}, hash::StarkFelt, @@ -22,3 +28,229 @@ pub struct State { pub storage: FxHashMap, pub nonces: FxHashMap, } + +impl BlockifierState for State { + fn set_storage_at( + &mut self, + contract_address: ContractAddress, + key: StorageKey, + value: StarkFelt, + ) { + self.storage.insert((contract_address, key), value); + } + + fn increment_nonce(&mut self, contract_address: ContractAddress) -> StateResult<()> { + let current_nonce = self + .nonces + .get(&contract_address) + .cloned() + .unwrap_or_default(); + + let mut current_nonce: u64 = current_nonce.0.try_into()?; + current_nonce += 1; + + self.nonces + .insert(contract_address, Nonce(StarkFelt::from(current_nonce))); + + Ok(()) + } + + fn set_class_hash_at( + &mut self, + contract_address: ContractAddress, + class_hash: ClassHash, + ) -> StateResult<()> { + self.contracts.insert(contract_address, class_hash); + Ok(()) + } + + fn set_contract_class( + &mut self, + class_hash: &ClassHash, + contract_class: ContractClass, + ) -> StateResult<()> { + self.classes.insert(class_hash.to_owned(), contract_class); + Ok(()) + } + + fn set_compiled_class_hash( + &mut self, + class_hash: ClassHash, + compiled_class_hash: CompiledClassHash, + ) -> StateResult<()> { + self.compiled_classes + .insert(class_hash, compiled_class_hash); + Ok(()) + } + + fn to_state_diff(&self) -> CommitmentStateDiff { + unreachable!("to_state_diff should not be called in the sequencer") + } +} + +impl BlockifierStateReader for State { + /// Default: 0 for an uninitialized contract address. + fn get_storage_at( + &mut self, + contract_address: ContractAddress, + key: StorageKey, + ) -> StateResult { + Ok(self + .storage + .get(&(contract_address, key)) + .cloned() + .unwrap_or_default()) + } + + /// Default: 0 for an uninitialized contract address. + fn get_nonce_at(&mut self, contract_address: ContractAddress) -> StateResult { + Ok(self + .nonces + .get(&contract_address) + .cloned() + .unwrap_or_default()) + } + + /// Default: 0 (uninitialized class hash) for an uninitialized contract address. + fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { + Ok(self + .contracts + .get(&contract_address) + .cloned() + .unwrap_or_default()) + } + + /// Errors if the compiled class hash is not declared. + fn get_compiled_contract_class( + &mut self, + class_hash: &ClassHash, + ) -> StateResult { + self.classes + .get(class_hash) + .cloned() + .ok_or_else(|| StateError::UndeclaredClassHash(class_hash.to_owned())) + } + + /// Errors if the class hash is not declared. + fn get_compiled_class_hash(&mut self, class_hash: ClassHash) -> StateResult { + self.compiled_classes + .get(&class_hash) + .cloned() + .ok_or_else(|| StateError::UndeclaredClassHash(class_hash)) + } +} + +#[cfg(test)] +mod tests { + use blockifier::execution::contract_class::ContractClassV0; + use starknet_api::core::PatriciaKey; + + use super::*; + lazy_static::lazy_static! { + static ref ONE_FELT: StarkFelt = StarkFelt::from(1u8); + static ref ONE_PATRICIA: PatriciaKey = TryInto::::try_into(*ONE_FELT).unwrap(); + static ref ONE_HASH: ClassHash = ClassHash(*ONE_FELT); + static ref ONE_COMPILED_HASH: CompiledClassHash = CompiledClassHash(*ONE_FELT); + static ref TEST_ADDRESS: ContractAddress = ContractAddress(*ONE_PATRICIA); + } + + #[test] + fn test_storage() { + // Given + let mut state = State::default(); + + // When + state.set_storage_at(*TEST_ADDRESS, StorageKey(*ONE_PATRICIA), *ONE_FELT); + + // Then + let expected = *ONE_FELT; + let actual = state + .get_storage_at(*TEST_ADDRESS, StorageKey(*ONE_PATRICIA)) + .unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_nonce() { + // Given + let mut state = State::default(); + + // When + state.increment_nonce(*TEST_ADDRESS).unwrap(); + + // Then + let expected = Nonce(*ONE_FELT); + let actual = state.get_nonce_at(*TEST_ADDRESS).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_class_hash() { + // Given + let mut state = State::default(); + + // When + state.set_class_hash_at(*TEST_ADDRESS, *ONE_HASH).unwrap(); + + // Then + let expected = *ONE_HASH; + let actual = state.get_class_hash_at(*TEST_ADDRESS).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_contract_class() { + // Given + let mut state = State::default(); + + // When + state + .set_contract_class(&ONE_HASH, ContractClass::V0(ContractClassV0::default())) + .unwrap(); + + // Then + let expected = ContractClass::V0(ContractClassV0::default()); + let actual = state.get_compiled_contract_class(&ONE_HASH).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + #[should_panic( + expected = "UndeclaredClassHash(ClassHash(StarkFelt(\"0x0000000000000000000000000000000000000000000000000000000000000001\")))" + )] + fn test_uninitialized_contract_class() { + // Given + let mut state = State::default(); + + // When + state.get_compiled_contract_class(&ONE_HASH).unwrap(); + } + + #[test] + fn test_compiled_class_hash() { + // Given + let mut state = State::default(); + + // When + state + .set_compiled_class_hash(*ONE_HASH, *ONE_COMPILED_HASH) + .unwrap(); + + // Then + let expected = *ONE_COMPILED_HASH; + let actual = state.get_compiled_class_hash(*ONE_HASH).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + #[should_panic( + expected = "UndeclaredClassHash(ClassHash(StarkFelt(\"0x0000000000000000000000000000000000000000000000000000000000000001\"))" + )] + fn test_uninitialized_compiled_class_hash() { + // Given + let mut state = State::default(); + + // When + state.get_compiled_class_hash(*ONE_HASH).unwrap(); + } +} From 02d761f9d81246c3d4c9e63b184e5e80c4c2336f Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Wed, 20 Sep 2023 21:52:04 +0700 Subject: [PATCH 2/9] move blockifier from workspace to maintain two versions --- Cargo.toml | 5 ++-- crates/ef-testing/Cargo.toml | 7 +++-- crates/sequencer/Cargo.toml | 2 +- crates/sequencer/src/config.rs | 1 - crates/sequencer/src/constants.rs | 27 +++++++++++++++++ crates/sequencer/src/lib.rs | 2 +- crates/sequencer/src/sequencer.rs | 18 +++++++---- crates/sequencer/src/state.rs | 50 ++++++++++++++----------------- 8 files changed, 72 insertions(+), 40 deletions(-) delete mode 100644 crates/sequencer/src/config.rs create mode 100644 crates/sequencer/src/constants.rs diff --git a/Cargo.toml b/Cargo.toml index 6c5006de..5902a7b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,8 @@ reqwest = { version = "0.11.20", features = ["gzip"] } rstest = "0.18.1" thiserror = "1.0.47" tokio = { version = "1.21.2", features = ["macros"] } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } walkdir = "2.3.3" zip = "0.6.6" @@ -60,9 +62,6 @@ zip = "0.6.6" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0" -[patch."https://github.com/starkware-libs/blockifier"] -blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "c794d1b" } - [patch."https://github.com/ethereum/c-kzg-4844"] c-kzg = { git = "https://github.com/rjected/c-kzg-4844", branch = "dan/add-serde-feature" } diff --git a/crates/ef-testing/Cargo.toml b/crates/ef-testing/Cargo.toml index 21c02c1c..211cdf4b 100644 --- a/crates/ef-testing/Cargo.toml +++ b/crates/ef-testing/Cargo.toml @@ -40,12 +40,12 @@ regex = { workspace = true } reqwest = { workspace = true, optional = true } rstest = { workspace = true } tokio = { workspace = true } -tracing = "0.1.37" +tracing = { workspace = true } walkdir = { workspace = true } zip = { workspace = true, optional = true } [dev-dependencies] -tracing-subscriber = "0.3.17" +tracing-subscriber = { workspace = true } [features] ef-tests = [] @@ -61,3 +61,6 @@ required-features = ["dump"] name = "fetch-kakarot-submodule-commit" path = "src/bin/fetch_kakarot_submodule_commit.rs" required-features = ["fetch-commit"] + +[patch."https://github.com/starkware-libs/blockifier"] +blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "c794d1b" } diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index 697b84d5..dc1f7dfa 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -14,7 +14,7 @@ license.workspace = true [dependencies] # Starknet blockifier = { git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" } -starknet_api = { workspace = true } +starknet_api = "0.5.0-rc1" # Other rustc-hash = "1.1.0" diff --git a/crates/sequencer/src/config.rs b/crates/sequencer/src/config.rs deleted file mode 100644 index 989c9ba7..00000000 --- a/crates/sequencer/src/config.rs +++ /dev/null @@ -1 +0,0 @@ -pub struct SequencerConfig {} diff --git a/crates/sequencer/src/constants.rs b/crates/sequencer/src/constants.rs new file mode 100644 index 00000000..010c3e45 --- /dev/null +++ b/crates/sequencer/src/constants.rs @@ -0,0 +1,27 @@ +#[cfg(test)] +pub mod test_constants { + use starknet::core::types::FieldElement; + use starknet_api::{ + block::{BlockNumber, BlockTimestamp}, + core::{ClassHash, CompiledClassHash, ContractAddress, PatriciaKey}, + hash::StarkFelt, + }; + + lazy_static::lazy_static! { + pub static ref SENDER_ADDRESS: FieldElement = FieldElement::from(2u8); + pub static ref SEQUENCER_ADDRESS: ContractAddress = ContractAddress(TryInto::::try_into(StarkFelt::from(1234u16)).unwrap()); + pub static ref FEE_TOKEN_ADDRESS: ContractAddress = ContractAddress(TryInto::::try_into(StarkFelt::from(12345u16)).unwrap()); + + pub static ref ONE_FELT: StarkFelt = StarkFelt::from(1u8); + pub static ref TWO_FELT: StarkFelt = StarkFelt::from(2u8); + pub static ref ONE_PATRICIA: PatriciaKey = TryInto::::try_into(*ONE_FELT).unwrap(); + pub static ref TWO_PATRICIA: PatriciaKey = TryInto::::try_into(*TWO_FELT).unwrap(); + pub static ref ONE_HASH: ClassHash = ClassHash(*ONE_FELT); + pub static ref TWO_HASH: ClassHash = ClassHash(*TWO_FELT); + pub static ref ONE_COMPILED_HASH: CompiledClassHash = CompiledClassHash(*ONE_FELT); + pub static ref ONE_BLOCK_NUMBER: BlockNumber = BlockNumber(1); + pub static ref ONE_BLOCK_TIMESTAMP: BlockTimestamp = BlockTimestamp(1); + pub static ref TEST_ADDRESS: ContractAddress = ContractAddress(*ONE_PATRICIA); + pub static ref TEST_ACCOUNT: ContractAddress = ContractAddress(*TWO_PATRICIA); + } +} diff --git a/crates/sequencer/src/lib.rs b/crates/sequencer/src/lib.rs index 4f4593df..d43a0535 100644 --- a/crates/sequencer/src/lib.rs +++ b/crates/sequencer/src/lib.rs @@ -1,3 +1,3 @@ -pub mod config; +pub mod constants; pub mod sequencer; pub mod state; diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index e4d845b8..dc4f394c 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -4,14 +4,22 @@ use blockifier::state::state_api::{State, StateReader}; /// Sequencer is the main struct of the sequencer crate. /// Using a trait bound for the state allows for better /// speed, as the type of the state is known at compile time. -pub struct Sequencer { - pub config: SequencerConfig, +pub struct Sequencer +where + for<'a> &'a mut S: State + StateReader, +{ + pub context: BlockContext, pub state: S, } -impl Sequencer { +impl Sequencer +where + for<'a> &'a mut S: State + StateReader, +{ /// Creates a new Sequencer instance. - pub fn new(config: SequencerConfig, state: S) -> Self { - Self { config, state } + pub fn new(context: BlockContext, state: S) -> Self { + Self { context, state } + } +} } } diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index 672ba9d3..e1a9959f 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -22,14 +22,14 @@ use starknet_api::{ /// See [rustc-hash](https://crates.io/crates/rustc-hash) for more information. #[derive(Default)] pub struct State { - pub classes: FxHashMap, - pub compiled_classes: FxHashMap, - pub contracts: FxHashMap, - pub storage: FxHashMap, - pub nonces: FxHashMap, + classes: FxHashMap, + compiled_class_hashes: FxHashMap, + contracts: FxHashMap, + storage: FxHashMap, + nonces: FxHashMap, } -impl BlockifierState for State { +impl<'a> BlockifierState for &'a mut State { fn set_storage_at( &mut self, contract_address: ContractAddress, @@ -78,17 +78,17 @@ impl BlockifierState for State { class_hash: ClassHash, compiled_class_hash: CompiledClassHash, ) -> StateResult<()> { - self.compiled_classes + self.compiled_class_hashes .insert(class_hash, compiled_class_hash); Ok(()) } - fn to_state_diff(&self) -> CommitmentStateDiff { + fn to_state_diff(&mut self) -> CommitmentStateDiff { unreachable!("to_state_diff should not be called in the sequencer") } } -impl BlockifierStateReader for State { +impl<'a> BlockifierStateReader for &'a mut State { /// Default: 0 for an uninitialized contract address. fn get_storage_at( &mut self, @@ -120,7 +120,7 @@ impl BlockifierStateReader for State { .unwrap_or_default()) } - /// Errors if the compiled class hash is not declared. + /// Errors if the compiled class is not declared. fn get_compiled_contract_class( &mut self, class_hash: &ClassHash, @@ -131,9 +131,9 @@ impl BlockifierStateReader for State { .ok_or_else(|| StateError::UndeclaredClassHash(class_hash.to_owned())) } - /// Errors if the class hash is not declared. + /// Errors if the compiled class hash is not declared. fn get_compiled_class_hash(&mut self, class_hash: ClassHash) -> StateResult { - self.compiled_classes + self.compiled_class_hashes .get(&class_hash) .cloned() .ok_or_else(|| StateError::UndeclaredClassHash(class_hash)) @@ -143,21 +143,17 @@ impl BlockifierStateReader for State { #[cfg(test)] mod tests { use blockifier::execution::contract_class::ContractClassV0; - use starknet_api::core::PatriciaKey; + + use crate::constants::test_constants::{ + ONE_COMPILED_HASH, ONE_FELT, ONE_HASH, ONE_PATRICIA, TEST_ADDRESS, + }; use super::*; - lazy_static::lazy_static! { - static ref ONE_FELT: StarkFelt = StarkFelt::from(1u8); - static ref ONE_PATRICIA: PatriciaKey = TryInto::::try_into(*ONE_FELT).unwrap(); - static ref ONE_HASH: ClassHash = ClassHash(*ONE_FELT); - static ref ONE_COMPILED_HASH: CompiledClassHash = CompiledClassHash(*ONE_FELT); - static ref TEST_ADDRESS: ContractAddress = ContractAddress(*ONE_PATRICIA); - } #[test] fn test_storage() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state.set_storage_at(*TEST_ADDRESS, StorageKey(*ONE_PATRICIA), *ONE_FELT); @@ -173,7 +169,7 @@ mod tests { #[test] fn test_nonce() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state.increment_nonce(*TEST_ADDRESS).unwrap(); @@ -187,7 +183,7 @@ mod tests { #[test] fn test_class_hash() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state.set_class_hash_at(*TEST_ADDRESS, *ONE_HASH).unwrap(); @@ -201,7 +197,7 @@ mod tests { #[test] fn test_contract_class() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state @@ -220,7 +216,7 @@ mod tests { )] fn test_uninitialized_contract_class() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state.get_compiled_contract_class(&ONE_HASH).unwrap(); @@ -229,7 +225,7 @@ mod tests { #[test] fn test_compiled_class_hash() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state @@ -248,7 +244,7 @@ mod tests { )] fn test_uninitialized_compiled_class_hash() { // Given - let mut state = State::default(); + let mut state = &mut State::default(); // When state.get_compiled_class_hash(*ONE_HASH).unwrap(); From 057eb26e5f2318a7325b3e78844dd40b7c5879d5 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Wed, 20 Sep 2023 21:57:44 +0700 Subject: [PATCH 3/9] view toml --- Cargo.lock | 115 +++++++++++++++++++++++++++--- crates/sequencer/Cargo.toml | 1 + crates/sequencer/src/sequencer.rs | 4 +- 3 files changed, 106 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 057e83d2..da99f670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -716,11 +716,49 @@ dependencies = [ [[package]] name = "blockifier" -version = "0.1.0-rc0" -source = "git+https://github.com/dojoengine/blockifier?rev=c794d1b#c794d1b85b0937de9e0f4e3edbc9322792f7ab2e" +version = "0.3.0-rc0" +source = "git+https://github.com/starkware-libs/blockifier.git?tag=v0.3.0-rc0#72087fe729a950f284189fa74304824e7c1c99ee" dependencies = [ + "ark-ec", + "ark-ff 0.4.2", + "ark-secp256k1", + "ark-secp256r1", + "cached", + "cairo-felt", + "cairo-lang-casm", + "cairo-lang-runner", + "cairo-lang-starknet", + "cairo-vm", + "ctor", + "derive_more", + "indexmap 1.9.3", + "itertools 0.10.5", + "keccak", + "log", + "num-bigint", + "num-integer", + "num-traits 0.2.16", + "phf", + "serde", + "serde_json", + "sha3", + "starknet-crypto 0.5.1", + "starknet_api 0.5.0-rc1", + "strum 0.24.1", + "strum_macros 0.24.3", + "thiserror", +] + +[[package]] +name = "blockifier" +version = "0.3.0-rc0" +source = "git+https://github.com/starkware-libs/blockifier#35c33206cd893e22dc5eb8dad480936b2372f57a" +dependencies = [ + "ark-ec", "ark-ff 0.4.2", "ark-secp256k1", + "ark-secp256r1", + "cached", "cairo-felt", "cairo-lang-casm", "cairo-lang-runner", @@ -740,7 +778,7 @@ dependencies = [ "serde_json", "sha3", "starknet-crypto 0.5.1", - "starknet_api", + "starknet_api 0.5.0-rc1", "strum 0.24.1", "strum_macros 0.24.3", "thiserror", @@ -996,6 +1034,42 @@ dependencies = [ "serde", ] +[[package]] +name = "cached" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b195e4fbc4b6862bbd065b991a34750399c119797efff72492f28a5864de8700" +dependencies = [ + "async-trait", + "cached_proc_macro", + "cached_proc_macro_types", + "futures", + "hashbrown 0.13.2", + "instant", + "once_cell", + "thiserror", + "tokio", +] + +[[package]] +name = "cached_proc_macro" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b48814962d2fd604c50d2b9433c2a41a0ab567779ee2c02f7fba6eca1221f082" +dependencies = [ + "cached_proc_macro_types", + "darling 0.14.4", + "proc-macro2 1.0.67", + "quote 1.0.33", + "syn 1.0.109", +] + +[[package]] +name = "cached_proc_macro_types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" + [[package]] name = "cairo-felt" version = "0.8.2" @@ -2472,7 +2546,7 @@ dependencies = [ "serde", "serde_json", "starknet", - "starknet_api", + "starknet_api 0.2.0", "thiserror", "tokio", "tracing", @@ -5277,7 +5351,7 @@ dependencies = [ "serde_with", "starknet", "starknet-crypto 0.6.0", - "starknet_api", + "starknet_api 0.2.0", "tokio", "tracing", "tracing-subscriber", @@ -5292,7 +5366,7 @@ dependencies = [ "anyhow", "async-trait", "auto_impl", - "blockifier", + "blockifier 0.3.0-rc0 (git+https://github.com/starkware-libs/blockifier)", "cairo-lang-casm", "cairo-lang-starknet", "cairo-vm", @@ -5306,7 +5380,7 @@ dependencies = [ "serde_json", "serde_with", "starknet", - "starknet_api", + "starknet_api 0.2.0", "thiserror", "tokio", "tracing", @@ -5319,7 +5393,7 @@ version = "0.2.1" source = "git+https://github.com/dojoengine/dojo?rev=b924dac#b924dac179726a6af56f4b61f0d66883e16aa76e" dependencies = [ "anyhow", - "blockifier", + "blockifier 0.3.0-rc0 (git+https://github.com/starkware-libs/blockifier)", "cairo-lang-starknet", "cairo-vm", "flate2", @@ -5332,7 +5406,7 @@ dependencies = [ "serde_json", "serde_with", "starknet", - "starknet_api", + "starknet_api 0.2.0", "thiserror", "tokio", "tower", @@ -7917,10 +7991,11 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" name = "sequencer" version = "0.1.0" dependencies = [ - "blockifier", + "blockifier 0.3.0-rc0 (git+https://github.com/starkware-libs/blockifier.git?tag=v0.3.0-rc0)", "lazy_static", "rustc-hash", - "starknet_api", + "starknet", + "starknet_api 0.5.0-rc1", ] [[package]] @@ -8517,6 +8592,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "starknet_api" +version = "0.5.0-rc1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f70f6673391b3f3624651e8692f4e76aab9194abb3d3feeb3a07a6b0546639ee" +dependencies = [ + "cairo-lang-starknet", + "derive_more", + "hex", + "indexmap 1.9.3", + "once_cell", + "primitive-types", + "serde", + "serde_json", + "starknet-crypto 0.5.1", + "thiserror", +] + [[package]] name = "static_assertions" version = "1.1.0" diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index dc1f7dfa..0f1eee6b 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -15,6 +15,7 @@ license.workspace = true # Starknet blockifier = { git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" } starknet_api = "0.5.0-rc1" +starknet = { workspace = true } # Other rustc-hash = "1.1.0" diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index dc4f394c..7e579c2f 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -1,4 +1,4 @@ -use crate::config::SequencerConfig; +use blockifier::block_context::BlockContext; use blockifier::state::state_api::{State, StateReader}; /// Sequencer is the main struct of the sequencer crate. @@ -20,6 +20,4 @@ where pub fn new(context: BlockContext, state: S) -> Self { Self { context, state } } -} - } } From 5be042401ef282e4d86e760a59fd1eea17ee82c4 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 09:16:04 +0700 Subject: [PATCH 4/9] update manifests --- Cargo.toml | 3 +++ crates/ef-testing/Cargo.toml | 3 --- crates/sequencer/Cargo.toml | 4 ++-- crates/sequencer/src/constants.rs | 6 ++++-- crates/sequencer/src/state.rs | 20 ++++++++++++-------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5902a7b4..16791673 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,9 @@ zip = "0.6.6" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0" +[patch."https://github.com/starkware-libs/blockifier"] +blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "c794d1b" } + [patch."https://github.com/ethereum/c-kzg-4844"] c-kzg = { git = "https://github.com/rjected/c-kzg-4844", branch = "dan/add-serde-feature" } diff --git a/crates/ef-testing/Cargo.toml b/crates/ef-testing/Cargo.toml index 211cdf4b..5bd2be00 100644 --- a/crates/ef-testing/Cargo.toml +++ b/crates/ef-testing/Cargo.toml @@ -61,6 +61,3 @@ required-features = ["dump"] name = "fetch-kakarot-submodule-commit" path = "src/bin/fetch_kakarot_submodule_commit.rs" required-features = ["fetch-commit"] - -[patch."https://github.com/starkware-libs/blockifier"] -blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "c794d1b" } diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index 0f1eee6b..dfe10af5 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -13,8 +13,8 @@ license.workspace = true [dependencies] # Starknet -blockifier = { git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" } -starknet_api = "0.5.0-rc1" +blockifier = { package = "blockifier", git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" } +starknet_api = { workspace = true } starknet = { workspace = true } # Other diff --git a/crates/sequencer/src/constants.rs b/crates/sequencer/src/constants.rs index 010c3e45..d07edee6 100644 --- a/crates/sequencer/src/constants.rs +++ b/crates/sequencer/src/constants.rs @@ -8,6 +8,10 @@ pub mod test_constants { }; lazy_static::lazy_static! { + pub static ref TEST_CONTRACT_ADDRESS: ContractAddress = ContractAddress(*ONE_PATRICIA); + pub static ref TEST_CONTRACT_ACCOUNT: ContractAddress = ContractAddress(*TWO_PATRICIA); + pub static ref TEST_ADDRESS: StarkFelt = *ONE_FELT; + pub static ref TEST_CONTRACT: StarkFelt = *TWO_FELT; pub static ref SENDER_ADDRESS: FieldElement = FieldElement::from(2u8); pub static ref SEQUENCER_ADDRESS: ContractAddress = ContractAddress(TryInto::::try_into(StarkFelt::from(1234u16)).unwrap()); pub static ref FEE_TOKEN_ADDRESS: ContractAddress = ContractAddress(TryInto::::try_into(StarkFelt::from(12345u16)).unwrap()); @@ -21,7 +25,5 @@ pub mod test_constants { pub static ref ONE_COMPILED_HASH: CompiledClassHash = CompiledClassHash(*ONE_FELT); pub static ref ONE_BLOCK_NUMBER: BlockNumber = BlockNumber(1); pub static ref ONE_BLOCK_TIMESTAMP: BlockTimestamp = BlockTimestamp(1); - pub static ref TEST_ADDRESS: ContractAddress = ContractAddress(*ONE_PATRICIA); - pub static ref TEST_ACCOUNT: ContractAddress = ContractAddress(*TWO_PATRICIA); } } diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index e1a9959f..b5a41828 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -29,6 +29,8 @@ pub struct State { nonces: FxHashMap, } +/// State implementation for the sequencer. We use a mutable reference to the state +/// because this is what will be available during the implementation of the execution. impl<'a> BlockifierState for &'a mut State { fn set_storage_at( &mut self, @@ -83,7 +85,7 @@ impl<'a> BlockifierState for &'a mut State { Ok(()) } - fn to_state_diff(&mut self) -> CommitmentStateDiff { + fn to_state_diff(&self) -> CommitmentStateDiff { unreachable!("to_state_diff should not be called in the sequencer") } } @@ -145,7 +147,7 @@ mod tests { use blockifier::execution::contract_class::ContractClassV0; use crate::constants::test_constants::{ - ONE_COMPILED_HASH, ONE_FELT, ONE_HASH, ONE_PATRICIA, TEST_ADDRESS, + ONE_COMPILED_HASH, ONE_FELT, ONE_HASH, ONE_PATRICIA, TEST_CONTRACT_ADDRESS, }; use super::*; @@ -156,12 +158,12 @@ mod tests { let mut state = &mut State::default(); // When - state.set_storage_at(*TEST_ADDRESS, StorageKey(*ONE_PATRICIA), *ONE_FELT); + state.set_storage_at(*TEST_CONTRACT_ADDRESS, StorageKey(*ONE_PATRICIA), *ONE_FELT); // Then let expected = *ONE_FELT; let actual = state - .get_storage_at(*TEST_ADDRESS, StorageKey(*ONE_PATRICIA)) + .get_storage_at(*TEST_CONTRACT_ADDRESS, StorageKey(*ONE_PATRICIA)) .unwrap(); assert_eq!(expected, actual); } @@ -172,11 +174,11 @@ mod tests { let mut state = &mut State::default(); // When - state.increment_nonce(*TEST_ADDRESS).unwrap(); + state.increment_nonce(*TEST_CONTRACT_ADDRESS).unwrap(); // Then let expected = Nonce(*ONE_FELT); - let actual = state.get_nonce_at(*TEST_ADDRESS).unwrap(); + let actual = state.get_nonce_at(*TEST_CONTRACT_ADDRESS).unwrap(); assert_eq!(expected, actual); } @@ -186,11 +188,13 @@ mod tests { let mut state = &mut State::default(); // When - state.set_class_hash_at(*TEST_ADDRESS, *ONE_HASH).unwrap(); + state + .set_class_hash_at(*TEST_CONTRACT_ADDRESS, *ONE_HASH) + .unwrap(); // Then let expected = *ONE_HASH; - let actual = state.get_class_hash_at(*TEST_ADDRESS).unwrap(); + let actual = state.get_class_hash_at(*TEST_CONTRACT_ADDRESS).unwrap(); assert_eq!(expected, actual); } From 06491c5e2e5aa22a131c14d23fc12b92e0f0fc9e Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 09:17:54 +0700 Subject: [PATCH 5/9] lock --- Cargo.lock | 292 +++++++++++++++-------------------------------------- 1 file changed, 80 insertions(+), 212 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da99f670..ba8e40ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] @@ -388,15 +388,6 @@ dependencies = [ "rand", ] -[[package]] -name = "array-init" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" -dependencies = [ - "nodrop", -] - [[package]] name = "arrayvec" version = "0.7.4" @@ -716,49 +707,11 @@ dependencies = [ [[package]] name = "blockifier" -version = "0.3.0-rc0" -source = "git+https://github.com/starkware-libs/blockifier.git?tag=v0.3.0-rc0#72087fe729a950f284189fa74304824e7c1c99ee" -dependencies = [ - "ark-ec", - "ark-ff 0.4.2", - "ark-secp256k1", - "ark-secp256r1", - "cached", - "cairo-felt", - "cairo-lang-casm", - "cairo-lang-runner", - "cairo-lang-starknet", - "cairo-vm", - "ctor", - "derive_more", - "indexmap 1.9.3", - "itertools 0.10.5", - "keccak", - "log", - "num-bigint", - "num-integer", - "num-traits 0.2.16", - "phf", - "serde", - "serde_json", - "sha3", - "starknet-crypto 0.5.1", - "starknet_api 0.5.0-rc1", - "strum 0.24.1", - "strum_macros 0.24.3", - "thiserror", -] - -[[package]] -name = "blockifier" -version = "0.3.0-rc0" -source = "git+https://github.com/starkware-libs/blockifier#35c33206cd893e22dc5eb8dad480936b2372f57a" +version = "0.1.0-rc0" +source = "git+https://github.com/dojoengine/blockifier?rev=c794d1b#c794d1b85b0937de9e0f4e3edbc9322792f7ab2e" dependencies = [ - "ark-ec", "ark-ff 0.4.2", "ark-secp256k1", - "ark-secp256r1", - "cached", "cairo-felt", "cairo-lang-casm", "cairo-lang-runner", @@ -778,7 +731,7 @@ dependencies = [ "serde_json", "sha3", "starknet-crypto 0.5.1", - "starknet_api 0.5.0-rc1", + "starknet_api", "strum 0.24.1", "strum_macros 0.24.3", "thiserror", @@ -787,7 +740,7 @@ dependencies = [ [[package]] name = "boa_ast" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "bitflags 2.4.0", "boa_interner", @@ -800,7 +753,7 @@ dependencies = [ [[package]] name = "boa_engine" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "bitflags 2.4.0", "boa_ast", @@ -838,7 +791,7 @@ dependencies = [ [[package]] name = "boa_gc" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "boa_macros", "boa_profiler", @@ -849,7 +802,7 @@ dependencies = [ [[package]] name = "boa_icu_provider" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "icu_collections", "icu_normalizer", @@ -862,7 +815,7 @@ dependencies = [ [[package]] name = "boa_interner" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "boa_gc", "boa_macros", @@ -877,7 +830,7 @@ dependencies = [ [[package]] name = "boa_macros" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "proc-macro2 1.0.67", "quote 1.0.33", @@ -888,7 +841,7 @@ dependencies = [ [[package]] name = "boa_parser" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" dependencies = [ "bitflags 2.4.0", "boa_ast", @@ -908,7 +861,7 @@ dependencies = [ [[package]] name = "boa_profiler" version = "0.17.0" -source = "git+https://github.com/boa-dev/boa#9da687496858551c0ded0deaf66076970dde9389" +source = "git+https://github.com/boa-dev/boa#986b048560f6f1a6f0fbe2724d3b7c59207e75b6" [[package]] name = "brotli" @@ -1034,42 +987,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cached" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b195e4fbc4b6862bbd065b991a34750399c119797efff72492f28a5864de8700" -dependencies = [ - "async-trait", - "cached_proc_macro", - "cached_proc_macro_types", - "futures", - "hashbrown 0.13.2", - "instant", - "once_cell", - "thiserror", - "tokio", -] - -[[package]] -name = "cached_proc_macro" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b48814962d2fd604c50d2b9433c2a41a0ab567779ee2c02f7fba6eca1221f082" -dependencies = [ - "cached_proc_macro_types", - "darling 0.14.4", - "proc-macro2 1.0.67", - "quote 1.0.33", - "syn 1.0.109", -] - -[[package]] -name = "cached_proc_macro_types" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" - [[package]] name = "cairo-felt" version = "0.8.2" @@ -1687,9 +1604,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.3" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" +checksum = "b1d7b8d5ec32af0fadc644bf1fd509a688c2103b185644bb1e29d164e0703136" dependencies = [ "clap_builder", "clap_derive", @@ -1707,9 +1624,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "5179bb514e4d7c2051749d8fcefa2ed6d06a9f4e6d69faf3805f5d80b8cf8d56" dependencies = [ "anstream", "anstyle", @@ -2492,9 +2409,9 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "dyn-clone" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" +checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" [[package]] name = "ecdsa" @@ -2546,7 +2463,7 @@ dependencies = [ "serde", "serde_json", "starknet", - "starknet_api 0.2.0", + "starknet_api", "thiserror", "tokio", "tracing", @@ -2625,9 +2542,9 @@ dependencies = [ [[package]] name = "enr" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0be7b2ac146c1f99fe245c02d16af0696450d8e06c135db75e10eeb9e642c20d" +checksum = "fe81b5c06ecfdbc71dd845216f225f53b62a10cb8a16c946836a3467f701d05b" dependencies = [ "base64 0.21.4", "bytes", @@ -2637,7 +2554,6 @@ dependencies = [ "rand", "rlp", "serde", - "serde-hex", "sha3", "zeroize", ] @@ -2896,7 +2812,7 @@ dependencies = [ [[package]] name = "ethers-core" version = "2.0.10" -source = "git+https://github.com/gakonst/ethers-rs#4ac0058f50571954596cabbe13a3d57351d9adac" +source = "git+https://github.com/gakonst/ethers-rs#08bcb67c36d9a2869950e51ecf76124c9febe035" dependencies = [ "arrayvec", "bytes", @@ -2937,7 +2853,7 @@ dependencies = [ [[package]] name = "ethers-etherscan" version = "2.0.10" -source = "git+https://github.com/gakonst/ethers-rs#4ac0058f50571954596cabbe13a3d57351d9adac" +source = "git+https://github.com/gakonst/ethers-rs#08bcb67c36d9a2869950e51ecf76124c9febe035" dependencies = [ "ethers-core 2.0.10 (git+https://github.com/gakonst/ethers-rs)", "reqwest", @@ -3066,7 +2982,7 @@ dependencies = [ [[package]] name = "ethers-solc" version = "2.0.10" -source = "git+https://github.com/gakonst/ethers-rs#4ac0058f50571954596cabbe13a3d57351d9adac" +source = "git+https://github.com/gakonst/ethers-rs#08bcb67c36d9a2869950e51ecf76124c9febe035" dependencies = [ "cfg-if", "const-hex", @@ -3242,7 +3158,7 @@ dependencies = [ [[package]] name = "foundry-config" version = "0.2.0" -source = "git+https://github.com/foundry-rs/foundry?branch=master#ecf9a10bab059130ef9b90d1b160b6a725a6e21a" +source = "git+https://github.com/foundry-rs/foundry?branch=master#83b9176a6d579e8cfd03741fe322a4420b3c9903" dependencies = [ "Inflector", "dirs-next", @@ -3422,7 +3338,7 @@ checksum = "6973ce8518068a71d404f428f6a5b563088545546a6bd8f9c0a7f2608149bc8a" dependencies = [ "genco-macros", "relative-path", - "smallvec 1.11.0", + "smallvec", ] [[package]] @@ -3512,7 +3428,7 @@ dependencies = [ "log", "once_cell", "signal-hook", - "smallvec 1.11.0", + "smallvec", "thiserror", "unicode-normalization", ] @@ -3556,7 +3472,7 @@ dependencies = [ "gix-quote", "kstring", "log", - "smallvec 1.11.0", + "smallvec", "thiserror", "unicode-bom", ] @@ -3618,7 +3534,7 @@ dependencies = [ "log", "memchr", "once_cell", - "smallvec 1.11.0", + "smallvec", "thiserror", "unicode-bom", "winnow", @@ -3731,7 +3647,7 @@ dependencies = [ "gix-path", "gix-quote", "gix-trace", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -3808,7 +3724,7 @@ dependencies = [ "gix-traverse", "itoa", "memmap2", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -3847,7 +3763,7 @@ dependencies = [ "gix-hash", "gix-object", "gix-revwalk", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -3867,7 +3783,7 @@ dependencies = [ "hex", "itoa", "nom", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -3908,7 +3824,7 @@ dependencies = [ "gix-traverse", "memmap2", "parking_lot 0.12.1", - "smallvec 1.11.0", + "smallvec", "thiserror", "uluru", ] @@ -3992,7 +3908,7 @@ dependencies = [ "gix-hash", "gix-revision", "gix-validate", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -4022,7 +3938,7 @@ dependencies = [ "gix-hash", "gix-hashtable", "gix-object", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -4071,7 +3987,7 @@ dependencies = [ "gix-hashtable", "gix-object", "gix-revwalk", - "smallvec 1.11.0", + "smallvec", "thiserror", ] @@ -4358,9 +4274,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -4563,7 +4479,7 @@ dependencies = [ "icu_collections", "icu_properties", "icu_provider", - "smallvec 1.11.0", + "smallvec", "utf16_iter", "utf8_iter", "write16", @@ -5351,7 +5267,7 @@ dependencies = [ "serde_with", "starknet", "starknet-crypto 0.6.0", - "starknet_api 0.2.0", + "starknet_api", "tokio", "tracing", "tracing-subscriber", @@ -5366,7 +5282,7 @@ dependencies = [ "anyhow", "async-trait", "auto_impl", - "blockifier 0.3.0-rc0 (git+https://github.com/starkware-libs/blockifier)", + "blockifier", "cairo-lang-casm", "cairo-lang-starknet", "cairo-vm", @@ -5380,7 +5296,7 @@ dependencies = [ "serde_json", "serde_with", "starknet", - "starknet_api 0.2.0", + "starknet_api", "thiserror", "tokio", "tracing", @@ -5393,7 +5309,7 @@ version = "0.2.1" source = "git+https://github.com/dojoengine/dojo?rev=b924dac#b924dac179726a6af56f4b61f0d66883e16aa76e" dependencies = [ "anyhow", - "blockifier 0.3.0-rc0 (git+https://github.com/starkware-libs/blockifier)", + "blockifier", "cairo-lang-starknet", "cairo-vm", "flate2", @@ -5406,7 +5322,7 @@ dependencies = [ "serde_json", "serde_with", "starknet", - "starknet_api 0.2.0", + "starknet_api", "thiserror", "tokio", "tower", @@ -5581,12 +5497,6 @@ dependencies = [ "rawpointer", ] -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "md-5" version = "0.10.5" @@ -5767,12 +5677,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "nom" version = "7.1.3" @@ -6060,9 +5964,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.1.3+3.1.2" +version = "300.1.5+3.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd2c101a165fff9935e34def4669595ab1c7847943c42be86e21503e482be107" +checksum = "559068e4c12950d7dcaa1857a61725c0d38d4fc03ff8e070ab31a75d6e316491" dependencies = [ "cc", ] @@ -6179,7 +6083,7 @@ dependencies = [ "instant", "libc", "redox_syscall 0.2.16", - "smallvec 1.11.0", + "smallvec", "winapi", ] @@ -6192,7 +6096,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall 0.3.5", - "smallvec 1.11.0", + "smallvec", "windows-targets 0.48.5", ] @@ -6393,14 +6297,14 @@ dependencies = [ [[package]] name = "phonenumber" -version = "0.3.2+8.13.9" +version = "0.3.3+8.13.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34749f64ea9d76f10cdc8a859588b57775f59177c7dd91f744d620bd62982d6f" +checksum = "635f3e6288e4f01c049d89332a031bd74f25d64b6fb94703ca966e819488cd06" dependencies = [ "bincode 1.3.3", "either", "fnv", - "itertools 0.10.5", + "itertools 0.11.0", "lazy_static", "nom", "quick-xml", @@ -6408,6 +6312,7 @@ dependencies = [ "regex-cache", "serde", "serde_derive", + "strum 0.24.1", "thiserror", ] @@ -6511,13 +6416,13 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "predicates" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" +checksum = "6dfc28575c2e3f19cb3c73b93af36460ae898d426eba6fc15b9bd2a5220758a0" dependencies = [ "anstyle", "difflib", - "itertools 0.10.5", + "itertools 0.11.0", "predicates-core", ] @@ -6753,9 +6658,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -6763,14 +6668,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -7545,9 +7448,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.13" +version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" dependencies = [ "bitflags 2.4.0", "errno", @@ -7653,7 +7556,7 @@ dependencies = [ "parking_lot 0.11.2", "rustc-hash", "salsa-macros", - "smallvec 1.11.0", + "smallvec", ] [[package]] @@ -7991,11 +7894,11 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" name = "sequencer" version = "0.1.0" dependencies = [ - "blockifier 0.3.0-rc0 (git+https://github.com/starkware-libs/blockifier.git?tag=v0.3.0-rc0)", + "blockifier", "lazy_static", "rustc-hash", "starknet", - "starknet_api 0.5.0-rc1", + "starknet_api", ] [[package]] @@ -8007,17 +7910,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-hex" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca37e3e4d1b39afd7ff11ee4e947efae85adfddf4841787bfa47c470e96dc26d" -dependencies = [ - "array-init", - "serde", - "smallvec 0.6.14", -] - [[package]] name = "serde-value" version = "0.7.0" @@ -8256,18 +8148,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "0.6.14" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" -dependencies = [ - "maybe-uninit", -] - -[[package]] -name = "smallvec" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "smol_str" @@ -8592,24 +8475,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "starknet_api" -version = "0.5.0-rc1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f70f6673391b3f3624651e8692f4e76aab9194abb3d3feeb3a07a6b0546639ee" -dependencies = [ - "cairo-lang-starknet", - "derive_more", - "hex", - "indexmap 1.9.3", - "once_cell", - "primitive-types", - "serde", - "serde_json", - "starknet-crypto 0.5.1", - "thiserror", -] - [[package]] name = "static_assertions" version = "1.1.0" @@ -8640,6 +8505,9 @@ name = "strum" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros 0.24.3", +] [[package]] name = "strum" @@ -8826,9 +8694,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] @@ -9038,9 +8906,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -9215,7 +9083,7 @@ dependencies = [ "once_cell", "regex", "sharded-slab", - "smallvec 1.11.0", + "smallvec", "thread_local", "tracing", "tracing-core", @@ -9379,9 +9247,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" @@ -9640,9 +9508,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] From f0768034b2824823a48139dbfdce34e2d0a9b149 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 11:19:38 +0700 Subject: [PATCH 6/9] update from comments --- crates/sequencer/src/sequencer.rs | 3 +++ crates/sequencer/src/state.rs | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index 7e579c2f..46b7a34c 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -4,6 +4,9 @@ use blockifier::state::state_api::{State, StateReader}; /// Sequencer is the main struct of the sequencer crate. /// Using a trait bound for the state allows for better /// speed, as the type of the state is known at compile time. +/// We bound S such that a mutable reference to S (&'a mut S) +/// must implement State and StateReader. The `for` keyword +/// indicates that the bound must hold for any lifetime 'a. pub struct Sequencer where for<'a> &'a mut S: State + StateReader, diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index b5a41828..3d36acaf 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -31,7 +31,7 @@ pub struct State { /// State implementation for the sequencer. We use a mutable reference to the state /// because this is what will be available during the implementation of the execution. -impl<'a> BlockifierState for &'a mut State { +impl BlockifierState for &mut State { fn set_storage_at( &mut self, contract_address: ContractAddress, @@ -90,8 +90,8 @@ impl<'a> BlockifierState for &'a mut State { } } -impl<'a> BlockifierStateReader for &'a mut State { - /// Default: 0 for an uninitialized contract address. +impl BlockifierStateReader for &mut State { + /// Default: 0 for an uninitialized contract address or key. fn get_storage_at( &mut self, contract_address: ContractAddress, @@ -113,7 +113,7 @@ impl<'a> BlockifierStateReader for &'a mut State { .unwrap_or_default()) } - /// Default: 0 (uninitialized class hash) for an uninitialized contract address. + /// Default: 0 for an uninitialized contract address. fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { Ok(self .contracts @@ -122,7 +122,9 @@ impl<'a> BlockifierStateReader for &'a mut State { .unwrap_or_default()) } - /// Errors if the compiled class is not declared. + /// # Errors + /// + /// If the compiled class is not declared. fn get_compiled_contract_class( &mut self, class_hash: &ClassHash, @@ -133,7 +135,9 @@ impl<'a> BlockifierStateReader for &'a mut State { .ok_or_else(|| StateError::UndeclaredClassHash(class_hash.to_owned())) } - /// Errors if the compiled class hash is not declared. + /// # Errors + /// + /// If the compiled class hash is not declared. fn get_compiled_class_hash(&mut self, class_hash: ClassHash) -> StateResult { self.compiled_class_hashes .get(&class_hash) From 46104a2db8d0a05d8d3e14d9253ed55a955e5475 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 11:47:34 +0700 Subject: [PATCH 7/9] add rust doc, update should panic --- crates/sequencer/src/sequencer.rs | 1 + crates/sequencer/src/state.rs | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index 46b7a34c..1f336a15 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -7,6 +7,7 @@ use blockifier::state::state_api::{State, StateReader}; /// We bound S such that a mutable reference to S (&'a mut S) /// must implement State and StateReader. The `for` keyword /// indicates that the bound must hold for any lifetime 'a. +/// For more details, check out https://doc.rust-lang.org/nomicon/hrtb.html pub struct Sequencer where for<'a> &'a mut S: State + StateReader, diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index 3d36acaf..f49d8a91 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -219,9 +219,7 @@ mod tests { } #[test] - #[should_panic( - expected = "UndeclaredClassHash(ClassHash(StarkFelt(\"0x0000000000000000000000000000000000000000000000000000000000000001\")))" - )] + #[should_panic(expected = "UndeclaredClassHash")] fn test_uninitialized_contract_class() { // Given let mut state = &mut State::default(); @@ -247,9 +245,7 @@ mod tests { } #[test] - #[should_panic( - expected = "UndeclaredClassHash(ClassHash(StarkFelt(\"0x0000000000000000000000000000000000000000000000000000000000000001\"))" - )] + #[should_panic(expected = "UndeclaredClassHash")] fn test_uninitialized_compiled_class_hash() { // Given let mut state = &mut State::default(); From 4f3f4f59a944ad4418d6fc61ecedac65eca6a4f6 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 11:56:15 +0700 Subject: [PATCH 8/9] remove unnecessary comments --- crates/sequencer/src/state.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index f49d8a91..8c80216c 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -91,7 +91,6 @@ impl BlockifierState for &mut State { } impl BlockifierStateReader for &mut State { - /// Default: 0 for an uninitialized contract address or key. fn get_storage_at( &mut self, contract_address: ContractAddress, @@ -104,7 +103,6 @@ impl BlockifierStateReader for &mut State { .unwrap_or_default()) } - /// Default: 0 for an uninitialized contract address. fn get_nonce_at(&mut self, contract_address: ContractAddress) -> StateResult { Ok(self .nonces @@ -113,7 +111,6 @@ impl BlockifierStateReader for &mut State { .unwrap_or_default()) } - /// Default: 0 for an uninitialized contract address. fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { Ok(self .contracts From fda6a9a2733a44fb5572ef4b7eb32df136ff1ce2 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 21 Sep 2023 12:15:08 +0700 Subject: [PATCH 9/9] rename constants + TODO --- crates/sequencer/Cargo.toml | 1 + crates/sequencer/src/constants.rs | 6 +++--- crates/sequencer/src/state.rs | 23 +++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index dfe10af5..c24dd664 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -13,6 +13,7 @@ license.workspace = true [dependencies] # Starknet +# TODO: remove the blockifier patch on the workspace once we can remove Katana. blockifier = { package = "blockifier", git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" } starknet_api = { workspace = true } starknet = { workspace = true } diff --git a/crates/sequencer/src/constants.rs b/crates/sequencer/src/constants.rs index d07edee6..bc7320e1 100644 --- a/crates/sequencer/src/constants.rs +++ b/crates/sequencer/src/constants.rs @@ -20,9 +20,9 @@ pub mod test_constants { pub static ref TWO_FELT: StarkFelt = StarkFelt::from(2u8); pub static ref ONE_PATRICIA: PatriciaKey = TryInto::::try_into(*ONE_FELT).unwrap(); pub static ref TWO_PATRICIA: PatriciaKey = TryInto::::try_into(*TWO_FELT).unwrap(); - pub static ref ONE_HASH: ClassHash = ClassHash(*ONE_FELT); - pub static ref TWO_HASH: ClassHash = ClassHash(*TWO_FELT); - pub static ref ONE_COMPILED_HASH: CompiledClassHash = CompiledClassHash(*ONE_FELT); + pub static ref ONE_CLASS_HASH: ClassHash = ClassHash(*ONE_FELT); + pub static ref TWO_CLASS_HASH: ClassHash = ClassHash(*TWO_FELT); + pub static ref ONE_COMPILED_CLASS_HASH: CompiledClassHash = CompiledClassHash(*ONE_FELT); pub static ref ONE_BLOCK_NUMBER: BlockNumber = BlockNumber(1); pub static ref ONE_BLOCK_TIMESTAMP: BlockTimestamp = BlockTimestamp(1); } diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index 8c80216c..46966626 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -148,7 +148,7 @@ mod tests { use blockifier::execution::contract_class::ContractClassV0; use crate::constants::test_constants::{ - ONE_COMPILED_HASH, ONE_FELT, ONE_HASH, ONE_PATRICIA, TEST_CONTRACT_ADDRESS, + ONE_CLASS_HASH, ONE_COMPILED_CLASS_HASH, ONE_FELT, ONE_PATRICIA, TEST_CONTRACT_ADDRESS, }; use super::*; @@ -190,11 +190,11 @@ mod tests { // When state - .set_class_hash_at(*TEST_CONTRACT_ADDRESS, *ONE_HASH) + .set_class_hash_at(*TEST_CONTRACT_ADDRESS, *ONE_CLASS_HASH) .unwrap(); // Then - let expected = *ONE_HASH; + let expected = *ONE_CLASS_HASH; let actual = state.get_class_hash_at(*TEST_CONTRACT_ADDRESS).unwrap(); assert_eq!(expected, actual); } @@ -206,12 +206,15 @@ mod tests { // When state - .set_contract_class(&ONE_HASH, ContractClass::V0(ContractClassV0::default())) + .set_contract_class( + &ONE_CLASS_HASH, + ContractClass::V0(ContractClassV0::default()), + ) .unwrap(); // Then let expected = ContractClass::V0(ContractClassV0::default()); - let actual = state.get_compiled_contract_class(&ONE_HASH).unwrap(); + let actual = state.get_compiled_contract_class(&ONE_CLASS_HASH).unwrap(); assert_eq!(expected, actual); } @@ -222,7 +225,7 @@ mod tests { let mut state = &mut State::default(); // When - state.get_compiled_contract_class(&ONE_HASH).unwrap(); + state.get_compiled_contract_class(&ONE_CLASS_HASH).unwrap(); } #[test] @@ -232,12 +235,12 @@ mod tests { // When state - .set_compiled_class_hash(*ONE_HASH, *ONE_COMPILED_HASH) + .set_compiled_class_hash(*ONE_CLASS_HASH, *ONE_COMPILED_CLASS_HASH) .unwrap(); // Then - let expected = *ONE_COMPILED_HASH; - let actual = state.get_compiled_class_hash(*ONE_HASH).unwrap(); + let expected = *ONE_COMPILED_CLASS_HASH; + let actual = state.get_compiled_class_hash(*ONE_CLASS_HASH).unwrap(); assert_eq!(expected, actual); } @@ -248,6 +251,6 @@ mod tests { let mut state = &mut State::default(); // When - state.get_compiled_class_hash(*ONE_HASH).unwrap(); + state.get_compiled_class_hash(*ONE_CLASS_HASH).unwrap(); } }