From 091ca078117ea92601bbcc411174d8181f0967b3 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 3 Dec 2024 17:36:23 +0800 Subject: [PATCH] update to latest sequencer --- Cargo.lock | 116 ++++++++++-- Cargo.toml | 8 +- blockchain-tests-skip.yml | 166 +++++++++++++++++- .../src/evm_sequencer/account/mod.rs | 2 +- .../src/evm_sequencer/sequencer/mod.rs | 25 +-- crates/sequencer/src/commit.rs | 8 +- crates/sequencer/src/native.rs | 36 ++-- crates/sequencer/src/sequencer.rs | 110 ++++++------ crates/sequencer/src/serde.rs | 10 +- crates/sequencer/src/state.rs | 30 ++-- crates/sequencer/src/transaction.rs | 55 +++--- rust-toolchain | 2 +- 12 files changed, 408 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea1208e7..c8dc76f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -1118,7 +1118,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.0.0" -source = "git+https://github.com/kkrt-labs/sequencer.git?rev=41fa336f05eaec38bfa53e0e43d19a608c0fef37#41fa336f05eaec38bfa53e0e43d19a608c0fef37" +source = "git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" dependencies = [ "anyhow", "ark-ec", @@ -1128,17 +1128,14 @@ dependencies = [ "cached 0.44.0", "cairo-lang-casm", "cairo-lang-runner", - "cairo-lang-sierra", "cairo-lang-starknet-classes", "cairo-lang-utils", "cairo-native", "cairo-vm", "derive_more 0.99.18", - "educe", "indexmap 2.5.0", - "itertools 0.10.5", + "itertools 0.12.1", "keccak", - "lazy_static", "log", "num-bigint", "num-integer", @@ -1149,12 +1146,13 @@ dependencies = [ "phf", "rand", "rstest", + "semver 1.0.23", "serde", "serde_json", "sha2 0.10.8", - "sha3", "starknet-types-core", - "starknet_api", + "starknet_api 0.0.0 (git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022)", + "starknet_sierra_compile", "strum 0.25.0", "strum_macros 0.25.3", "tempfile", @@ -1862,8 +1860,9 @@ dependencies = [ [[package]] name = "cairo-native" -version = "0.2.3" -source = "git+https://github.com/lambdaclass/cairo_native?rev=5e60089288c461eca98bf3dbe03cc882778ff677#5e60089288c461eca98bf3dbe03cc882778ff677" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bdebc70c3d563bc30078985ae3e975aa7dc4fa233631b5e0462a924c26c0dd9" dependencies = [ "anyhow", "aquamarine", @@ -1915,8 +1914,9 @@ dependencies = [ [[package]] name = "cairo-native-runtime" -version = "0.2.3" -source = "git+https://github.com/lambdaclass/cairo_native?rev=5e60089288c461eca98bf3dbe03cc882778ff677#5e60089288c461eca98bf3dbe03cc882778ff677" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf997252c402d6844f41357660cde3c11825ac5b3feafd0fb99b9dcdfb58aa3" dependencies = [ "cairo-lang-sierra-gas", "itertools 0.13.0", @@ -1934,6 +1934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58363ad8065ed891e3b14a8191b707677c7c7cb5b9d10030822506786d8d8108" dependencies = [ "anyhow", + "arbitrary", "bincode 2.0.0-rc.3", "bitvec", "generic-array", @@ -2885,7 +2886,7 @@ dependencies = [ "serde_yaml", "starknet", "starknet-crypto 0.7.2", - "starknet_api", + "starknet_api 0.0.0 (git+https://github.com/starkware-libs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022)", "thiserror", "tokio", "tracing", @@ -4036,6 +4037,14 @@ version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" +[[package]] +name = "infra_utils" +version = "0.0.0" +source = "git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" +dependencies = [ + "tokio", +] + [[package]] name = "inotify" version = "0.9.6" @@ -5350,10 +5359,11 @@ dependencies = [ [[package]] name = "papyrus_config" version = "0.0.0" -source = "git+https://github.com/kkrt-labs/sequencer.git?rev=41fa336f05eaec38bfa53e0e43d19a608c0fef37#41fa336f05eaec38bfa53e0e43d19a608c0fef37" +source = "git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" dependencies = [ "clap", - "itertools 0.10.5", + "infra_utils", + "itertools 0.12.1", "serde", "serde_json", "strum_macros 0.25.3", @@ -5361,6 +5371,26 @@ dependencies = [ "validator", ] +[[package]] +name = "papyrus_proc_macros" +version = "0.0.0" +source = "git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" +dependencies = [ + "quote", + "syn 2.0.77", + "tracing", +] + +[[package]] +name = "papyrus_proc_macros" +version = "0.0.0" +source = "git+https://github.com/starkware-libs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" +dependencies = [ + "quote", + "syn 2.0.77", + "tracing", +] + [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -8210,7 +8240,7 @@ dependencies = [ "serde", "serde_json", "starknet", - "starknet_api", + "starknet_api 0.0.0 (git+https://github.com/starkware-libs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022)", "tempfile", "thiserror", "tracing", @@ -8782,6 +8812,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa1b9e01ccb217ab6d475c5cda05dbb22c30029f7bb52b192a010a00d77a3d74" dependencies = [ + "arbitrary", "lambdaworks-crypto", "lambdaworks-math", "lazy_static", @@ -8794,14 +8825,44 @@ dependencies = [ [[package]] name = "starknet_api" version = "0.0.0" -source = "git+https://github.com/kkrt-labs/sequencer.git?rev=41fa336f05eaec38bfa53e0e43d19a608c0fef37#41fa336f05eaec38bfa53e0e43d19a608c0fef37" +source = "git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" dependencies = [ "bitvec", + "cairo-lang-runner", "cairo-lang-starknet-classes", "derive_more 0.99.18", "hex", "indexmap 2.5.0", - "itertools 0.10.5", + "itertools 0.12.1", + "num-bigint", + "papyrus_proc_macros 0.0.0 (git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022)", + "pretty_assertions", + "primitive-types", + "serde", + "serde_json", + "sha3", + "starknet-crypto 0.7.2", + "starknet-types-core", + "strum 0.25.0", + "strum_macros 0.25.3", + "thiserror", +] + +[[package]] +name = "starknet_api" +version = "0.0.0" +source = "git+https://github.com/starkware-libs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" +dependencies = [ + "bitvec", + "cairo-lang-runner", + "cairo-lang-starknet-classes", + "derive_more 0.99.18", + "hex", + "indexmap 2.5.0", + "itertools 0.12.1", + "num-bigint", + "papyrus_proc_macros 0.0.0 (git+https://github.com/starkware-libs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022)", + "pretty_assertions", "primitive-types", "serde", "serde_json", @@ -8813,6 +8874,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "starknet_sierra_compile" +version = "0.0.0" +source = "git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022#e5ed51d697f678ddf27f3b0a5752065a71474022" +dependencies = [ + "cairo-lang-sierra", + "cairo-lang-starknet-classes", + "cairo-lang-utils", + "cairo-native", + "papyrus_config", + "serde", + "serde_json", + "starknet-types-core", + "starknet_api 0.0.0 (git+https://github.com/kkrt-labs/sequencer.git?rev=e5ed51d697f678ddf27f3b0a5752065a71474022)", + "tempfile", + "thiserror", + "validator", +] + [[package]] name = "static_assertions" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 7b73d790..97e5e953 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,14 +42,14 @@ cairo-lang-starknet = "2.9.0-dev.0" cairo-lang-utils = "2.9.0-dev.0" cairo-lang-starknet-classes = "2.9.0-dev.0" cairo-lang-sierra = "2.9.0-dev.0" -cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev="5e60089288c461eca98bf3dbe03cc882778ff677"} +cairo-native = "0.2.4" cairo-vm = "1.0.1" -blockifier = { package = "blockifier", git = "https://github.com/kkrt-labs/sequencer.git", rev="41fa336f05eaec38bfa53e0e43d19a608c0fef37", default-features = false, features = [ - "testing", +blockifier = { package = "blockifier", git = "https://github.com/kkrt-labs/sequencer.git", rev="e5ed51d697f678ddf27f3b0a5752065a71474022", default-features = false, features = [ + "testing", "cairo_native", ] } starknet = "0.12" starknet-crypto = "0.7" -starknet_api = { package = "starknet_api", git = "https://github.com/kkrt-labs/sequencer.git", rev="41fa336f05eaec38bfa53e0e43d19a608c0fef37" } +starknet_api = { package = "starknet_api", git = "https://github.com/starkware-libs/sequencer.git", rev="e5ed51d697f678ddf27f3b0a5752065a71474022" } # Other async-trait = "0.1" diff --git a/blockchain-tests-skip.yml b/blockchain-tests-skip.yml index 1c3e4268..c95e7a1f 100644 --- a/blockchain-tests-skip.yml +++ b/blockchain-tests-skip.yml @@ -11,5 +11,169 @@ filename: - None testname: + vmArithmeticTest: + - addmod_d10g0v0_Cancun + - addmod_d11g0v0_Cancun + - addmod_d8g0v0_Cancun + - addmod_d9g0v0_Cancun + - divByZero_d63g0v0_Cancun + - divByZero_d64g0v0_Cancun + - divByZero_d65g0v0_Cancun + - divByZero_d66g0v0_Cancun + - divByZero_d67g0v0_Cancun + - divByZero_d68g0v0_Cancun + - divByZero_d69g0v0_Cancun + - divByZero_d70g0v0_Cancun + - divByZero_d71g0v0_Cancun + - divByZero_d72g0v0_Cancun + - divByZero_d73g0v0_Cancun + - divByZero_d74g0v0_Cancun + - divByZero_d75g0v0_Cancun + - divByZero_d76g0v0_Cancun + - divByZero_d77g0v0_Cancun + - divByZero_d78g0v0_Cancun + - divByZero_d79g0v0_Cancun + - divByZero_d80g0v0_Cancun + - divByZero_d81g0v0_Cancun + - divByZero_d82g0v0_Cancun + - divByZero_d83g0v0_Cancun + - divByZero_d84g0v0_Cancun + - divByZero_d85g0v0_Cancun + - divByZero_d86g0v0_Cancun + - divByZero_d87g0v0_Cancun + - divByZero_d88g0v0_Cancun + - divByZero_d89g0v0_Cancun + - divByZero_d90g0v0_Cancun + - divByZero_d91g0v0_Cancun + - divByZero_d92g0v0_Cancun + - divByZero_d93g0v0_Cancun + - divByZero_d94g0v0_Cancun + - divByZero_d95g0v0_Cancun + - divByZero_d96g0v0_Cancun + - divByZero_d97g0v0_Cancun + - expPower256Of256_d0g0v0_Cancun + - exp_d1g0v0_Cancun + - exp_d3g0v0_Cancun + - exp_d8g0v0_Cancun + - exp_d9g0v0_Cancun + - expPower256_d0g0v0_Cancun + - mulmod_d12g0v0_Cancun + - mulmod_d13g0v0_Cancun + - mulmod_d14g0v0_Cancun + - mulmod_d15g0v0_Cancun + - twoOps_d0g0v0_Cancun -regex: + +regex: regex: + stArgsZeroOneBalance: + - .* + stAttackTest: + - .* + stBadOpcode: + - .* + stBugs: + - .* + stCallCodes: + - .* + stCallCreateCallCodeTest: + - .* + stCallDelegateCodesCallCodeHomestead: + - .* + stCallDelegateCodesHomestead: + - .* + stChainId: + - .* + stCodeSizeLimit: + - .* + stCreateTest: + - .* + stCreate2: + - .* + stDelegatecallTestHomestead: + - .* + stEIP150Specific: + - .* + stEIP150singleCodeGasPrices: + - .* + stEIP1559: + - .* + stEIP158Specific: + - .* + stEIP2930: + - .* + stExample: + - .* + stExtCodeHash: + - .* + stInitCodeTest: + - .* + stLogTests: + - .* + stMemExpandingEIP150Calls: + - .* + stMemoryStressTest: + - .* + stMemoryTest: + - .* + stNonZeroCallsTest: + - .* + stPreCompiledContracts: + - .* + stPreCompiledContracts2: + - .* + stQuadraticComplexityTest: + - .* + stRandom: + - .* + stRandom2: + - .* + stRecursiveCreate: + - .* + stRefundTest: + - .* + stReturnDataTest: + - .* + stRevertTest: + - .* + stSLoadTest: + - .* + stSStoreTest: + - .* + stSelfBalance: + - .* + stShift: + - .* + stSolidityTest: + - .* + stSpecialTest: + - .* + stStackTests: + - .* + stStaticCall: + - .* + stStaticFlagEnabled: + - .* + stSystemOperationsTest: + - .* + stTimeConsuming: + - .* + stTransactionTest: + - .* + stTransitionTest: + - .* + stWalletTest: + - .* + stZeroCallsRevert: + - .* + stZeroKnowledge: + - .* + stZeroKnowledge2: + - .* + vmIOandFlowOperations: + - .* + vmLogTest: + - .* + vmPerformance: + - .* + vmTests: + - .* diff --git a/crates/ef-testing/src/evm_sequencer/account/mod.rs b/crates/ef-testing/src/evm_sequencer/account/mod.rs index 0c0ad7ea..b63ae3eb 100644 --- a/crates/ef-testing/src/evm_sequencer/account/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/account/mod.rs @@ -187,7 +187,7 @@ mod tests { use crate::evm_sequencer::constants::storage_variables::ACCOUNT_BYTECODE; use super::*; - use blockifier::abi::abi_utils::get_storage_var_address; + use starknet_api::abi::abi_utils::get_storage_var_address; use reth_primitives::Bytes; #[test] diff --git a/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs b/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs index 103a3e2f..22b26335 100644 --- a/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs @@ -18,7 +18,8 @@ use crate::evm_sequencer::{ types::contract_class::CasmContractClassWrapper, utils::compute_starknet_address, }; -use blockifier::blockifier::block::{BlockInfo, GasPrices}; +use blockifier::blockifier::block::BlockInfo; +use starknet_api::block::{GasPrices, GasPriceVector, NonzeroGasPrice}; use blockifier::context::ChainInfo; use blockifier::context::{BlockContext, FeeTokenAddresses}; use blockifier::versioned_constants::VersionedConstants; @@ -42,7 +43,7 @@ use crate::evm_sequencer::constants::{ storage_variables::KAKAROT_CAIRO1_HELPERS_CLASS_HASH, CAIRO1_HELPERS_CLASS, CAIRO1_HELPERS_CLASS_HASH, }; -use blockifier::abi::abi_utils::get_storage_var_address; +use starknet_api::abi::abi_utils::get_storage_var_address; #[allow(unused_imports)] use blockifier::state::state_api::{ State as BlockifierState, StateReader as BlockifierStateReader, @@ -110,14 +111,18 @@ impl KakarotSequencer { ) .try_into() .expect("Failed to convert to ContractAddress"), - gas_prices: GasPrices::new( - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - ), + gas_prices: GasPrices { + eth_gas_prices: GasPriceVector{ + l1_gas_price: Default::default(), + l1_data_gas_price: Default::default(), + l2_gas_price: Default::default() + }, + strk_gas_prices: GasPriceVector{ + l1_gas_price: Default::default(), + l1_data_gas_price: Default::default(), + l2_gas_price: Default::default() + }, + }, use_kzg_da: false, }; diff --git a/crates/sequencer/src/commit.rs b/crates/sequencer/src/commit.rs index 21f4124b..cee8d451 100644 --- a/crates/sequencer/src/commit.rs +++ b/crates/sequencer/src/commit.rs @@ -12,18 +12,18 @@ where { fn commit(cached_state: &mut CachedState<&mut S>) -> StateResult<()> { let diff = cached_state.to_state_diff()?; - for (address, class_hash) in diff.class_hashes { + for (address, class_hash) in diff.state_maps.class_hashes { cached_state.state.set_class_hash_at(address, class_hash)?; } - for (address, _) in diff.nonces { + for (address, _) in diff.state_maps.nonces { cached_state.state.increment_nonce(address)?; } - for ((address, storage_key), value) in &diff.storage { + for ((address, storage_key), value) in &diff.state_maps.storage { cached_state .state .set_storage_at(*address, *storage_key, *value)?; } - for (class_hash, compiled_class_hash) in diff.compiled_class_hashes { + for (class_hash, compiled_class_hash) in diff.state_maps.compiled_class_hashes { cached_state .state .set_compiled_class_hash(class_hash, compiled_class_hash)?; diff --git a/crates/sequencer/src/native.rs b/crates/sequencer/src/native.rs index a25ff0db..c4e42528 100644 --- a/crates/sequencer/src/native.rs +++ b/crates/sequencer/src/native.rs @@ -1,11 +1,13 @@ -use blockifier::execution::contract_class::NativeContractClassV1; -use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; +use blockifier::execution::contract_class::{ + CompiledClassV0, CompiledClassV1, RunnableCompiledClass, +}; +use blockifier::execution::native::contract_class::NativeCompiledClassV1; +use cairo_lang_starknet_classes::contract_class::ContractClass; use cairo_native::executor::AotContractExecutor; use cairo_native::OptLevel; use starknet_api::core::ClassHash; use lazy_static::lazy_static; -use std::sync::Arc; use std::{fs, path::PathBuf}; lazy_static! { @@ -39,36 +41,44 @@ fn setup_native_cache_dir() -> PathBuf { fn native_try_from_json_string( raw_contract_class: &str, library_output_path: &PathBuf, -) -> Result> { - let sierra_contract_class: cairo_lang_starknet_classes::contract_class::ContractClass = - serde_json::from_str(raw_contract_class)?; +) -> Result> { + let sierra_contract_class: ContractClass = serde_json::from_str(raw_contract_class)?; + + let compiled_class = serde_json::from_str(raw_contract_class)?; let sierra_program = sierra_contract_class.extract_sierra_program()?; let maybe_cached_executor = AotContractExecutor::load(library_output_path); if let Ok(executor) = maybe_cached_executor { println!("Loaded cached executor"); - let native_class = NativeContractClassV1::new(Arc::new(executor), sierra_contract_class)?; + let native_class = NativeCompiledClassV1::new(executor, compiled_class); return Ok(native_class); } println!("Creating new executor"); - let mut executor = AotContractExecutor::new(&sierra_program, &sierra_contract_class.entry_points_by_type, OptLevel::Default)?; + let mut executor = AotContractExecutor::new( + &sierra_program, + &sierra_contract_class.entry_points_by_type, + OptLevel::Default, + )?; executor.save(library_output_path)?; println!("Saved executor to {:?}", library_output_path); - let native_class = NativeContractClassV1::new(Arc::new(executor), sierra_contract_class)?; + let native_class = NativeCompiledClassV1::new(executor, compiled_class); Ok(native_class) } -pub fn class_from_json_str(raw_json: &str, class_hash: ClassHash) -> Result { +pub fn class_from_json_str( + raw_json: &str, + class_hash: ClassHash, +) -> Result { println!("raw json length {}", raw_json.len()); let class_def = raw_json.to_string(); println!("class def parsed"); - let class: ContractClass = - if let Ok(class) = ContractClassV0::try_from_json_string(class_def.as_str()) { + let class: RunnableCompiledClass = + if let Ok(class) = CompiledClassV0::try_from_json_string(class_def.as_str()) { class.into() - } else if let Ok(class) = ContractClassV1::try_from_json_string(class_def.as_str()) { + } else if let Ok(class) = CompiledClassV1::try_from_json_string(class_def.as_str()) { println!("v1 contract"); class.into() } else if let Ok(class) = { diff --git a/crates/sequencer/src/sequencer.rs b/crates/sequencer/src/sequencer.rs index b56131fb..9dd581f6 100644 --- a/crates/sequencer/src/sequencer.rs +++ b/crates/sequencer/src/sequencer.rs @@ -72,18 +72,21 @@ where transaction: Transaction, ) -> TransactionExecutionResult { let sender_address = match &transaction { - Transaction::AccountTransaction(tx) => match tx { - blockifier::transaction::account_transaction::AccountTransaction::Invoke(tx) => { - tx.tx.sender_address() + Transaction::Account(account_tx) => { + let tx = &account_tx.tx; + match tx { + starknet_api::executable_transaction::AccountTransaction::Invoke(tx) => { + tx.sender_address() + } + starknet_api::executable_transaction::AccountTransaction::Declare(tx) => { + tx.sender_address() + } + starknet_api::executable_transaction::AccountTransaction::DeployAccount(tx) => { + tx.contract_address() + } } - blockifier::transaction::account_transaction::AccountTransaction::Declare(tx) => { - tx.tx().sender_address() - } - blockifier::transaction::account_transaction::AccountTransaction::DeployAccount( - tx, - ) => tx.contract_address(), - }, - Transaction::L1HandlerTransaction(_) => ContractAddress::from(0u8), + } + Transaction::L1Handler(_) => ContractAddress::from(0u8), }; let mut cached_state = CachedState::new(&mut self.state); @@ -115,25 +118,23 @@ where mod tests { use std::fmt::Display; use std::fs::File; - use std::num::NonZeroU128; - use blockifier::abi::abi_utils::get_storage_var_address; - use blockifier::blockifier::block::{BlockInfo, GasPrices}; + use starknet_api::abi::abi_utils::get_storage_var_address; use blockifier::bouncer::BouncerConfig; use blockifier::context::ChainInfo; use blockifier::context::{BlockContext, FeeTokenAddresses}; - use blockifier::execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}; + use blockifier::execution::contract_class::{RunnableCompiledClass, CompiledClassV0, CompiledClassV1}; use blockifier::state::state_api::State as BlockifierState; - use blockifier::transaction::account_transaction::AccountTransaction; - use blockifier::transaction::transactions::InvokeTransaction as BlockifierInvokeTransaction; use blockifier::versioned_constants::VersionedConstants; use starknet::core::types::Felt; use starknet::macros::selector; use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce}; use starknet_api::executable_transaction::InvokeTransaction; - use starknet_api::transaction::{ - Calldata, Fee, InvokeTransactionV1, TransactionHash, TransactionSignature, + use starknet_api::transaction::{InvokeTransaction as InvokeTransactionTypes, InvokeTransactionV1}; + use starknet_api::transaction::fields::{ + Calldata, Fee, TransactionSignature, }; + use starknet_api::block::{BlockInfo, GasPrices, GasPriceVector}; use crate::constants::test_constants::{ ETH_FEE_TOKEN_ADDRESS, SEQUENCER_ADDRESS, STRK_FEE_TOKEN_ADDRESS, @@ -160,19 +161,19 @@ mod tests { } } - fn read_contract_class_v0(path: &str) -> ContractClass { + fn read_contract_class_v0(path: &str) -> RunnableCompiledClass { let reader = File::open(path).unwrap(); - let contract_class: ContractClassV0 = serde_json::from_reader(reader).unwrap(); + let contract_class: CompiledClassV0 = serde_json::from_reader(reader).unwrap(); - ContractClass::V0(contract_class) + RunnableCompiledClass::V0(contract_class) } - fn read_contract_class_v1(path: &str) -> ContractClass { + fn read_contract_class_v1(path: &str) -> RunnableCompiledClass { let raw_contract_class = std::fs::read_to_string(path).unwrap(); - let contract_class: ContractClassV1 = - ContractClassV1::try_from_json_string(&raw_contract_class).unwrap(); + let contract_class: CompiledClassV1 = + CompiledClassV1::try_from_json_string(&raw_contract_class).unwrap(); - ContractClass::V1(contract_class) + RunnableCompiledClass::V1(contract_class) } fn declare_and_deploy_contract( @@ -255,14 +256,18 @@ mod tests { block_number: *ONE_BLOCK_NUMBER, block_timestamp: *ONE_BLOCK_TIMESTAMP, sequencer_address: *SEQUENCER_ADDRESS, - gas_prices: GasPrices::new( - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - NonZeroU128::new(1).unwrap(), - ), + gas_prices: GasPrices { + eth_gas_prices: GasPriceVector{ + l1_gas_price: Default::default(), + l1_data_gas_price: Default::default(), + l2_gas_price: Default::default() + }, + strk_gas_prices: GasPriceVector{ + l1_gas_price: Default::default(), + l1_data_gas_price: Default::default(), + l2_gas_price: Default::default() + }, + }, use_kzg_da: false, }; @@ -284,26 +289,23 @@ mod tests { } fn test_transaction() -> Transaction { - Transaction::AccountTransaction(AccountTransaction::Invoke(BlockifierInvokeTransaction { - tx: InvokeTransaction { - tx: starknet_api::transaction::InvokeTransaction::V1(InvokeTransactionV1 { - sender_address: *TEST_ACCOUNT, - calldata: Calldata( - vec![ - *TEST_CONTRACT.0.key(), // destination - selector!("inc"), - *ZERO_FELT, // no data - ] - .into(), - ), - max_fee: Fee(1_000_000), - signature: TransactionSignature(vec![]), - nonce: Nonce(*ZERO_FELT), - }), - tx_hash: TransactionHash(*ZERO_FELT), - }, - only_query: false, - })) + let invoke_tx = InvokeTransactionTypes::V1(InvokeTransactionV1 { + sender_address: *TEST_ACCOUNT, + calldata: Calldata( + vec![ + *TEST_CONTRACT.0.key(), // destination + selector!("inc"), + *ZERO_FELT, // no data + ] + .into(), + ), + max_fee: Fee(1_000_000), + signature: TransactionSignature(vec![]), + nonce: Nonce(*ZERO_FELT), + }); + let transaction = + InvokeTransaction::create(invoke_tx, &ChainId::Other("KKRT".into())).unwrap(); + Transaction::Account(transaction.into()) } sequencer_test!(CairoVersion::V0, test_sequencer_cairo_0); diff --git a/crates/sequencer/src/serde.rs b/crates/sequencer/src/serde.rs index 68687714..6d05b06c 100644 --- a/crates/sequencer/src/serde.rs +++ b/crates/sequencer/src/serde.rs @@ -1,6 +1,6 @@ use std::{fs, io, path::Path}; -use blockifier::execution::contract_class::ContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; use starknet::core::types::Felt; @@ -48,7 +48,7 @@ pub enum SerializationError { #[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct SerializableState { - pub classes: HashMap, + pub classes: HashMap, pub compiled_classes_hash: HashMap, pub contracts: HashMap, #[serde(with = "serialize_contract_storage")] @@ -135,7 +135,7 @@ mod serialize_contract_storage { mod tests { use super::*; use blockifier::{ - execution::contract_class::{ContractClass, ContractClassV0}, + execution::contract_class::{CompiledClassV0, RunnableCompiledClass}, state::state_api::State as _, }; @@ -154,8 +154,8 @@ mod tests { // setting up entry for state.classes let class_hash = *ONE_CLASS_HASH; let contract_class = include_str!("./test_data/cairo_0/compiled_classes/counter.json"); - let contract_class: ContractClassV0 = serde_json::from_str(contract_class).expect("failed to deserialize ContractClass from ./crates/sequencer/test_data/cairo_1/compiled_classes/account.json"); - let contract_class = ContractClass::V0(contract_class); + let contract_class: CompiledClassV0 = serde_json::from_str(contract_class).expect("failed to deserialize RunnableCompiledClass from ./crates/sequencer/test_data/cairo_1/compiled_classes/account.json"); + let contract_class = RunnableCompiledClass::V0(contract_class); let compiled_class_hash = *ONE_COMPILED_CLASS_HASH; let contract_address = *TEST_CONTRACT; diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index 91d01e83..cc8a74c4 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -1,6 +1,6 @@ use crate::commit::Committer; use crate::serde::SerializableState; -use blockifier::execution::contract_class::ContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{ State as BlockifierState, StateReader as BlockifierStateReader, StateResult, @@ -19,7 +19,7 @@ pub type ContractStorageKey = (ContractAddress, StorageKey); /// See [Performance](https://github.com/rust-lang/hashbrown?tab=readme-ov-file#performance) #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct State { - classes: HashMap, + classes: HashMap, compiled_class_hashes: HashMap, contracts: HashMap, storage: HashMap, @@ -111,12 +111,12 @@ impl BlockifierState for &mut State { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: ContractClass, + contract_class: RunnableCompiledClass, ) -> StateResult<()> { - match &contract_class { - &ContractClass::V0(_) => println!("Setting V0 contract class"), - &ContractClass::V1(_) => println!("Setting V1 contract class"), - &ContractClass::V1Native(_) => println!("Setting V1Native contract class"), + match contract_class { + RunnableCompiledClass::V0(_) => println!("Setting V0 contract class"), + RunnableCompiledClass::V1(_) => println!("Setting V1 contract class"), + RunnableCompiledClass::V1Native(_) => println!("Setting V1Native contract class"), }; self.classes.insert(class_hash, contract_class); Ok(()) @@ -169,12 +169,12 @@ impl BlockifierStateReader for &mut State { /// # Errors /// /// If the compiled class is not declared. - fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { + fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult { let res = self .classes .get(&class_hash) .cloned() - .ok_or_else(|| StateError::UndeclaredClassHash(class_hash))?; + .ok_or(StateError::UndeclaredClassHash(class_hash))?; Ok(res) } @@ -185,13 +185,13 @@ impl BlockifierStateReader for &mut State { self.compiled_class_hashes .get(&class_hash) .copied() - .ok_or_else(|| StateError::UndeclaredClassHash(class_hash)) + .ok_or(StateError::UndeclaredClassHash(class_hash)) } } #[cfg(test)] mod tests { - use blockifier::execution::contract_class::ContractClassV0; + use blockifier::execution::contract_class::CompiledClassV0; use crate::constants::test_constants::{ ONE_CLASS_HASH, ONE_COMPILED_CLASS_HASH, ONE_FELT, ONE_PATRICIA, TEST_CONTRACT, @@ -256,13 +256,13 @@ mod tests { state .set_contract_class( *ONE_CLASS_HASH, - ContractClass::V0(ContractClassV0::default()), + RunnableCompiledClass::V0(CompiledClassV0::default()), ) .unwrap(); // Then - let expected = ContractClass::V0(ContractClassV0::default()); - let actual = state.get_compiled_contract_class(*ONE_CLASS_HASH).unwrap(); + let expected = RunnableCompiledClass::V0(CompiledClassV0::default()); + let actual = state.get_compiled_class(*ONE_CLASS_HASH).unwrap(); assert_eq!(expected, actual); } @@ -273,7 +273,7 @@ mod tests { let state = &mut State::default(); // When - state.get_compiled_contract_class(*ONE_CLASS_HASH).unwrap(); + state.get_compiled_class(*ONE_CLASS_HASH).unwrap(); } #[test] diff --git a/crates/sequencer/src/transaction.rs b/crates/sequencer/src/transaction.rs index 907802b3..58b37556 100644 --- a/crates/sequencer/src/transaction.rs +++ b/crates/sequencer/src/transaction.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use blockifier::transaction::transactions::InvokeTransaction as BlockifierInvokeTransaction; use blockifier::transaction::{ account_transaction::AccountTransaction, transaction_execution::Transaction as ExecutionTransaction, @@ -9,9 +8,8 @@ use starknet::core::crypto::compute_hash_on_elements; use starknet::core::types::{BroadcastedInvokeTransaction, BroadcastedTransaction, Felt}; use starknet_api::core::Nonce; use starknet_api::executable_transaction::InvokeTransaction; -use starknet_api::transaction::{ - Calldata, Fee, InvokeTransactionV1, TransactionHash, TransactionSignature, -}; +use starknet_api::transaction::fields::{Calldata, Fee, TransactionSignature}; +use starknet_api::transaction::{InvokeTransactionV1, TransactionHash}; /// Wrapper around a Starknet-rs transaction. /// Allows for conversion from a Starknet-rs @@ -33,37 +31,26 @@ impl BroadcastedTransactionWrapper { ) -> Result { match self.0 { BroadcastedTransaction::Invoke(invoke) => match invoke { - BroadcastedInvokeTransaction::V1(invoke_v1) => { - Ok(ExecutionTransaction::AccountTransaction( - AccountTransaction::Invoke(BlockifierInvokeTransaction { - tx: InvokeTransaction { - tx: starknet_api::transaction::InvokeTransaction::V1( - InvokeTransactionV1 { - max_fee: Fee(invoke_v1.max_fee.to_biguint().try_into()?), - signature: TransactionSignature( - invoke_v1 - .signature - .into_iter() - .map(Into::into) - .collect(), - ), - nonce: Nonce(invoke_v1.nonce), - sender_address: invoke_v1.sender_address.try_into()?, - calldata: Calldata(Arc::new(invoke_v1.calldata.to_vec())), - }, - ), - tx_hash: TransactionHash(compute_transaction_hash( - invoke_v1.sender_address, - &invoke_v1.calldata, - invoke_v1.max_fee, - chain_id, - invoke_v1.nonce, - )), - }, - only_query: false, + BroadcastedInvokeTransaction::V1(invoke_v1) => Ok(ExecutionTransaction::Account( + AccountTransaction::from(InvokeTransaction { + tx: starknet_api::transaction::InvokeTransaction::V1(InvokeTransactionV1 { + max_fee: Fee(invoke_v1.max_fee.to_biguint().try_into()?), + signature: TransactionSignature( + invoke_v1.signature.into_iter().map(Into::into).collect(), + ), + nonce: Nonce(invoke_v1.nonce), + sender_address: invoke_v1.sender_address.try_into()?, + calldata: Calldata(Arc::new(invoke_v1.calldata.to_vec())), }), - )) - } + tx_hash: TransactionHash(compute_transaction_hash( + invoke_v1.sender_address, + &invoke_v1.calldata, + invoke_v1.max_fee, + chain_id, + invoke_v1.nonce, + )), + }), + )), BroadcastedInvokeTransaction::V3(_) => { Err(eyre::eyre!("Unsupported InvokeTransaction version V3")) } diff --git a/rust-toolchain b/rust-toolchain index 1de01fa4..5d56faf9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,2 +1,2 @@ [toolchain] -channel = "1.81.0" +channel = "nightly"