diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a478ff674..ebb7cd0913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ - chore(db): changed the way hashes are encoded - refacto: reusable Eth client config for settlement/DA/other tasks - ci: add gomu gomu no gatling perfomrance test +- feat(runtime): moved StarkEvents from Substrate events to runtime storage +- feat(node): validate declare txs against local Sierra class in block import + queue - feat(runtime): moved StarkEvents from Substrate - feat(rpc/trace_api): add `trace_transaction` - fix(docker): fix dockerfile for `madara-node` diff --git a/Cargo.lock b/Cargo.lock index 291ab12ab2..2e5bac5bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6045,11 +6045,13 @@ dependencies = [ "mc-mapping-sync", "mc-rpc", "mc-settlement", + "mc-starknet-block-import", "mc-storage", "mp-block", "mp-digest-log", "mp-felt", "mp-sequencer-address", + "num-bigint", "pallet-starknet", "pallet-starknet-runtime-api", "reqwest", @@ -6075,6 +6077,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-blockchain", + "sp-consensus", "sp-consensus-aura", "sp-consensus-grandpa", "sp-core 21.0.0 (git+https://github.com/massalabs/polkadot-sdk?branch=release-polkadot-v1.3.0-std)", @@ -6088,6 +6091,7 @@ dependencies = [ "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", + "thiserror", "try-runtime-cli", "url", ] @@ -6431,6 +6435,37 @@ dependencies = [ "utils", ] +[[package]] +name = "mc-starknet-block-import" +version = "0.7.0" +dependencies = [ + "async-trait", + "blockifier", + "cairo-lang-starknet", + "cairo-lang-starknet-classes", + "cairo-lang-utils", + "cairo-vm", + "hex", + "log", + "madara-runtime", + "mc-db", + "mc-rpc", + "mp-felt", + "mp-transactions", + "num-bigint", + "pallet-starknet", + "pallet-starknet-runtime-api", + "sc-consensus", + "sc-rpc-api", + "serde_json", + "sp-api", + "sp-consensus", + "sp-runtime 24.0.0 (git+https://github.com/massalabs/polkadot-sdk?branch=release-polkadot-v1.3.0-std)", + "starknet-core", + "starknet_api", + "thiserror", +] + [[package]] name = "mc-storage" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index a0b0f1bf8c..ea3ff13cf8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ members = [ "crates/client/commitment-state-diff", "crates/client/settlement", "crates/client/eth-client", + "crates/client/starknet-block-import", "starknet-rpc-test", "da-test", "starknet-e2e-test", @@ -59,6 +60,7 @@ default-members = [ "crates/client/commitment-state-diff", "crates/client/settlement", "crates/client/eth-client", + "crates/client/starknet-block-import", "starknet-test-utils", ] @@ -190,6 +192,7 @@ mc-commitment-state-diff = { path = "crates/client/commitment-state-diff" } mc-l1-messages = { path = "crates/client/l1-messages" } mc-settlement = { path = "crates/client/settlement" } mc-eth-client = { path = "crates/client/eth-client" } +mc-starknet-block-import = { path = "crates/client/starknet-block-import" } # Madara runtime madara-runtime = { path = "crates/runtime" } diff --git a/crates/client/db/src/lib.rs b/crates/client/db/src/lib.rs index 1928917cb7..29089ab935 100644 --- a/crates/client/db/src/lib.rs +++ b/crates/client/db/src/lib.rs @@ -21,7 +21,7 @@ use starknet_api::hash::StarkHash; mod da_db; mod db_opening_utils; mod messaging_db; -mod sierra_classes_db; +pub mod sierra_classes_db; pub use messaging_db::LastSyncedEventBlock; mod l1_handler_tx_fee; mod meta_db; diff --git a/crates/client/starknet-block-import/Cargo.toml b/crates/client/starknet-block-import/Cargo.toml new file mode 100644 index 0000000000..013ee0a0cb --- /dev/null +++ b/crates/client/starknet-block-import/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "mc-starknet-block-import" +version.workspace = true +edition.workspace = true +description = "Starknet specific block import logic" +homepage = "https://github.com/keep-starknet-strange/madara" +license = "MIT" +publish = false +repository = "https://github.com/keep-starknet-strange/madara" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +async-trait = "0.1" +log = { workspace = true } +num-bigint = { workspace = true } +thiserror = { workspace = true } + +# Substrate primitives dependencies +sp-api = { workspace = true } +sp-consensus = { workspace = true } +sp-runtime = { workspace = true } + +# Substrate client dependencies +sc-consensus = { workspace = true } +sc-rpc-api = { workspace = true } + +# Starknet +blockifier = { workspace = true } +cairo-lang-starknet = { workspace = true } +cairo-lang-starknet-classes = { workspace = true } +cairo-lang-utils = { workspace = true } +cairo-vm = { workspace = true } +hex = { workspace = true } +madara-runtime = { workspace = true } +mc-db = { workspace = true } +mc-rpc = { workspace = true } +pallet-starknet = { workspace = true } +pallet-starknet-runtime-api = { workspace = true } +starknet-core = { workspace = true } +starknet_api = { workspace = true, features = [ + "scale-info", + "parity-scale-codec", +] } + +# Primitives +mp-felt = { workspace = true } +mp-transactions = { workspace = true, features = ["scale-info"] } + +[dev-dependencies] +serde_json = { workspace = true } diff --git a/crates/client/starknet-block-import/README.md b/crates/client/starknet-block-import/README.md new file mode 100644 index 0000000000..3ae53689fa --- /dev/null +++ b/crates/client/starknet-block-import/README.md @@ -0,0 +1,50 @@ +# Starknet block import + +This crate introduces a Starknet specific handler that can be added to the block +import pipeline. More specifically, it "wraps" the underlying block import logic +i.e. executes first in the queue. + +Read more about block import pipeline: + +- +- + +The purpose of this custom block import logic is to do additional checks for +declare transactions. Despite the introduction of the safe intermediate +representation (Sierra) for Cairo, there's still a possibility of the following +attack: + +- User crafts a malicious Cairo contract the execution of which cannot be proven +- User submits that transaction via a patched node that does not verify Sierra + classes +- The runtime does not have Sierra classes and therefore cannot check the + validiy either +- Sequencer fails to prove the execution and also cannot charge for the work + done => DoS attack vector + +Read more about Sierra and the problem it addresses: + +- + +Starknet block import solves the issue above as follows: + +- Upon receiving a new block it searches for declare transactions +- For every declare transaction found, it tries to find according Sierra classes + in the local DB +- It tries to compile the class to check if they match the contract class from + the transaction +- The block import fails if there is at least one transaction with mismatching + class hashes + +## Notes + +Currently Sierra classes DB is populated when user submits RPC requests and +therefore the approch works for single node setup only. In order to make it work +in the multi-node setting, one needs to query missing Sierra classes from other +nodes via P2P (see +) + +Cairo compiler version mismatch can be a problem, e.g. if the version used by +Madara is lagging behind significantly it can fail to compile Sierra classes +obtained from the recent compilers. Similarly, old Sierra classes might not +compile because of the broken backward compatibility. diff --git a/crates/client/starknet-block-import/src/compilation.rs b/crates/client/starknet-block-import/src/compilation.rs new file mode 100644 index 0000000000..676b6eb795 --- /dev/null +++ b/crates/client/starknet-block-import/src/compilation.rs @@ -0,0 +1,265 @@ +use blockifier::execution::contract_class::{ContractClass as BlockifierCasmClass, EntryPointV1}; +use cairo_lang_starknet_classes::casm_contract_class::{CasmContractClass, StarknetSierraCompilationError}; +use cairo_lang_starknet_classes::contract_class::{ + ContractClass as SierraContractClass, ContractEntryPoint as SierraEntryPoint, + ContractEntryPoints as SierraEntryPoints, +}; +use cairo_lang_utils::bigint::BigUintAsHex; +use cairo_vm::types::program::Program; +use cairo_vm::types::relocatable::MaybeRelocatable; +use mp_felt::Felt252Wrapper; +use mp_transactions::from_broadcasted_transactions::casm_contract_class_to_compiled_class; +use num_bigint::BigUint; +use starknet_api::deprecated_contract_class::{EntryPoint as EntryPointV0, EntryPointType as DeprecatedEntryPointType}; +use starknet_api::hash::StarkFelt; +use starknet_api::state::{ + ContractClass as BlockifierSierraClass, EntryPoint as BlockifierEntryPoint, + EntryPointType as BlockifierEntryPointType, +}; +use starknet_core::types::contract::{ + CompiledClass, CompiledClassEntrypoint, CompiledClassEntrypointList, ComputeClassHashError, +}; +use starknet_core::types::{FieldElement, FromByteArrayError}; + +#[derive(Debug, thiserror::Error)] +pub enum CompilationError { + #[error(transparent)] + ComputeClassHash(#[from] ComputeClassHashError), + #[error(transparent)] + SierraCompilation(#[from] StarknetSierraCompilationError), + #[error("Unexpected relocatable while converting program to bytecode")] + UnexpectedRelocatable, + #[error("Failed to parse felt from bytes: {0}")] + FeltFromBytes(#[from] FromByteArrayError), +} + +pub(crate) fn blockifier_casm_class_to_compiled_class_hash( + casm_class: BlockifierCasmClass, +) -> Result { + let (bytecode, entry_points_by_type) = match casm_class { + BlockifierCasmClass::V0(class) => { + let mut entry_points_by_type = class.entry_points_by_type.clone(); + let entrypoints = CompiledClassEntrypointList { + external: entry_points_by_type + .shift_remove(&DeprecatedEntryPointType::External) + .map_or(vec![], convert_casm_entry_points_v0), + l1_handler: entry_points_by_type + .shift_remove(&DeprecatedEntryPointType::L1Handler) + .map_or(vec![], convert_casm_entry_points_v0), + constructor: entry_points_by_type + .shift_remove(&DeprecatedEntryPointType::Constructor) + .map_or(vec![], convert_casm_entry_points_v0), + }; + let bytecode = cairo_vm_program_to_bytecode(&class.program)?; + (bytecode, entrypoints) + } + BlockifierCasmClass::V1(class) => { + let mut entry_points_by_type = class.entry_points_by_type.clone(); + let entrypoints = CompiledClassEntrypointList { + external: entry_points_by_type + .shift_remove(&DeprecatedEntryPointType::External) + .map_or(vec![], convert_casm_entry_points_v1), + l1_handler: entry_points_by_type + .shift_remove(&DeprecatedEntryPointType::L1Handler) + .map_or(vec![], convert_casm_entry_points_v1), + constructor: entry_points_by_type + .shift_remove(&DeprecatedEntryPointType::Constructor) + .map_or(vec![], convert_casm_entry_points_v1), + }; + let bytecode = cairo_vm_program_to_bytecode(&class.program)?; + (bytecode, entrypoints) + } + }; + let compiled_class = CompiledClass { + bytecode, + entry_points_by_type, + // The rest of the fields do not contribute to the class hash + bytecode_segment_lengths: Default::default(), + prime: Default::default(), + compiler_version: Default::default(), + hints: Default::default(), + pythonic_hints: Default::default(), + }; + compiled_class.class_hash().map_err(Into::into) +} + +pub(crate) fn blockifier_sierra_class_to_compiled_class_hash( + sierra_class: BlockifierSierraClass, +) -> Result { + let BlockifierSierraClass { sierra_program, mut entry_points_by_type, .. } = sierra_class; + + let sierra_contract_class = SierraContractClass { + sierra_program: sierra_program.iter().map(stark_felt_to_biguint_as_hex).collect(), + entry_points_by_type: SierraEntryPoints { + external: entry_points_by_type + .shift_remove(&BlockifierEntryPointType::External) + .map_or(vec![], convert_sierra_entry_points), + l1_handler: entry_points_by_type + .shift_remove(&BlockifierEntryPointType::L1Handler) + .map_or(vec![], convert_sierra_entry_points), + constructor: entry_points_by_type + .shift_remove(&BlockifierEntryPointType::Constructor) + .map_or(vec![], convert_sierra_entry_points), + }, + // The rest of the fields are not used for compilation + sierra_program_debug_info: None, + contract_class_version: Default::default(), + abi: None, + }; + + // Pythonic hints do not affect the class hash calculation + // FIXME: more restrictive max bytecode size? + let casm_contract_class = CasmContractClass::from_contract_class(sierra_contract_class, false, usize::MAX)?; + let compiled_class = casm_contract_class_to_compiled_class(&casm_contract_class); + compiled_class.class_hash().map_err(Into::into) +} + +pub fn convert_sierra_entry_points(entry_points: Vec) -> Vec { + entry_points + .into_iter() + .map(|entry_point| SierraEntryPoint { + selector: stark_felt_to_biguint(&entry_point.selector.0), + function_idx: entry_point.function_idx.0 as usize, + }) + .collect() +} + +pub fn convert_casm_entry_points_v1(entry_points: Vec) -> Vec { + entry_points + .into_iter() + .map(|entry_point| CompiledClassEntrypoint { + builtins: entry_point.builtins.into_iter().map(normalize_builtin_name).collect(), + offset: entry_point.offset.0, + selector: stark_felt_to_field_element(&entry_point.selector.0), + }) + .collect() +} + +pub fn convert_casm_entry_points_v0(entry_points: Vec) -> Vec { + entry_points + .into_iter() + .map(|entry_point| CompiledClassEntrypoint { + builtins: vec![], + offset: entry_point.offset.0, + selector: stark_felt_to_field_element(&entry_point.selector.0), + }) + .collect() +} + +pub(crate) fn cairo_vm_program_to_bytecode(program: &Program) -> Result, CompilationError> { + let mut bytecode = Vec::with_capacity(program.data_len()); + for item in program.iter_data() { + match item { + MaybeRelocatable::Int(felt) => bytecode.push(Felt252Wrapper::from(felt.clone()).into()), + MaybeRelocatable::RelocatableValue(_) => return Err(CompilationError::UnexpectedRelocatable), + } + } + Ok(bytecode) +} + +pub fn stark_felt_to_biguint(felt: &StarkFelt) -> BigUint { + BigUint::from_bytes_be(felt.bytes()) +} + +pub fn stark_felt_to_biguint_as_hex(felt: &StarkFelt) -> BigUintAsHex { + BigUintAsHex { value: stark_felt_to_biguint(felt) } +} + +pub fn stark_felt_to_field_element(felt: &StarkFelt) -> FieldElement { + // Can only fail if the 32 byte number is not smaller than the field's modulus, + // but StarkFelt already enforces that + FieldElement::from_bytes_be(&felt.0).unwrap() +} + +// CairoVM adds "_builtin" suffix to builtin names. +// Need to remove it because it affects class hash. +fn normalize_builtin_name(builtin: String) -> String { + builtin.strip_suffix("_builtin").map(Into::into).unwrap_or(builtin) +} + +#[cfg(test)] +mod test { + use blockifier::execution::contract_class::{ContractClass as BlockifierCasmClass, ContractClassV1}; + use mc_rpc::flattened_sierra_to_sierra_contract_class; + use starknet_core::types::contract::SierraClass; + use starknet_core::types::FieldElement; + + use super::{blockifier_casm_class_to_compiled_class_hash, blockifier_sierra_class_to_compiled_class_hash}; + + #[test] + fn test_blockifier_casm_class_to_compiled_class_hash_same_compiler_version() { + // starkli class-hash + // crates/client/starknet-block-import/tests/same_compiler/compiled_contract_class.json + let expected_class_hash = + FieldElement::from_hex_be("0x065f93ec23a940ec285a12359778a0865dd20deceec9be7c6e000257e7b0e009").unwrap(); + let casm_class = BlockifierCasmClass::V1( + ContractClassV1::try_from_json_string(include_str!("../tests/same_compiler/compiled_contract_class.json")) + .unwrap(), + ); + let casm_class_hash = blockifier_casm_class_to_compiled_class_hash(casm_class).unwrap(); + assert_eq!(expected_class_hash, casm_class_hash); + } + + #[test] + fn test_blockifier_sierra_class_to_compiled_class_hash_same_compiler_version() { + let expected_class_hash = + FieldElement::from_hex_be("0x065f93ec23a940ec285a12359778a0865dd20deceec9be7c6e000257e7b0e009").unwrap(); + let sierra_class: SierraClass = + serde_json::from_str(include_str!("../tests/same_compiler/sierra_contract_class.json")).unwrap(); + let blockifier_sierra_class = flattened_sierra_to_sierra_contract_class(sierra_class.flatten().unwrap().into()); + let casm_class_hash = blockifier_sierra_class_to_compiled_class_hash(blockifier_sierra_class).unwrap(); + assert_eq!(expected_class_hash, casm_class_hash); + } + + #[test] + fn test_blockifier_casm_class_to_compiled_class_hash_newer_compiler() { + // starkli class-hash + // crates/client/starknet-block-import/tests/newer_compiler/compiled_contract_class.json + let expected_class_hash = + FieldElement::from_hex_be("0x04fbe579190ab2932b2badac19b51cc45c7f6e88b2915362e0dd2341a5a28563").unwrap(); + let casm_class = BlockifierCasmClass::V1( + ContractClassV1::try_from_json_string(include_str!("../tests/newer_compiler/compiled_contract_class.json")) + .unwrap(), + ); + let casm_class_hash = blockifier_casm_class_to_compiled_class_hash(casm_class).unwrap(); + assert_eq!(expected_class_hash, casm_class_hash); + } + + #[test] + #[should_panic] + fn test_blockifier_sierra_class_to_compiled_class_hash_newer_compiler() { + let expected_class_hash = + FieldElement::from_hex_be("0x04fbe579190ab2932b2badac19b51cc45c7f6e88b2915362e0dd2341a5a28563").unwrap(); + let sierra_class: SierraClass = + serde_json::from_str(include_str!("../tests/newer_compiler/sierra_contract_class.json")).unwrap(); + let blockifier_sierra_class = flattened_sierra_to_sierra_contract_class(sierra_class.flatten().unwrap().into()); + let casm_class_hash = blockifier_sierra_class_to_compiled_class_hash(blockifier_sierra_class).unwrap(); + assert_eq!(expected_class_hash, casm_class_hash); + } + + #[test] + fn test_blockifier_casm_class_to_compiled_class_hash_older_compiler() { + // starkli class-hash + // crates/client/starknet-block-import/tests/older_compiler/compiled_contract_class.json + let expected_class_hash = + FieldElement::from_hex_be("0x03ef7bb4fc22d98580e823f280742d58620109e1b597d0463e8d7d154f9cb5d7").unwrap(); + let casm_class = BlockifierCasmClass::V1( + ContractClassV1::try_from_json_string(include_str!("../tests/older_compiler/compiled_contract_class.json")) + .unwrap(), + ); + let casm_class_hash = blockifier_casm_class_to_compiled_class_hash(casm_class).unwrap(); + assert_eq!(expected_class_hash, casm_class_hash); + } + + #[ignore] + #[test] + fn test_blockifier_sierra_class_to_compiled_class_hash_older_compiler() { + let expected_class_hash = + FieldElement::from_hex_be("0x03ef7bb4fc22d98580e823f280742d58620109e1b597d0463e8d7d154f9cb5d7").unwrap(); + let sierra_class: SierraClass = + serde_json::from_str(include_str!("../tests/older_compiler/sierra_contract_class.json")).unwrap(); + let blockifier_sierra_class = flattened_sierra_to_sierra_contract_class(sierra_class.flatten().unwrap().into()); + let casm_class_hash = blockifier_sierra_class_to_compiled_class_hash(blockifier_sierra_class).unwrap(); + assert_eq!(expected_class_hash, casm_class_hash); + } +} diff --git a/crates/client/starknet-block-import/src/lib.rs b/crates/client/starknet-block-import/src/lib.rs new file mode 100644 index 0000000000..144e100d94 --- /dev/null +++ b/crates/client/starknet-block-import/src/lib.rs @@ -0,0 +1,112 @@ +#![doc = include_str!("../README.md")] + +use std::sync::Arc; + +use async_trait::async_trait; +use blockifier::transaction::account_transaction::AccountTransaction; +use blockifier::transaction::transaction_execution::Transaction; +use madara_runtime::opaque::Block; +use madara_runtime::Hash; +use pallet_starknet_runtime_api::StarknetRuntimeApi; +use sc_consensus::{BlockCheckParams, BlockImport, BlockImportParams, ImportResult, JustificationImport}; +use sp_api::{HeaderT, ProvideRuntimeApi}; +use sp_consensus::Error as ConsensusError; +use sp_runtime::traits::NumberFor; +use sp_runtime::Justification; + +mod compilation; +mod validation; + +use crate::validation::validate_declare_transaction; + +type MadaraBackend = mc_db::Backend; + +pub struct StarknetBlockImport> { + inner: I, + client: Arc, + madara_backend: Arc, +} + +#[async_trait] +impl BlockImport for StarknetBlockImport +where + I: BlockImport + Send + Clone, + C: ProvideRuntimeApi + Send + Sync, + C::Api: StarknetRuntimeApi, +{ + type Error = ConsensusError; + + async fn check_block(&mut self, block: BlockCheckParams) -> Result { + self.inner.check_block(block).await + } + + async fn import_block(&mut self, block: BlockImportParams) -> Result { + log::debug!("🐺 Starknet block import: verifying declared CASM classes against local Sierra classes"); + if let Some(extrinsics) = &block.body { + // Extrinsic filter does not access the block state so technically the block hash does not matter. + // But since we need to provide one anyways, parent hash is a convenient option. + let prev_block_hash = *block.header.parent_hash(); + let transactions: Vec = self + .client + .runtime_api() + .extrinsic_filter(prev_block_hash, extrinsics.clone()) + .map_err(|e| ConsensusError::ClientImport(e.to_string()))?; + + for tx in transactions { + if let Transaction::AccountTransaction(AccountTransaction::Declare(declare)) = tx { + log::trace!("🐺 Starknet block import: checking declare transaction\n\t{:?}", declare,); + validate_declare_transaction(declare, self.madara_backend.sierra_classes().clone())?; + } + } + } + + self.inner.import_block(block).await + } +} + +#[async_trait] +impl JustificationImport for StarknetBlockImport +where + I: JustificationImport + Send + Clone, + C: ProvideRuntimeApi + Send + Sync, +{ + type Error = I::Error; + + async fn on_start(&mut self) -> Vec<(Hash, NumberFor)> { + self.inner.on_start().await + } + + async fn import_justification( + &mut self, + hash: Hash, + number: NumberFor, + justification: Justification, + ) -> Result<(), Self::Error> { + self.inner.import_justification(hash, number, justification).await + } +} + +impl StarknetBlockImport +where + I: BlockImport + Send + Sync + Clone, + C: ProvideRuntimeApi + Send, +{ + pub fn new(inner: I, client: Arc, madara_backend: Arc) -> Self { + Self { inner, client, madara_backend } + } + + pub fn unwrap(self) -> I { + self.inner + } +} + +// https://github.com/rust-lang/rust/issues/41481 +impl Clone for StarknetBlockImport +where + I: BlockImport + Send + Clone, + C: ProvideRuntimeApi + Send, +{ + fn clone(&self) -> Self { + Self { inner: self.inner.clone(), client: self.client.clone(), madara_backend: self.madara_backend.clone() } + } +} diff --git a/crates/client/starknet-block-import/src/validation.rs b/crates/client/starknet-block-import/src/validation.rs new file mode 100644 index 0000000000..f8aa637b3b --- /dev/null +++ b/crates/client/starknet-block-import/src/validation.rs @@ -0,0 +1,53 @@ +use std::sync::Arc; + +use blockifier::transaction::transactions::DeclareTransaction; +use mc_db::sierra_classes_db::SierraClassesDb; +use sp_consensus::Error as ConsensusError; + +use crate::compilation::{ + blockifier_casm_class_to_compiled_class_hash, blockifier_sierra_class_to_compiled_class_hash, + stark_felt_to_field_element, +}; + +pub fn validate_declare_transaction( + declare: DeclareTransaction, + sierra_classes_db: Arc, +) -> Result<(), ConsensusError> { + // 0. Check if it's declare V2 or higher and extract Casm class hash + let expected_casm_class_hash = match declare.tx() { + starknet_api::transaction::DeclareTransaction::V2(v2) => stark_felt_to_field_element(&v2.compiled_class_hash.0), + starknet_api::transaction::DeclareTransaction::V3(v3) => stark_felt_to_field_element(&v3.compiled_class_hash.0), + _ => return Ok(()), + }; + + // 1. Check if we have the according Sierra class stored locally (should have been saved during the + // add declare rpc call) + let sierra_class = sierra_classes_db + .get_sierra_class(declare.class_hash()) + .map_err(|e| ConsensusError::Other(Box::new(e)))? + .ok_or_else(|| { + ConsensusError::StateUnavailable(format!("Could not find Sierra class locally {:?}", declare.class_hash())) + })?; + + // 2. Check if Casm class matches the compiled class hash in the transaction + let compiled_casm_class_hash = blockifier_casm_class_to_compiled_class_hash(declare.class_info.contract_class()) + .map_err(|e| ConsensusError::Other(Box::new(e)))?; + if compiled_casm_class_hash != expected_casm_class_hash { + return Err(ConsensusError::ClientImport(format!( + "Mismatched class hash (compiling casm class from extrinsic): expected (in tx) {0:x}, got {1:x}", + expected_casm_class_hash, compiled_casm_class_hash + ))); + } + + // 3. Compile Sierra class to Casm class and check class hashes again + let compiled_casm_class_hash_from_sierra_class = + blockifier_sierra_class_to_compiled_class_hash(sierra_class).map_err(|e| ConsensusError::Other(Box::new(e)))?; + if compiled_casm_class_hash_from_sierra_class != expected_casm_class_hash { + return Err(ConsensusError::ClientImport(format!( + "Mismatched class hash (compiling sierra class from local db): expected (in tx) {0:x}, got {1:x}", + expected_casm_class_hash, compiled_casm_class_hash_from_sierra_class + ))); + } + + Ok(()) +} diff --git a/crates/client/starknet-block-import/tests/newer_compiler/.tool-versions b/crates/client/starknet-block-import/tests/newer_compiler/.tool-versions new file mode 100644 index 0000000000..0f25521fc2 --- /dev/null +++ b/crates/client/starknet-block-import/tests/newer_compiler/.tool-versions @@ -0,0 +1 @@ +scarb = 2.6.4 \ No newline at end of file diff --git a/crates/client/starknet-block-import/tests/newer_compiler/compiled_contract_class.json b/crates/client/starknet-block-import/tests/newer_compiler/compiled_contract_class.json new file mode 100644 index 0000000000..37a0d89740 --- /dev/null +++ b/crates/client/starknet-block-import/tests/newer_compiler/compiled_contract_class.json @@ -0,0 +1,412 @@ +{ + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "compiler_version": "2.6.3", + "bytecode": [ + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0x100000000000000000000000000000000", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x9e", + "0x4825800180007ffa", + "0x0", + "0x400280007ff97fff", + "0x482680017ff98000", + "0x1", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0xa", + "0x482680017ffc8000", + "0x1", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480280007ffc8000", + "0x10780017fff7fff", + "0x8", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x20680017fff7ffe", + "0x76", + "0x48307ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ff77fff8000", + "0x48127ff57fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0xf2", + "0x482480017fff8000", + "0xf1", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff3", + "0x3d7c", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff27fff", + "0x10780017fff7fff", + "0x46", + "0x4824800180007ff3", + "0x3d7c", + "0x400080007ff37fff", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x27d877ff18f2ff9ed25ad76706d4f9d684e1bc6bae661861ea8b5c8baaa1ec0", + "0x482480017ff18000", + "0x1", + "0x480680017fff8000", + "0x53746f7261676552656164", + "0x400280007ffb7fff", + "0x400280017ffb7ffb", + "0x400280027ffb7ffc", + "0x400280037ffb7ffd", + "0x480280057ffb8000", + "0x20680017fff7fff", + "0x25", + "0x480280067ffb8000", + "0x480280047ffb8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x27d877ff18f2ff9ed25ad76706d4f9d684e1bc6bae661861ea8b5c8baaa1ec0", + "0x48307fef7ffc8000", + "0x480680017fff8000", + "0x53746f726167655772697465", + "0x400280077ffb7fff", + "0x400280087ffb7ffb", + "0x400280097ffb7ffc", + "0x4002800a7ffb7ffd", + "0x4002800b7ffb7ffe", + "0x4802800d7ffb8000", + "0x20680017fff7fff", + "0xd", + "0x40780017fff7fff", + "0x1", + "0x48127ff57fff8000", + "0x4802800c7ffb8000", + "0x482680017ffb8000", + "0xe", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x4802800c7ffb8000", + "0x482680017ffb8000", + "0x10", + "0x4802800e7ffb8000", + "0x4802800f7ffb8000", + "0x10780017fff7fff", + "0x9", + "0x40780017fff7fff", + "0x7", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x8", + "0x480280067ffb8000", + "0x480280077ffb8000", + "0x48127ff27fff8000", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff08000", + "0x1", + "0x48127fee7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x400080007ffe7fff", + "0x48127ff87fff8000", + "0x48127ff67fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0x100000000000000000000000000000000", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x60", + "0x4825800180007ffa", + "0x0", + "0x400280007ff97fff", + "0x482680017ff98000", + "0x1", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ffc7fff8000", + "0x48127ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x55", + "0x482480017fff8000", + "0x54", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff8", + "0xd70", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff77fff", + "0x10780017fff7fff", + "0x2b", + "0x4824800180007ff8", + "0xd70", + "0x400080007ff87fff", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x27d877ff18f2ff9ed25ad76706d4f9d684e1bc6bae661861ea8b5c8baaa1ec0", + "0x482480017ff68000", + "0x1", + "0x480680017fff8000", + "0x53746f7261676552656164", + "0x400280007ffb7fff", + "0x400280017ffb7ffb", + "0x400280027ffb7ffc", + "0x400280037ffb7ffd", + "0x480280057ffb8000", + "0x20680017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480280067ffb8000", + "0x400080007ffe7fff", + "0x48127ffb7fff8000", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48127ffd7fff8000", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x8", + "0x480680017fff8000", + "0x1", + "0x480280067ffb8000", + "0x480280077ffb8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff58000", + "0x1", + "0x48127ff37fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe" + ], + "bytecode_segment_lengths": [178, 116], + "hints": [ + [ + 0, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x0" }, + "rhs": { "Deref": { "register": "FP", "offset": -6 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [38, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 57, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x3d7c" }, + "rhs": { "Deref": { "register": "AP", "offset": -12 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [ + 81, + [ + { + "SystemCall": { + "system": { "Deref": { "register": "FP", "offset": -5 } } + } + } + ] + ], + [ + 98, + [ + { + "SystemCall": { + "system": { + "BinOp": { + "op": "Add", + "a": { "register": "FP", "offset": -5 }, + "b": { "Immediate": "0x7" } + } + } + } + } + ] + ], + [101, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [134, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [149, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [163, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 178, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x0" }, + "rhs": { "Deref": { "register": "FP", "offset": -6 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [195, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 214, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0xd70" }, + "rhs": { "Deref": { "register": "AP", "offset": -7 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [ + 238, + [ + { + "SystemCall": { + "system": { "Deref": { "register": "FP", "offset": -5 } } + } + } + ] + ], + [241, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [264, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [279, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]] + ], + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320", + "offset": 0, + "builtins": ["range_check"] + }, + { + "selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695", + "offset": 178, + "builtins": ["range_check"] + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + } +} diff --git a/crates/client/starknet-block-import/tests/newer_compiler/sierra_contract_class.json b/crates/client/starknet-block-import/tests/newer_compiler/sierra_contract_class.json new file mode 100644 index 0000000000..ac6cd432af --- /dev/null +++ b/crates/client/starknet-block-import/tests/newer_compiler/sierra_contract_class.json @@ -0,0 +1,380 @@ +{ + "sierra_program": [ + "0x1", + "0x5", + "0x0", + "0x2", + "0x6", + "0x3", + "0x99", + "0x67", + "0x16", + "0x52616e6765436865636b", + "0x800000000000000100000000000000000000000000000000", + "0x436f6e7374", + "0x800000000000000000000000000000000000000000000002", + "0x1", + "0x12", + "0x2", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x4f7574206f6620676173", + "0x4172726179", + "0x800000000000000300000000000000000000000000000001", + "0x536e617073686f74", + "0x800000000000000700000000000000000000000000000001", + "0x3", + "0x537472756374", + "0x800000000000000700000000000000000000000000000002", + "0x0", + "0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62", + "0x4", + "0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3", + "0x5", + "0x8", + "0x753332", + "0x800000000000000700000000000000000000000000000000", + "0x53746f7261676541646472657373", + "0x53746f726167654261736541646472657373", + "0x4275696c74696e436f737473", + "0x53797374656d", + "0x800000000000000f00000000000000000000000000000001", + "0x16a4c8d7c05909052238a862d8cc3e7975bf05a07b3a69c6b28951083a6d672", + "0x800000000000000300000000000000000000000000000003", + "0xd", + "0x456e756d", + "0x9931c641b913035ae674b400b61a51476d506bbe8bba2ff8a6272790aba9e6", + "0x6", + "0xe", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x66656c74323532", + "0x800000000000000700000000000000000000000000000003", + "0x11c6d8087e00642489f92d2821ad6ebd6532ad1a3b6d12833da6d6810391511", + "0x11", + "0x426f78", + "0x4761734275696c74696e", + "0x33", + "0x7265766f6b655f61705f747261636b696e67", + "0x77697468647261775f676173", + "0x6272616e63685f616c69676e", + "0x7374727563745f6465636f6e737472756374", + "0x656e61626c655f61705f747261636b696e67", + "0x73746f72655f74656d70", + "0x61727261795f736e617073686f745f706f705f66726f6e74", + "0x756e626f78", + "0x72656e616d65", + "0x656e756d5f696e6974", + "0x13", + "0x6a756d70", + "0x7374727563745f636f6e737472756374", + "0x656e756d5f6d61746368", + "0x64697361626c655f61705f747261636b696e67", + "0x64726f70", + "0x14", + "0x61727261795f6e6577", + "0x636f6e73745f61735f696d6d656469617465", + "0x10", + "0x61727261795f617070656e64", + "0xf", + "0x15", + "0xc", + "0x6765745f6275696c74696e5f636f737473", + "0xb", + "0x77697468647261775f6761735f616c6c", + "0x73746f726167655f626173655f616464726573735f636f6e7374", + "0x27d877ff18f2ff9ed25ad76706d4f9d684e1bc6bae661861ea8b5c8baaa1ec0", + "0x73746f726167655f616464726573735f66726f6d5f62617365", + "0x7", + "0x9", + "0x73746f726167655f726561645f73797363616c6c", + "0x66656c743235325f616464", + "0x73746f726167655f77726974655f73797363616c6c", + "0x736e617073686f745f74616b65", + "0xe1", + "0xffffffffffffffff", + "0x7f", + "0xa", + "0x6f", + "0x27", + "0x17", + "0x18", + "0x19", + "0x1a", + "0x1b", + "0x1c", + "0x1d", + "0x1e", + "0x1f", + "0x20", + "0x61", + "0x21", + "0x22", + "0x23", + "0x24", + "0x25", + "0x26", + "0x28", + "0x53", + "0x29", + "0x2a", + "0x2b", + "0x2c", + "0x2d", + "0x2e", + "0x2f", + "0x30", + "0x31", + "0x4e", + "0x32", + "0x34", + "0x35", + "0x36", + "0x37", + "0x38", + "0x39", + "0x3a", + "0x3b", + "0x3c", + "0x3d", + "0x58", + "0x3e", + "0x3f", + "0x40", + "0x41", + "0x42", + "0x43", + "0x44", + "0x45", + "0x46", + "0x47", + "0x48", + "0x49", + "0x4a", + "0x4b", + "0x4c", + "0x4d", + "0x4f", + "0x50", + "0x51", + "0x52", + "0xd3", + "0xa2", + "0xc6", + "0xbd", + "0x8d", + "0x818", + "0x100f13051211100f0e050d0c06050b0a090706050403080706050403020100", + "0x5200514111f0f1e111d0f021c181b181a1819181711071605040315051411", + "0xd2a2905060528112721182614111d0f2507060504032405230522111f210e", + "0x535060505340605053311050532113115050530112f112e112d2c022b0605", + "0x5053a05073705073629050539113837050532130505321107370507360605", + "0x6050541060505324005053f0605053e0605053c3d05053c1305053c113b37", + "0x5053211454205053244050532430505320507420507362405053920050539", + "0xe050550114f114e114d4c050532160505324b05053f114a49070548114746", + "0x3f2905053c0705053f0e05053211074205073623050539150505390e05053c", + "0x1107114b23075315130752070511070511115205111111511505053c050505", + "0x5207160523111305520513051511115205111311160552050e050e11115205", + "0x54c1120055205440516114405520554054b11115205110711460524544c07", + "0x51107111137051144114005520524054611420552054c0554112405520520", + "0x52050605461142055205460554110605520529052411290552051120111152", + "0x5705560043075207420523111152051107113d055537055207400542114005", + "0x5370537111152050005061111520543052911115205114011115205110711", + "0x5205595807571159055205590500115905520511431158055205113d111152", + "0x5130515115d0552055c055a115c0552055a5b0759115b0552051158115a05", + "0x151313055d0552055d055d110705520507055c111505520515055b11130552", + "0x55f115e055205115e11115205570529111152051140111152051107115d07", + "0x520511621111520511071163620761605f0752075e15130e60115e0552055e", + "0x66055205660565111152051113116605520511641165055205640563116405", + "0xe696856670e5207656607601367115f0552055f0515116505520565056611", + "0x55205680500116e0552056d0563116d0552051162111152051107116c6b6a", + "0x5205700565116705520567055b11700552051164116f055205376807561168", + "0x72710752076f6e7056671568116f0552056f0500116e0552056e0566117005", + "0x7520576056a1176055205113d11115205114011115205110711752c740e73", + "0x52057a056e117a05520579056d117905520578056c1111520577056b117877", + "0x57b055d117205520572055c117105520571055b115f0552055f0515117b05", + "0x7d0552052c055c117c05520574055b111152051107117b72715f13057b0552", + "0x6a055b1111520537053711115205110711117f051144117e05520575056f11", + "0x52051158111152051140117e0552056c056f117d0552056b055c117c055205", + "0x7c055b115f0552055f0515118205520581055a11810552057e800759118005", + "0x5205110711827d7c5f13058205520582055d117d0552057d055c117c055205", + "0x1184055205840500118405520511701183055205113d111152053705371111", + "0x5520587055a11870552058586075911860552051158118505520584830757", + "0x520588055d110705520507055c116305520563055b11620552056205151188", + "0x420529111152053d0571111152051140111152051107118807636213058805", + "0x58a890757118a0552058a0500118a05520511721189055205113d11115205", + "0x130515118e0552058d055a118d0552058b8c0759118c0552051158118b0552", + "0x1313058e0552058e055d110705520507055c111505520515055b1113055205", + "0x11730552051170118f055205113d111152050e0574111152051107118e0715", + "0x5520590910759119105520511581190055205738f07571173055205730500", + "0x520507055c114b0552054b055b1123055205230515119305520592055a1192", + "0x13075207051107051111520511111193074b2313059305520593055d110705", + "0x160523111305520513051511160552050e050e111152051107114b23079415", + "0x113d11115205540506111152054c052911115205110711460595544c075207", + "0x11581124055205204407571120055205200500112005520511431144055205", + "0x5b1113055205130515112905520540055a1140055205244207591142055205", + "0x1107112907151313052905520529055d110705520507055c11150552051505", + "0x615130e60110605520506055f1106055205115e1111520546052911115205", + "0x11580552055705631157055205116211115205110711004307963d37075207", + "0x11370552053705151158055205580566115905520559056511590552051164", + "0x1160055205113d111152051107115f5e5d0e975c5b5a0e52075859073d1367", + "0x520563056b11646307520562056a11620552055c600757115c0552055c0500", + "0x5205370515116705520566056e116605520565056d116505520564056c1111", + "0x5b5a3713056705520567055d115b0552055b055c115a0552055a055b113705", + "0x6a05520568055a11680552055f560759115605520511581111520511071167", + "0x552056a055d115e0552055e055c115d0552055d055b113705520537051511", + "0x6c0500116c0552051170116b055205113d111152051107116a5e5d3713056a", + "0x5a116f0552056d6e0759116e0552051158116d0552056c6b0757116c055205", + "0x110705520507055c110005520500055b114305520543051511700552056f05", + "0x5205113d111152050e0574111152051107117007004313057005520570055d", + "0x52051158117405520572710757117205520572050011720552051170117105", + "0x4b055b1123055205230515117605520575055a1175055205742c0759112c05", + "0x444311130776074b2313057605520576055d110705520507055c114b055205", + "0x980e07051142444311131544431113110e070511424443111315" + ], + "sierra_program_debug_info": { + "type_names": [ + [0, "RangeCheck"], + [ + 1, + "Const" + ], + [2, "Const"], + [3, "Array"], + [4, "Snapshot>"], + [5, "core::array::Span::"], + [6, "Tuple>"], + [7, "Const"], + [8, "u32"], + [9, "StorageAddress"], + [10, "StorageBaseAddress"], + [11, "BuiltinCosts"], + [12, "System"], + [13, "core::panics::Panic"], + [14, "Tuple>"], + [ + 15, + "core::panics::PanicResult::<(core::array::Span::,)>" + ], + [ + 16, + "Const" + ], + [17, "Unit"], + [18, "felt252"], + [19, "core::option::Option::"], + [20, "Box"], + [21, "GasBuiltin"] + ], + "libfunc_names": [ + [0, "revoke_ap_tracking"], + [1, "withdraw_gas"], + [2, "branch_align"], + [3, "struct_deconstruct>"], + [4, "enable_ap_tracking"], + [5, "store_temp"], + [6, "array_snapshot_pop_front"], + [7, "unbox"], + [8, "rename"], + [9, "enum_init, 0>"], + [10, "store_temp>>"], + [11, "store_temp>"], + [12, "jump"], + [13, "struct_construct"], + [14, "enum_init, 1>"], + [15, "enum_match>"], + [16, "disable_ap_tracking"], + [17, "drop>>"], + [18, "drop>"], + [19, "drop"], + [20, "array_new"], + [ + 21, + "const_as_immediate>" + ], + [22, "store_temp"], + [23, "array_append"], + [24, "struct_construct"], + [25, "struct_construct>>"], + [ + 26, + "enum_init,)>, 1>" + ], + [27, "store_temp"], + [28, "store_temp"], + [ + 29, + "store_temp,)>>" + ], + [30, "get_builtin_costs"], + [31, "store_temp"], + [32, "withdraw_gas_all"], + [ + 33, + "storage_base_address_const<1126416765373040447134877403742562949829456288349438530158544342912871308992>" + ], + [34, "storage_address_from_base"], + [35, "const_as_immediate>"], + [36, "store_temp"], + [37, "store_temp"], + [38, "storage_read_syscall"], + [39, "felt252_add"], + [40, "storage_write_syscall"], + [41, "snapshot_take>"], + [42, "drop>"], + [43, "struct_construct>"], + [44, "struct_construct>>"], + [ + 45, + "enum_init,)>, 0>" + ], + [46, "store_temp>"], + [47, "const_as_immediate>"], + [48, "drop"], + [ + 49, + "const_as_immediate>" + ], + [50, "drop>"] + ], + "user_func_names": [ + [0, "counter1::Counter::__wrapper__increase_balance"], + [1, "counter1::Counter::__wrapper__get_balance"] + ] + }, + "contract_class_version": "0.1.0", + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320", + "function_idx": 0 + }, + { + "selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695", + "function_idx": 1 + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + }, + "abi": [ + { + "type": "function", + "name": "increase_balance", + "inputs": [{ "name": "amount", "type": "core::felt252" }], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_balance", + "inputs": [], + "outputs": [{ "type": "core::felt252" }], + "state_mutability": "view" + }, + { + "type": "event", + "name": "counter1::Counter::Event", + "kind": "enum", + "variants": [] + } + ] +} diff --git a/crates/client/starknet-block-import/tests/older_compiler/.tool-versions b/crates/client/starknet-block-import/tests/older_compiler/.tool-versions new file mode 100644 index 0000000000..6bead5a744 --- /dev/null +++ b/crates/client/starknet-block-import/tests/older_compiler/.tool-versions @@ -0,0 +1 @@ +scarb = 0.5.0 \ No newline at end of file diff --git a/crates/client/starknet-block-import/tests/older_compiler/compiled_contract_class.json b/crates/client/starknet-block-import/tests/older_compiler/compiled_contract_class.json new file mode 100644 index 0000000000..637c1eede2 --- /dev/null +++ b/crates/client/starknet-block-import/tests/older_compiler/compiled_contract_class.json @@ -0,0 +1,597 @@ +{ + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "compiler_version": "2.0.0", + "bytecode": [ + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffa858", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x79", + "0x4825800180007ffa", + "0x57a8", + "0x400280007ff97fff", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0xfe", + "0x482680017ff98000", + "0x1", + "0x20680017fff7ffd", + "0x60", + "0x48307ffb80007ffc", + "0x4824800180007fff", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x6", + "0x480680017fff8000", + "0x0", + "0x10780017fff7fff", + "0x4", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x1", + "0x48307ffe80007fff", + "0x20680017fff7fff", + "0x3d", + "0x1104800180018000", + "0x1cc", + "0x482480017fff8000", + "0x1cb", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007fe5", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff37fff", + "0x10780017fff7fff", + "0x20", + "0x4824800180007fe5", + "0x0", + "0x400080007ff47fff", + "0x48127fff7fff8000", + "0x480a7ffb7fff8000", + "0x48127ff17fff8000", + "0x1104800180018000", + "0xf6", + "0x482480017fbb8000", + "0x1", + "0x20680017fff7ffc", + "0xc", + "0x40780017fff7fff", + "0x1", + "0x48127ffe7fff8000", + "0x48127ff87fff8000", + "0x48127ff87fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127fff7fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff18000", + "0x1", + "0x48127fe07fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x1104800180018000", + "0xf4", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ff47fff8000", + "0x48127fe37fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f2073686f727420666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ffd7fff8000", + "0x48127fec7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffe160", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x69", + "0x4825800180007ffa", + "0x1ea0", + "0x400280007ff97fff", + "0x48297ffc80007ffd", + "0x482680017ff98000", + "0x1", + "0x4824800180007ffe", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x6", + "0x480680017fff8000", + "0x0", + "0x10780017fff7fff", + "0x4", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x1", + "0x48307ffe80007fff", + "0x20680017fff7fff", + "0x41", + "0x1104800180018000", + "0x145", + "0x482480017fff8000", + "0x144", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff4", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff47fff", + "0x10780017fff7fff", + "0x24", + "0x4824800180007ff4", + "0x0", + "0x400080007ff57fff", + "0x48127fff7fff8000", + "0x480a7ffb7fff8000", + "0x1104800180018000", + "0x98", + "0x482480017fd58000", + "0x1", + "0x20680017fff7ffc", + "0x11", + "0x40780017fff7fff", + "0x1", + "0x48127ffd7fff8000", + "0x48127ffe7fff8000", + "0x48127ffd7fff8000", + "0x1104800180018000", + "0xa2", + "0x48127ff77fff8000", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127fff7fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff28000", + "0x1", + "0x48127fef7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x1104800180018000", + "0x69", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ff57fff8000", + "0x48127ff27fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0xa", + "0x482680017ffc8000", + "0x1", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480a7ffc7fff8000", + "0x10780017fff7fff", + "0x8", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x48127ffc7fff8000", + "0x48127ffc7fff8000", + "0x20680017fff7ffc", + "0x8", + "0x48127ffe7fff8000", + "0x48127ffe7fff8000", + "0x480680017fff8000", + "0x0", + "0x480080007ffa8000", + "0x208b7fff7fff7ffe", + "0x48127ffe7fff8000", + "0x48127ffe7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x1104800180018000", + "0x40", + "0x20680017fff7ffd", + "0x19", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x48287ffd7ffd8000", + "0x1104800180018000", + "0x6a", + "0x20680017fff7ffd", + "0xb", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x18", + "0x48127fe37fff8000", + "0x48127fe37fff8000", + "0x480680017fff8000", + "0x1", + "0x48127fe37fff8000", + "0x48127fe37fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0x18", + "0x20680017fff7ffd", + "0xa", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x400380007ffd7ffb", + "0x480a7ffc7fff8000", + "0x482680017ffd8000", + "0x1", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x904f2833296109453ae83969e306a0ffe26d05f3d29af52bcc8fe626ac1d6b", + "0x480680017fff8000", + "0x53746f7261676552656164", + "0x400280007ffd7fff", + "0x400380017ffd7ffc", + "0x400280027ffd7ffd", + "0x400280037ffd7ffe", + "0x480280057ffd8000", + "0x20680017fff7fff", + "0xc", + "0x480280047ffd8000", + "0x482680017ffd8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480280067ffd8000", + "0x10780017fff7fff", + "0x9", + "0x480280047ffd8000", + "0x482680017ffd8000", + "0x8", + "0x480680017fff8000", + "0x1", + "0x480280067ffd8000", + "0x480280077ffd8000", + "0x1104800180018000", + "0x47", + "0x20680017fff7ffd", + "0xa", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x904f2833296109453ae83969e306a0ffe26d05f3d29af52bcc8fe626ac1d6b", + "0x480680017fff8000", + "0x53746f726167655772697465", + "0x400280007ffc7fff", + "0x400380017ffc7ffb", + "0x400280027ffc7ffd", + "0x400280037ffc7ffe", + "0x400380047ffc7ffd", + "0x480280067ffc8000", + "0x20680017fff7fff", + "0xd", + "0x480280057ffc8000", + "0x482680017ffc8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x10780017fff7fff", + "0x9", + "0x480280057ffc8000", + "0x482680017ffc8000", + "0x9", + "0x480680017fff8000", + "0x1", + "0x480280077ffc8000", + "0x480280087ffc8000", + "0x1104800180018000", + "0x21", + "0x20680017fff7ffd", + "0xb", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffb", + "0x8", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x1", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffb", + "0x9", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x1", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe" + ], + "hints": [ + [ + 0, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x57a8" }, + "rhs": { "Deref": { "register": "FP", "offset": -6 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [ + 41, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x0" }, + "rhs": { "Deref": { "register": "AP", "offset": -26 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [62, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [80, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [98, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [112, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [126, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 141, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x1ea0" }, + "rhs": { "Deref": { "register": "FP", "offset": -6 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [ + 176, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x0" }, + "rhs": { "Deref": { "register": "AP", "offset": -11 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [196, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [219, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [237, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [251, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 378, + [ + { + "SystemCall": { + "system": { "Deref": { "register": "FP", "offset": -3 } } + } + } + ] + ], + [ + 428, + [ + { + "SystemCall": { + "system": { "Deref": { "register": "FP", "offset": -4 } } + } + } + ] + ] + ], + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320", + "offset": 0, + "builtins": ["range_check"] + }, + { + "selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695", + "offset": 141, + "builtins": ["range_check"] + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + } +} diff --git a/crates/client/starknet-block-import/tests/older_compiler/sierra_contract_class.json b/crates/client/starknet-block-import/tests/older_compiler/sierra_contract_class.json new file mode 100644 index 0000000000..f07afc3390 --- /dev/null +++ b/crates/client/starknet-block-import/tests/older_compiler/sierra_contract_class.json @@ -0,0 +1,681 @@ +{ + "sierra_program": [ + "0x1", + "0x2", + "0x0", + "0x2", + "0x0", + "0x0", + "0xd6", + "0x2a", + "0x20", + "0x52616e6765436865636b", + "0x0", + "0x4761734275696c74696e", + "0x66656c74323532", + "0x4172726179", + "0x1", + "0x2", + "0x536e617073686f74", + "0x3", + "0x537472756374", + "0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62", + "0x4", + "0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3", + "0x456e756d", + "0x11c6d8087e00642489f92d2821ad6ebd6532ad1a3b6d12833da6d6810391511", + "0x6", + "0x753332", + "0x3288d594b9a45d15bb2fcb7903f06cdb06b27f0ba88186ec4cfaa98307cb972", + "0x4275696c74696e436f737473", + "0x35e92dcebd5aa7a2da5bd503f14e1ceb28de72af84e56389c413b772635a4f1", + "0x91b53cd7d1f331c897e86bd435418b9800d25e52836eeb1ddd77b0fbee9f21", + "0xb", + "0x53797374656d", + "0xc", + "0x14de46c93830b854d231d540339ee8ae16bb18830a375fe81572a472d5945f1", + "0xf", + "0x30ff60cf035a0c8fe2fa52438ddbb14986edd88dfd31534ff815990b6f2d285", + "0xe", + "0x10", + "0x5", + "0x19b3b4955bdcfa379bfc5a4949111c4efdd79128f8676f4d0895419b22e2ad7", + "0x12", + "0x2f528e3c691e195fca674982b69c0dc4284f206c3ea4d680220e99b59315a92", + "0x14", + "0x426f78", + "0x29d7d57c04a880978e7b3689f6218e507f3be17588744b58dc17762447ad0e7", + "0x16", + "0xf4dd0b9df3924091abad2d9eb0ea9145b9cb62dd60f7e62963086f49d51a53", + "0x18", + "0x53746f726167654261736541646472657373", + "0x53746f7261676541646472657373", + "0x90d0203c41ad646d024845257a6eceb2f8b59b29ce7420dd518053d2edeedc", + "0x101dc0399934cc08fa0d6f6f2daead4e4a38cabeea1c743e1fc28d2d6e58e99", + "0xd3a26a7712a33547a4a74e7594a446ca400cb36a0c2c307b92eff9ce82ff8", + "0x1e", + "0x76", + "0x7265766f6b655f61705f747261636b696e67", + "0x656e61626c655f61705f747261636b696e67", + "0x77697468647261775f676173", + "0x6272616e63685f616c69676e", + "0x73746f72655f74656d70", + "0x66756e6374696f6e5f63616c6c", + "0x656e756d5f6d61746368", + "0x7", + "0x7374727563745f6465636f6e737472756374", + "0x61727261795f6c656e", + "0x736e617073686f745f74616b65", + "0x8", + "0x64726f70", + "0x7533325f636f6e7374", + "0x72656e616d65", + "0x7533325f6571", + "0x7374727563745f636f6e737472756374", + "0x656e756d5f696e6974", + "0x9", + "0x6a756d70", + "0x626f6f6c5f6e6f745f696d706c", + "0x6765745f6275696c74696e5f636f737473", + "0xa", + "0x77697468647261775f6761735f616c6c", + "0x64697361626c655f61705f747261636b696e67", + "0xd", + "0x11", + "0x61727261795f6e6577", + "0x13", + "0x66656c743235325f636f6e7374", + "0x4f7574206f6620676173", + "0x61727261795f617070656e64", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x496e70757420746f6f2073686f727420666f7220617267756d656e7473", + "0x15", + "0x61727261795f736e617073686f745f706f705f66726f6e74", + "0x17", + "0x756e626f78", + "0x66656c743235325f616464", + "0x19", + "0x73746f726167655f626173655f616464726573735f636f6e7374", + "0x904f2833296109453ae83969e306a0ffe26d05f3d29af52bcc8fe626ac1d6b", + "0x73746f726167655f616464726573735f66726f6d5f62617365", + "0x1b", + "0x73746f726167655f726561645f73797363616c6c", + "0x1c", + "0x73746f726167655f77726974655f73797363616c6c", + "0x1d", + "0x1f", + "0x1bf", + "0xffffffffffffffff", + "0x66", + "0x1a", + "0x53", + "0x44", + "0x21", + "0x22", + "0x23", + "0x24", + "0x28", + "0x29", + "0x2a", + "0x2b", + "0x25", + "0x26", + "0x27", + "0x2c", + "0x3d", + "0x2d", + "0x2e", + "0x2f", + "0x30", + "0x31", + "0x32", + "0x33", + "0x34", + "0x35", + "0x36", + "0x37", + "0x38", + "0x39", + "0x3a", + "0x3b", + "0x3c", + "0x3e", + "0x3f", + "0x40", + "0x41", + "0x42", + "0x43", + "0x45", + "0x46", + "0x49", + "0x47", + "0x48", + "0x4a", + "0x4b", + "0x4c", + "0x4d", + "0x4e", + "0x4f", + "0x50", + "0x51", + "0x52", + "0x54", + "0x55", + "0x56", + "0x57", + "0x58", + "0x59", + "0x5a", + "0x5b", + "0x5c", + "0x5d", + "0x5e", + "0x5f", + "0x60", + "0x61", + "0x62", + "0x63", + "0x64", + "0x65", + "0x67", + "0xeb", + "0x9a", + "0x9e", + "0xd9", + "0xcc", + "0xc5", + "0x101", + "0x106", + "0x110", + "0x138", + "0x132", + "0x152", + "0x16b", + "0x170", + "0x17b", + "0x190", + "0x195", + "0x68", + "0x69", + "0x6a", + "0x1a0", + "0x6b", + "0x6c", + "0x6d", + "0x6e", + "0x6f", + "0x70", + "0x1ad", + "0x71", + "0x1b9", + "0x72", + "0x73", + "0x74", + "0x75", + "0x85", + "0xfa", + "0x117", + "0x140", + "0x144", + "0x158", + "0x15e", + "0x181", + "0x1a7", + "0x1b3", + "0x1081", + "0x7060f02090e0d02060a0c060b02070a090606080706060502040203020100", + "0x60d02090a021716061502070a1402060a0213100610061202090e02111006", + "0x90e1e060d02070a1d061c061b02090e09061a060d02090a1902060a100618", + "0x625062402090e070606231d0622062102090e07060d02070a1d0620061f02", + "0x90e090607062a02090e022902281d0627062602090e100616060d02090a10", + "0x633023202310230022f2e1d062d062c02090e10060d02070a090610062b02", + "0x3c3a06063b3a060639070606381e0606373606063502060633070906341e06", + "0x7400242410606330207410607401006063f023e3a0606333a06063d020706", + "0x6063f1606063f024702464506063302441006063b41060635024306074106", + "0x64a1c06063b49060635090906340706063318060633480606330606063318", + "0x607404b06063302074b0607402006063f1e06063f0906063b090606390706", + "0x4f07064c0c0906341d06063f1a06063f0706064e4d07064c0706063b06074b", + "0x6063922060637510606351e0906341806063b180606395007064c1e06063b", + "0x53060740530606330c06063302075306074007060652100906340906063307", + "0x37060736060740360606330207360607400706063d07060654530606350607", + "0x63f27060637560606353a0906340255360906341606063316060639180606", + "0x402206063f100606331606063b060749060740490606330207490607401c06", + "0x5c060740025b5a060633025958070657060751060740510606330207510607", + "0x6063302075e060740025d410906345c06063d06075c0607405c0606330207", + "0x560607402706063f2d0606375f060635450906345e06063d06075e0607405e", + "0x3302075f0607402d06063f5e0606355c060635060756060740560606330207", + "0xc07610706020707020261060206020261060202026006075f0607405f0606", + "0x61002413a07610645061e024506610609060c020261060209023610072e1e", + "0x2480661063a063a0202610602090218066216066107410636020c0661060c", + "0x2490661060218020261061a0616021d1a0761061c0645021c066106480641", + "0x510661064b064802220661061d064802026106200616024b20076106490645", + "0x25066106021d0202610602090202560261075122071a022206610622061c02", + "0x21d02026106020902025e06024b0227066106530620025306610625064902", + "0x620025a066106270651022706610663062002630661065606220256066106", + "0x27020261065c0653020261060209025e06645c0661075a0625025a0661065a", + "0x2090267660765005f0761072d1e0c0963022d0661062d0656022d06610602", + "0x6610600062d026906610668065e0268066106025c02026106025a02026106", + "0x6c6b6a0c67026d066106160666026c066106690600026b06610607065f026a", + "0x610602090273067271066107700668025f0661065f061002706f6e0961066d", + "0x2610675067002767507610674066f0274066106026e020261067106690202", + "0x661065f0610027906610678066c027806610677066b027706610676066a02", + "0x7d7c7b7a0c067d06610679066d027c0661066f065f027b0661066e062d027a", + "0x2800661066e062d027f0661065f0610027e06610673067102026106020902", + "0x6025a020261060209028281807f0c06820661067e066d02810661066f065f", + "0x83066106830666028306610602740272066106026e02026106160673020261", + "0x61068606710286066106848507770285066106027602840661068372077502", + "0x687066d028906610607065f026506610667062d0288066106660610028706", + "0x673020261065e065302026106025a020261060209028a8965880c068a0661", + "0x26e020261068d0653028d8c0761068b0678028b06610607065f0202610616", + "0x27602900661068f8e0775028f0661068f0666028f0661060279028e066106", + "0x2d02940661060c061002930661069206710292066106909107770291066106", + "0x20902649695940c066406610693066d02960661068c065f02950661061e06", + "0x297066106026e020261063a067a0202610618065302026106025a02026106", + "0x29a066106027602990661069897077502980661069806660298066106027b", + "0x661061e062d029d0661060c0610029c0661069b0671029b066106999a0777", + "0x5a02026106020902a09f9e9d0c06a00661069c066d029f06610607065f029e", + "0x6106a2066602a2066106027402a1066106026e0202610609067a0202610602", + "0xa5067102a5066106a3a4077702a4066106027602a3066106a2a1077502a206", + "0x66d026206610607065f02a806610636062d02a706610610061002a6066106", + "0x761070602070702026106020602026106020202a962a8a70c06a9066106a6", + "0x64502410661063a0641023a06610609063a02026106020902361007aa1e0c", + "0x16021c48076106180645021806610602180202610645061602164507610641", + "0x10021a0661061a061c021d0661061c0648021a066106160648020261064806", + "0x490249066106021d0202610602090202ab0261071d1a071a020c0661060c06", + "0x6106021d0202610602090202ac06024b024b06610620062002200661064906", + "0x625062002250661064b0651024b0661065106200251066106220622022206", + "0x653065302026106025a020261060209022706ad5306610725062502250661", + "0x5c07ae5a63076107561e0c0963025606610656065602560661060227020261", + "0x66000761065f067c025f0661062d065e022d066106025c020261060209025e", + "0x70066106660600026f06610607065f026e0661065a062d0202610600067d02", + "0x6b06af6a06610769067f026306610663061002696867096106706f6e097e02", + "0x273710761066c0681026d066106026e026c0661066a068002026106020902", + "0x740761067776077202770661066d0682027606610673066602026106710673", + "0x6610679066a0202610678067002797807610674066f020261067506530275", + "0x610667062d027d066106630610027c0661067b066c027b0661067a066b027a", + "0x2026106020902807f7e7d0c06800661067c066d027f06610668065f027e06", + "0x8306610668065f027206610667062d028206610663061002810661066b0671", + "0x602740285066106026e02026106020902848372820c068406610681066d02", + "0x88077702880661060276028706610686850775028606610686066602860661", + "0x5f028c0661065e062d028a0661065c06100289066106650671026506610687", + "0x6106025a020261060209028b8d8c8a0c068b06610689066d028d0661060706", + "0x61068f0653028f8e076106900678029006610607065f020261062706530202", + "0x66106929107750292066106920666029206610602790291066106026e0202", + "0x61060c06100296066106950671029506610693940777029406610602760293", + "0x9897640c069906610696066d02980661068e065f02970661061e062d026406", + "0x60274029a066106026e0202610609067a02026106025a0202610602090299", + "0x9d0777029d0661060276029c0661069b9a0775029b0661069b0666029b0661", + "0x5f02a106610636062d02a0066106100610029f0661069e0671029e0661069c", + "0x683020606610602063a02a3a2a1a00c06a30661069f066d02a20661060706", + "0x10066106070685021e066106090684020261060209020c06b0090707610706", + "0x3a0687023a066106021d0202610602090202b106024b02360661061e068602", + "0x60c024506610610066a023606610641068602100661060c06850241066106", + "0x248066106160665020261060209021806b216066107360688024506610645", + "0x490661061a068c021d06610645060c021a0661061c068a021c066106480689", + "0x6610620068d0220066106021d0202610618065302026106020902491d0706", + "0x8e020c06610607068b0251220706510661064b068c022206610645060c024b", + "0x1806610610068f021606610606065f024506610602062d02101e0761060c06", + "0x80020261060209021c06b34806610741067f02413a36096106181645099002", + "0x510661063a065f022206610636062d021d066106091a0791021a0661064806", + "0x93024b2049096106532551220c9202530661061d066602250661061e068f02", + "0x261065a0653025a63076106270694020261060209025606b4270661074b06", + "0x661062d0696022d0661065e5c0795025e066106021d025c06610663065e02", + "0x26766000906670661065f0664026606610620065f020006610649062d025f", + "0x64026e06610620065f026906610649062d0268066106560697020261060209", + "0x26106090673020261061e0698020261060209026f6e6909066f0661066806", + "0x66106700664026b0661063a065f026a06610636062d02700661061c069702", + "0x70609066106060699020706610602065f0206066106021d026c6b6a09066c", + "0x609068f023a06610606065f023606610602062d020906610607068b020907", + "0x61060209021606b54506610710067f02101e0c096106413a36099002410661", + "0x61060c062d021c06610648069b024806610618069a02180661064506800202", + "0x9d02026106020902491d1a0906490661061c069c021d0661061e065f021a06", + "0x65106610620069c02220661061e065f024b0661060c062d02200661061606", + "0x682020c066106021d02090661060706077502070661060206890251224b09", + "0x9066106029e0202610607069802101e0706100661060c0699021e06610609", + "0xc0661060c06a0021e0661061e061c021e0661060218020c06610609069f02", + "0x661063a06a20202610602090216454109b63a36100961070c1e06020ca102", + "0x2b706024b021a0661061806a3021c06610636065f024806610610062d0218", + "0x21c06610645065f024806610641062d021d0661061606a402026106020902", + "0x4b06610749067f02490661062006a602200661061a06a5021a0661061d06a3", + "0x610625069b022506610651069a02510661064b0680020261060209022206b8", + "0x63562709066306610653069c02560661061c065f022706610648062d025306", + "0x25e0661061c065f025c06610648062d025a06610622069d02026106020902", + "0x29e020261061e0698021e0c07610607068e022d5e5c09062d0661065a069c", + "0x3606a0023a0661063a061c023a0661060218023606610610069f0210066106", + "0x21d0202610602090248181609b9454107610709363a06021ea70236066106", + "0x662024906610645065f021d06610641062d021a0661061c06a8021c066106", + "0x610616062d024b0661064806a90202610602090202ba06024b02200661061a", + "0x65106bc02510661062006bb02200661064b0662024906610618065f021d06", + "0x7c002270661062506bf020261060209025306be250661072206bd02220661", + "0x25c06610649065f025a0661061d062d02630661065606c10256066106270c", + "0x61065306c3020261060c0698020261060209025e5c5a09065e0661066306c2", + "0x66005f0906660661062d06c2020006610649065f025f0661061d062d022d06", + "0x610609069b020906610606069a020261060209020706c5060661070206c402", + "0x710077702100661060276020261060209021e06061e0661060c069c020c06", + "0x60661070206c602410606410661063a069c023a06610636069d0236066106", + "0x61060c06ca020c0661060906c902090661060606c8020261060209020706c7", + "0x3606cb02360661060710077702100661060276020261060209021e06061e06", + "0x2090706024b4806020c1e4806020c16410606410661063a06ca023a066106", + "0x49480609071848060ccd02361e071e06cc090706024b4806020c1e4806020c", + "0x2100907090707d00706025148060918480609cf021048074806ce09070602", + "0x65c06d30907060256480609071648060cd20706025148060916480609d106", + "0xd5025f065e06d40251" + ], + "sierra_program_debug_info": { + "type_names": [ + [0, "RangeCheck"], + [1, "GasBuiltin"], + [2, "felt252"], + [3, "Array"], + [4, "Snapshot>"], + [5, "core::array::Span::"], + [6, "Unit"], + [7, "core::option::Option::"], + [8, "u32"], + [9, "core::bool"], + [10, "BuiltinCosts"], + [11, "counter0::Counter::balance_0::ContractState"], + [12, "counter0::Counter::ContractState"], + [13, "System"], + [14, "Tuple"], + [15, "core::Panic"], + [16, "Tuple>"], + [17, "core::PanicResult::<(counter0::Counter::ContractState, ())>"], + [18, "Tuple>"], + [19, "core::PanicResult::<(core::array::Span::,)>"], + [20, "Tuple"], + [21, "core::PanicResult::<(core::felt252,)>"], + [22, "Box"], + [23, "core::option::Option::>"], + [24, "Tuple"], + [ + 25, + "core::PanicResult::<(counter0::Counter::balance_0::ContractState, ())>" + ], + [26, "StorageBaseAddress"], + [27, "StorageAddress"], + [ + 28, + "core::result::Result::>" + ], + [29, "core::result::Result::<(), core::array::Array::>"], + [30, "Tuple"], + [31, "core::PanicResult::<((),)>"] + ], + "libfunc_names": [ + [0, "revoke_ap_tracking"], + [1, "enable_ap_tracking"], + [2, "withdraw_gas"], + [3, "branch_align"], + [4, "store_temp>"], + [5, "function_call"], + [6, "store_temp"], + [7, "enum_match>"], + [8, "struct_deconstruct>"], + [9, "array_len"], + [10, "snapshot_take"], + [11, "drop"], + [12, "u32_const<0>"], + [13, "rename"], + [14, "store_temp"], + [15, "u32_eq"], + [16, "struct_construct"], + [17, "enum_init"], + [18, "store_temp"], + [19, "jump"], + [20, "enum_init"], + [21, "bool_not_impl"], + [22, "enum_match"], + [23, "drop"], + [24, "get_builtin_costs"], + [25, "store_temp"], + [26, "withdraw_gas_all"], + [27, "disable_ap_tracking"], + [28, "struct_construct"], + [29, "struct_construct"], + [30, "store_temp"], + [31, "store_temp"], + [32, "store_temp"], + [33, "store_temp"], + [34, "function_call"], + [ + 35, + "enum_match>" + ], + [36, "drop>"], + [37, "array_new"], + [38, "snapshot_take>"], + [39, "drop>"], + [40, "struct_construct>"], + [41, "struct_construct>>"], + [ + 42, + "enum_init,)>, 0>" + ], + [ + 43, + "store_temp,)>>" + ], + [ + 44, + "enum_init,)>, 1>" + ], + [45, "drop"], + [46, "felt252_const<375233589013918064796019>"], + [47, "array_append"], + [48, "struct_construct"], + [49, "struct_construct>>"], + [50, "function_call"], + [ + 51, + "felt252_const<7733229381460288120802334208475838166080759535023995805565484692595>" + ], + [52, "drop>"], + [ + 53, + "felt252_const<1979706721653833758925397712865600297316042839304765459608024204080243>" + ], + [54, "snapshot_take"], + [55, "drop"], + [56, "function_call"], + [57, "enum_match>"], + [58, "struct_deconstruct>"], + [59, "snapshot_take"], + [60, "store_temp>"], + [61, "function_call"], + [62, "array_snapshot_pop_front"], + [ + 63, + "enum_init>, 0>" + ], + [64, "store_temp>>"], + [ + 65, + "store_temp>>" + ], + [ + 66, + "enum_init>, 1>" + ], + [ + 67, + "enum_match>>" + ], + [68, "unbox"], + [69, "rename"], + [70, "enum_init, 0>"], + [71, "store_temp>"], + [72, "enum_init, 1>"], + [73, "struct_deconstruct"], + [74, "snapshot_take"], + [75, "store_temp"], + [ + 76, + "function_call" + ], + [77, "felt252_add"], + [ + 78, + "function_call" + ], + [ + 79, + "enum_match>" + ], + [ + 80, + "struct_deconstruct>" + ], + [81, "struct_construct>"], + [ + 82, + "enum_init, 0>" + ], + [ + 83, + "store_temp>" + ], + [ + 84, + "enum_init, 1>" + ], + [85, "drop"], + [86, "store_temp"], + [87, "struct_construct>"], + [88, "enum_init, 0>"], + [89, "store_temp>"], + [90, "enum_init, 1>"], + [ + 91, + "storage_base_address_const<254972299075299712015478855430390632050936182311486400521237190787151437163>" + ], + [92, "storage_address_from_base"], + [93, "store_temp"], + [94, "storage_read_syscall"], + [ + 95, + "enum_init>, 0>" + ], + [ + 96, + "store_temp>>" + ], + [ + 97, + "enum_init>, 1>" + ], + [ + 98, + "rename>>" + ], + [ + 99, + "function_call::unwrap_syscall>" + ], + [100, "storage_write_syscall"], + [ + 101, + "enum_init>, 0>" + ], + [ + 102, + "store_temp>>" + ], + [ + 103, + "enum_init>, 1>" + ], + [ + 104, + "rename>>" + ], + [ + 105, + "function_call::unwrap_syscall>" + ], + [106, "enum_match>"], + [107, "struct_deconstruct>"], + [ + 108, + "struct_construct>" + ], + [ + 109, + "enum_init, 0>" + ], + [ + 110, + "store_temp>" + ], + [ + 111, + "enum_init, 1>" + ], + [ + 112, + "enum_match>>" + ], + [ + 113, + "enum_match>>" + ], + [114, "struct_construct>"], + [115, "enum_init, 0>"], + [116, "store_temp>"], + [117, "enum_init, 1>"] + ], + "user_func_names": [ + [0, "counter0::Counter::__external::increase_balance"], + [1, "counter0::Counter::__external::get_balance"], + [2, "core::Felt252Serde::deserialize"], + [3, "counter0::Counter::increase_balance"], + [4, "core::starknet::use_system_implicit"], + [5, "counter0::Counter::get_balance"], + [6, "core::Felt252Serde::serialize"], + [7, "counter0::Counter::balance_0::InternalContractStateImpl::read"], + [8, "counter0::Counter::balance_0::InternalContractStateImpl::write"], + [ + 9, + "core::starknet::SyscallResultTraitImpl::::unwrap_syscall" + ], + [10, "core::starknet::SyscallResultTraitImpl::<()>::unwrap_syscall"] + ] + }, + "contract_class_version": "0.1.0", + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320", + "function_idx": 0 + }, + { + "selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695", + "function_idx": 1 + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + }, + "abi": [ + { + "type": "function", + "name": "increase_balance", + "inputs": [{ "name": "amount", "type": "core::felt252" }], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_balance", + "inputs": [], + "outputs": [{ "type": "core::felt252" }], + "state_mutability": "view" + }, + { + "type": "event", + "name": "counter0::Counter::Event", + "kind": "enum", + "variants": [] + } + ] +} diff --git a/crates/client/starknet-block-import/tests/same_compiler/.tool-versions b/crates/client/starknet-block-import/tests/same_compiler/.tool-versions new file mode 100644 index 0000000000..277764a5d4 --- /dev/null +++ b/crates/client/starknet-block-import/tests/same_compiler/.tool-versions @@ -0,0 +1 @@ +scarb = 2.3.1 \ No newline at end of file diff --git a/crates/client/starknet-block-import/tests/same_compiler/compiled_contract_class.json b/crates/client/starknet-block-import/tests/same_compiler/compiled_contract_class.json new file mode 100644 index 0000000000..7834fd25a1 --- /dev/null +++ b/crates/client/starknet-block-import/tests/same_compiler/compiled_contract_class.json @@ -0,0 +1,567 @@ +{ + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "compiler_version": "2.3.1", + "bytecode": [ + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffa9e8", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x6b", + "0x4825800180007ffa", + "0x5618", + "0x400280007ff97fff", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0xe2", + "0x482680017ff98000", + "0x1", + "0x20680017fff7ffd", + "0x52", + "0x48307ffb80007ffc", + "0x4824800180007fff", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ffb7fff8000", + "0x48127fea7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x1ab", + "0x482480017fff8000", + "0x1aa", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007fe8", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff67fff", + "0x10780017fff7fff", + "0x20", + "0x4824800180007fe8", + "0x0", + "0x400080007ff77fff", + "0x48127fff7fff8000", + "0x480a7ffb7fff8000", + "0x48127ff47fff8000", + "0x1104800180018000", + "0xd7", + "0x482480017fbe8000", + "0x1", + "0x20680017fff7ffc", + "0xc", + "0x40780017fff7fff", + "0x1", + "0x48127ffe7fff8000", + "0x48127ff87fff8000", + "0x48127ff87fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127fff7fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff48000", + "0x1", + "0x48127fe37fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x400080007ffe7fff", + "0x48127ffd7fff8000", + "0x48127fec7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0xffffffffffffffffffffffffffffe2f0", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x5b", + "0x4825800180007ffa", + "0x1d10", + "0x400280007ff97fff", + "0x48297ffc80007ffd", + "0x482680017ff98000", + "0x1", + "0x4824800180007ffe", + "0x0", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ffc7fff8000", + "0x48127ff97fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x132", + "0x482480017fff8000", + "0x131", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff7", + "0x0", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff77fff", + "0x10780017fff7fff", + "0x24", + "0x4824800180007ff7", + "0x0", + "0x400080007ff87fff", + "0x48127fff7fff8000", + "0x480a7ffb7fff8000", + "0x1104800180018000", + "0x85", + "0x482480017fd88000", + "0x1", + "0x20680017fff7ffc", + "0x11", + "0x40780017fff7fff", + "0x1", + "0x48127ffd7fff8000", + "0x48127ffe7fff8000", + "0x48127ffd7fff8000", + "0x1104800180018000", + "0x8f", + "0x48127ff77fff8000", + "0x48127ff17fff8000", + "0x48127ff17fff8000", + "0x480680017fff8000", + "0x0", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x48127fff7fff8000", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ff97fff8000", + "0x48127ff97fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff58000", + "0x1", + "0x48127ff27fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0xa", + "0x482680017ffc8000", + "0x1", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480a7ffc7fff8000", + "0x10780017fff7fff", + "0x8", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x48127ffc7fff8000", + "0x48127ffc7fff8000", + "0x20680017fff7ffc", + "0x8", + "0x48127ffe7fff8000", + "0x48127ffe7fff8000", + "0x480680017fff8000", + "0x0", + "0x480080007ffa8000", + "0x208b7fff7fff7ffe", + "0x48127ffe7fff8000", + "0x48127ffe7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x480a7ffb7fff8000", + "0x480a7ffc7fff8000", + "0x1104800180018000", + "0x3e", + "0x20680017fff7ffd", + "0x19", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x48287ffd7ffd8000", + "0x1104800180018000", + "0x68", + "0x20680017fff7ffd", + "0xb", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x18", + "0x48127fe37fff8000", + "0x48127fe37fff8000", + "0x480680017fff8000", + "0x1", + "0x48127fe37fff8000", + "0x48127fe37fff8000", + "0x208b7fff7fff7ffe", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x1104800180018000", + "0x18", + "0x20680017fff7ffd", + "0xa", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x400380007ffd7ffb", + "0x480a7ffc7fff8000", + "0x482680017ffd8000", + "0x1", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x904f2833296109453ae83969e306a0ffe26d05f3d29af52bcc8fe626ac1d6b", + "0x480680017fff8000", + "0x53746f7261676552656164", + "0x400280007ffd7fff", + "0x400380017ffd7ffc", + "0x400280027ffd7ffd", + "0x400280037ffd7ffe", + "0x480280057ffd8000", + "0x20680017fff7fff", + "0xc", + "0x480280047ffd8000", + "0x482680017ffd8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480280067ffd8000", + "0x10780017fff7fff", + "0x9", + "0x480280047ffd8000", + "0x482680017ffd8000", + "0x8", + "0x480680017fff8000", + "0x1", + "0x480280067ffd8000", + "0x480280077ffd8000", + "0x1104800180018000", + "0x47", + "0x20680017fff7ffd", + "0xa", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x904f2833296109453ae83969e306a0ffe26d05f3d29af52bcc8fe626ac1d6b", + "0x480680017fff8000", + "0x53746f726167655772697465", + "0x400280007ffc7fff", + "0x400380017ffc7ffb", + "0x400280027ffc7ffd", + "0x400280037ffc7ffe", + "0x400380047ffc7ffd", + "0x480280067ffc8000", + "0x20680017fff7fff", + "0xd", + "0x480280057ffc8000", + "0x482680017ffc8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x10780017fff7fff", + "0x9", + "0x480280057ffc8000", + "0x482680017ffc8000", + "0x9", + "0x480680017fff8000", + "0x1", + "0x480280077ffc8000", + "0x480280087ffc8000", + "0x1104800180018000", + "0x21", + "0x20680017fff7ffd", + "0xb", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x48127ff67fff8000", + "0x48127ff67fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffb", + "0x8", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x1", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe", + "0x20780017fff7ffb", + "0x9", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x0", + "0x208b7fff7fff7ffe", + "0x480680017fff8000", + "0x1", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x208b7fff7fff7ffe" + ], + "hints": [ + [ + 0, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x5618" }, + "rhs": { "Deref": { "register": "FP", "offset": -6 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [25, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 44, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x0" }, + "rhs": { "Deref": { "register": "AP", "offset": -23 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [65, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [83, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [98, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [112, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 127, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x1d10" }, + "rhs": { "Deref": { "register": "FP", "offset": -6 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [146, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 165, + [ + { + "TestLessThanOrEqual": { + "lhs": { "Immediate": "0x0" }, + "rhs": { "Deref": { "register": "AP", "offset": -8 } }, + "dst": { "register": "AP", "offset": 0 } + } + } + ] + ], + [185, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [208, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [223, [{ "AllocSegment": { "dst": { "register": "AP", "offset": 0 } } }]], + [ + 348, + [ + { + "SystemCall": { + "system": { "Deref": { "register": "FP", "offset": -3 } } + } + } + ] + ], + [ + 398, + [ + { + "SystemCall": { + "system": { "Deref": { "register": "FP", "offset": -4 } } + } + } + ] + ] + ], + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320", + "offset": 0, + "builtins": ["range_check"] + }, + { + "selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695", + "offset": 127, + "builtins": ["range_check"] + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + } +} diff --git a/crates/client/starknet-block-import/tests/same_compiler/sierra_contract_class.json b/crates/client/starknet-block-import/tests/same_compiler/sierra_contract_class.json new file mode 100644 index 0000000000..804ff4b3cc --- /dev/null +++ b/crates/client/starknet-block-import/tests/same_compiler/sierra_contract_class.json @@ -0,0 +1,667 @@ +{ + "sierra_program": [ + "0x1", + "0x3", + "0x0", + "0x2", + "0x3", + "0x1", + "0xd0", + "0x30", + "0x1f", + "0x52616e6765436865636b", + "0x800000000000000100000000000000000000000000000000", + "0x537472756374", + "0x800000000000000f00000000000000000000000000000001", + "0x0", + "0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3", + "0x800000000000000f00000000000000000000000000000002", + "0x1", + "0x16a4c8d7c05909052238a862d8cc3e7975bf05a07b3a69c6b28951083a6d672", + "0x4172726179", + "0x800000000000000300000000000000000000000000000001", + "0x8", + "0x800000000000000300000000000000000000000000000003", + "0x3", + "0x4", + "0x456e756d", + "0xcc5e86243f861d2d64b08c35db21013e773ac5cf10097946fe0011304886d5", + "0x2", + "0x5", + "0x101dc0399934cc08fa0d6f6f2daead4e4a38cabeea1c743e1fc28d2d6e58e99", + "0x66656c74323532", + "0x800000000000000700000000000000000000000000000000", + "0x90d0203c41ad646d024845257a6eceb2f8b59b29ce7420dd518053d2edeedc", + "0x53746f7261676541646472657373", + "0x53746f726167654261736541646472657373", + "0x20ff6e48ce00abe39d8e3c47fe5f6934ff4ffc564f51c8cfb11f5d4989a0ccf", + "0x800000000000000f00000000000000000000000000000003", + "0xc", + "0x39438ad163ae11795c99a05436b266016a4d210a852c95f106f0e82ada3d6cd", + "0xd", + "0x426f78", + "0x800000000000000700000000000000000000000000000001", + "0x800000000000000700000000000000000000000000000003", + "0x29d7d57c04a880978e7b3689f6218e507f3be17588744b58dc17762447ad0e7", + "0xf", + "0x800000000000000700000000000000000000000000000002", + "0x10203be321c62a7bd4c060d69539c1fbe065baa9e253c74d2cc48be163e259", + "0x11", + "0x536e617073686f74", + "0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62", + "0x13", + "0x14", + "0x91b53cd7d1f331c897e86bd435418b9800d25e52836eeb1ddd77b0fbee9f21", + "0x16", + "0x12374a530a17b4b80217d0f9aae2a7d7f853a8caefde5804c2f26123bd78ada", + "0x17", + "0x4275696c74696e436f737473", + "0x53797374656d", + "0x9931c641b913035ae674b400b61a51476d506bbe8bba2ff8a6272790aba9e6", + "0x15", + "0x753332", + "0x11c6d8087e00642489f92d2821ad6ebd6532ad1a3b6d12833da6d6810391511", + "0x4761734275696c74696e", + "0x6e", + "0x7265766f6b655f61705f747261636b696e67", + "0x77697468647261775f676173", + "0x6272616e63685f616c69676e", + "0x73746f72655f74656d70", + "0x66756e6374696f6e5f63616c6c", + "0x656e756d5f6d61746368", + "0x1d", + "0x7374727563745f6465636f6e737472756374", + "0x61727261795f6c656e", + "0x736e617073686f745f74616b65", + "0x1c", + "0x64726f70", + "0x7533325f636f6e7374", + "0x72656e616d65", + "0x7533325f6571", + "0x61727261795f6e6577", + "0x66656c743235325f636f6e7374", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x61727261795f617070656e64", + "0x7374727563745f636f6e737472756374", + "0x656e756d5f696e6974", + "0x1b", + "0x1e", + "0x1a", + "0x6765745f6275696c74696e5f636f737473", + "0x19", + "0x77697468647261775f6761735f616c6c", + "0x18", + "0x4f7574206f6620676173", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x12", + "0x61727261795f736e617073686f745f706f705f66726f6e74", + "0x10", + "0x6a756d70", + "0x756e626f78", + "0x6", + "0x66656c743235325f616464", + "0x7", + "0xe", + "0x73746f726167655f626173655f616464726573735f636f6e7374", + "0x904f2833296109453ae83969e306a0ffe26d05f3d29af52bcc8fe626ac1d6b", + "0x73746f726167655f616464726573735f66726f6d5f62617365", + "0xa", + "0x73746f726167655f726561645f73797363616c6c", + "0x9", + "0x73746f726167655f77726974655f73797363616c6c", + "0x18f", + "0xffffffffffffffff", + "0x60", + "0xb", + "0x51", + "0x21", + "0x20", + "0x22", + "0x43", + "0x23", + "0x24", + "0x25", + "0x26", + "0x2a", + "0x2b", + "0x2c", + "0x2d", + "0x27", + "0x28", + "0x29", + "0x2e", + "0x3c", + "0x2f", + "0x30", + "0x31", + "0x32", + "0x33", + "0x34", + "0x35", + "0x36", + "0x37", + "0x38", + "0x39", + "0x3a", + "0x3b", + "0x3d", + "0x3e", + "0x3f", + "0x40", + "0x41", + "0x42", + "0x44", + "0x45", + "0x46", + "0x47", + "0x48", + "0x49", + "0x4a", + "0x4b", + "0x4c", + "0x4d", + "0x4e", + "0x4f", + "0x50", + "0x52", + "0x53", + "0x54", + "0x55", + "0x56", + "0x57", + "0x58", + "0x59", + "0x5a", + "0x5b", + "0x5c", + "0xc0", + "0x8a", + "0xb3", + "0xac", + "0xd5", + "0xda", + "0xe4", + "0x10c", + "0x106", + "0x122", + "0x13b", + "0x140", + "0x14b", + "0x160", + "0x5d", + "0x5e", + "0x165", + "0x5f", + "0x61", + "0x62", + "0x170", + "0x63", + "0x64", + "0x65", + "0x66", + "0x67", + "0x68", + "0x17d", + "0x69", + "0x189", + "0x6a", + "0x6b", + "0x6c", + "0x6d", + "0xce", + "0xeb", + "0x114", + "0x128", + "0x12e", + "0x151", + "0x177", + "0x183", + "0xefb", + "0xd100f080e0806050d030c080b0a0905040308080605070306050403020100", + "0x50403161916180f080c0817050d1016150f08080814050d10130812081105", + "0x240308082308220521100c08201f13081e081d050d1008081c0806051b031a", + "0x507032a08060524032908280524030f0820271308260825050d100c080605", + "0x1308320831050d100230162f13082e082d050d1008082c0806051b031c082b", + "0x508083a120e083b2a08083a05390538053736023508080c08340521101633", + "0x8083a410808440512084341080842410808400c08083f2a08083e3d08083c", + "0x1308084a0e08084a0c0808490c08083a481208470c0808460c080842054541", + "0x4a1c08084a05515008083a054f4c08083a4e08083a4d08083a08124c08124b", + "0x2a08084a0f0808420f0808402e0808425208083c0e0e083b2c08083a2c0808", + "0x422c080840541208472a080842080808425312084705124c08124b3208084a", + "0xc080856130e083b0f08083a0c0808402608083e5508083c0f0e083b2c0808", + "0x595708083c08125708124b0808084a05585708083a2908083a05125708124b", + "0x1c0808402c08083e08123d08124b3d08083a05123d08124b0c0808440c0808", + "0x125208124b2e08084a1e08083e5d08083c5c0e083b055b5a0e083b1c08083a", + "0x124b5508083a05125508124b2608084a1c08084208125208124b5208083a05", + "0x4b6308083a05126308124b05626108083a05605f12085e0808083a08125508", + "0x8125c08124b5c08083a05125c08124b05640c0e083b630808440812630812", + "0x4b5d08083a05125d08124b1e08084a1208083e5a08083c630e083b5c080844", + "0x5a08124b5a08083a05125a08124b1208084a5c08083c6308083c08125d0812", + "0xe050566080512055c5a1267130f1266120805120805056608050505650812", + "0x6808661263085a050f0866080f081305630c12660861080f05610866080e08", + "0x66085d0863055d0866081e080c051e0866080c085c050566080512051c0869", + "0x8550861052955126608260863052608660805680505660823086105572312", + "0x322a125d052a0866082a081e053208660829081c052a08660857081c050566", + "0x866080526052c08660805570505660868082305056608051205056a056612", + "0x8525012320550086608052a05520866082e2c1229052e0866082e0855052e", + "0x120852053d08660813082e05410866080f0813054c0866084e082c054e0866", + "0x6b086608054e05056608051205004d3d410f08000866084c0850054d086608", + "0x3d050566080512056f6e126d6c6a1266126b130f0e41056b0866086b084c05", + "0x57308660812085205720866086c082e057108660870084d057008660805", + "0x6a0813057877760e6608757473720f6b057508660868085505740866087108", + "0x5570505660879086c050566080512057b087a7908661278086a056a086608", + "0x871057f0866087e0870050566087d086f057e7d1266087c086e057c086608", + "0x52058308660876082e05820866086a0813058108660880087605800866087f", + "0x87b082c05056608051205858483820f088508660881085005840866087708", + "0x8608500588086608770852057a08660876082e05870866086a081305860866", + "0x58a0866080557050566086808230505660805120589887a870f0889086608", + "0x58d086608052a058c0866088b8a1229058b0866088b0855058b0866080577", + "0x866086f082e058f0866086e0813058e0866086d082c056d0866088c8d1232", + "0x78050566080512059291908f0f08920866088e085005910866081208520590", + "0x89408550594086608057305930866080557050566080c0872050566081c08", + "0x82c0597086608959612320596086608052a05950866089493122905940866", + "0x500569086608120852059a08660813082e05990866080f0813059808660897", + "0x866080557050566080e0872050566080512059b699a990f089b0866089808", + "0x86608052a059e0866089d9c1229059d0866089d0855059d0866080577059c", + "0x85c082e05a20866085a081305a1086608a0082c05a00866089e9f1232059f", + "0x56608050505a5a4a3a20f08a5086608a1085005a408660812085205a30866", + "0x80c050c0866080e085c050566080512055c5a12a6130f1266120805120805", + "0x863051c08660805680505660861086105686112660863086305630866080c", + "0x1e05570866085d081c052308660868081c050566081e0861055d1e1266081c", + "0x505660805120505a70566125723125d050f0866080f081305230866082308", + "0x5290866085526122905550866085508550555086608052605260866080557", + "0x2e0866080f0813052c08660832082c0532086608292a1232052a086608052a", + "0x54e50522e0f084e0866082c08500550086608120852055208660813082e05", + "0x3d411266124c130f0e41054c0866084c084c054c086608054e050566080512", + "0x66086a0874056a0866086b084d056b086608053d05056608051205004d12a8", + "0x86e0800057708660812085205760866083d082e050566086c0875056e6c12", + "0x7208661271087b05410866084108130571706f0e66087877760e7905780866", + "0x12660875087d057508660872087c05740866080557050566080512057308a9", + "0x87f7e127f057f08660874087e057e0866087b085505056608790823057b79", + "0x8108700505660880086f0581801266087c086e050566087d0878057d7c1266", + "0x82e0585086608410813058408660883087605830866088208710582086608", + "0x80512057a8786850f087a086608840850058708660870085205860866086f", + "0x8700852058a0866086f082e0589086608410813058808660873082c050566", + "0x58d0866080557050566080512058c8b8a890f088c086608880850058b0866", + "0x58f086608052a058e0866086d8d1229056d0866086d0855056d0866080577", + "0x8660800082e05920866084d0813059108660890082c05900866088e8f1232", + "0x7205056608051205959493920f089508660891085005940866081208520593", + "0x96122905970866089708550597086608057705960866080557050566080e08", + "0x1305690866089a082c059a086608989912320599086608052a059808660897", + "0x89e086608690850059d086608120852059c0866085c082e059b0866085a08", + "0x566080512050f08aa0e12126612080880050808660805085c059e9d9c9b0f", + "0x505ab080584055c086608130883055a08660812088205130866080e088105", + "0x883055a0866080f088205630866080c0886050c0866080585050566080512", + "0x8ac680866125c0887056108660861080e05610866085a0870055c08660863", + "0x230866085d0889055d0866081e0888051e08660868087a050566080512051c", + "0x81c087805056608051205265712082608660823088a055708660861080e05", + "0x660829088a052a08660861080e052908660855088b05550866080585050566", + "0x6108660805082e055a131266080f088d050f08660812088c05322a12083208", + "0x87b05630c5c0e66081c68610e8e051c0866085a086d056808660808085205", + "0x570866080e23128f05230866081e087c050566080512055d08ad1e08661263", + "0x86608570855052c08660813086d05320866080c0852052a0866085c082e05", + "0x566080512055008ae52086612290891052955260e66082e2c322a0f90052e", + "0x3d0866084e084d05410866080585050566084c0878054c4e12660852089205", + "0x6608550852056b08660826082e05000866084d0894054d086608413d129305", + "0x2e056e086608500896050566080512056c6a6b0e086c086608000895056a08", + "0x805120571706f0e08710866086e08950570086608550852056f0866082608", + "0x866085c082e05760866085d0896050566080e082305056608130897050566", + "0x50e08660812088c057278770e087208660876089505780866080c08520577", + "0x6608630c5c0e8e05630866080e086d050c086608080852055c08660805082e", + "0x98051c08660861087c050566080512056808af610866125a087b055a130f0e", + "0x55708660813085205230866080f082e055d0866081e0899051e0866081c08", + "0x80f082e0555086608680869050566080512052657230e08260866085d089a", + "0x8660805088805322a290e083208660855089a052a08660813085205290866", + "0x66080f089b05130866080e087e050f0866080585050e086608120812290512", + "0x568050f0866080e089d050e086608059c05056608120897055a1312085a08", + "0x5a0e66120f1308050f9f050f0866080f089e051308660813081e0513086608", + "0x52051e0866085a082e051c0866080c08a0050566080512056861630eb00c5c", + "0x86808a20505660805120505b108058405230866081c08a1055d0866085c08", + "0x2308a305230866085708a1055d086608610852051e08660863082e05570866", + "0x7c050566080512052a08b22908661226087b05260866085508a40555086608", + "0x5520866081e082e052e0866082c0899052c08660832089805320866082908", + "0x82a0869050566080512054e50520e084e0866082e089a05500866085d0852", + "0x3d410e084d0866084c089a053d0866085d085205410866081e082e054c0866", + "0x5c12660812088d055a086608056805130866080f089d050f086608059c054d", + "0x135a080513a5051308660813089e055a0866085a081e050566080c0897050c", + "0x866085d08b4055d0866080585050566080512051e1c680eb361631266120e", + "0x5b608058405550866082308b50526086608610852055708660863082e0523", + "0x5260866081c0852055708660868082e05290866081e08b705056608051205", + "0x2c0866122a08b9052a0866083208b8053208660855086705550866082908b5", + "0x85008bd0550086608525c12bc05520866082c08bb050566080512052e08ba", + "0x414c0e083d0866084e08be0541086608260852054c08660857082e054e0866", + "0x50008660857082e054d0866082e08bf050566085c0897050566080512053d", + "0x1208c1080866120508c0056a6b000e086a0866084d08be056b086608260852", + "0x8130866080f089a050f0866080e0899050e08660808089805056608051205", + "0x866085c0869055c086608125a1232055a086608052a050566080512051308", + "0xc4050566080512051208c3080866120508c205630808630866080c089a050c", + "0x56608051205130808130866080f08c6050f0866080e08c5050e0866080808", + "0x866080c08c6050c0866085c08c7055c086608125a1232055a086608052a05", + "0x54c4e4d050f2a4e4d050f050e1208054c4e4d050f2a4e4d050f6163080863", + "0x4d0e2c4e4d0ec90e120805524e4d0e0c2c4e4d0fc8053d2a122a08360e1208", + "0x1c4e4d0fcc120805554e4d0e1c4e4d0ecb0805080f120f0c12ca120805554e", + "0xcf055a085c08ce0555086308cd0e1208055d4e4d0e0c" + ], + "sierra_program_debug_info": { + "type_names": [ + [0, "RangeCheck"], + [1, "Unit"], + [2, "Tuple"], + [3, "core::panics::Panic"], + [4, "Array"], + [5, "Tuple>"], + [6, "core::panics::PanicResult::<((),)>"], + [7, "core::result::Result::<(), core::array::Array::>"], + [8, "felt252"], + [ + 9, + "core::result::Result::>" + ], + [10, "StorageAddress"], + [11, "StorageBaseAddress"], + [12, "counter0::Counter::balance_0::ContractMemberState"], + [13, "Tuple"], + [ + 14, + "core::panics::PanicResult::<(counter0::Counter::balance_0::ContractMemberState, ())>" + ], + [15, "Box"], + [16, "core::option::Option::>"], + [17, "Tuple"], + [18, "core::panics::PanicResult::<(core::felt252,)>"], + [19, "Snapshot>"], + [20, "core::array::Span::"], + [21, "Tuple>"], + [22, "counter0::Counter::ContractState"], + [23, "Tuple"], + [ + 24, + "core::panics::PanicResult::<(counter0::Counter::ContractState, ())>" + ], + [25, "BuiltinCosts"], + [26, "System"], + [ + 27, + "core::panics::PanicResult::<(core::array::Span::,)>" + ], + [28, "u32"], + [29, "core::option::Option::"], + [30, "GasBuiltin"] + ], + "libfunc_names": [ + [0, "revoke_ap_tracking"], + [1, "withdraw_gas"], + [2, "branch_align"], + [3, "store_temp>"], + [4, "function_call"], + [5, "store_temp"], + [6, "enum_match>"], + [7, "struct_deconstruct>"], + [8, "array_len"], + [9, "snapshot_take"], + [10, "drop"], + [11, "u32_const<0>"], + [12, "rename"], + [13, "store_temp"], + [14, "u32_eq"], + [15, "drop"], + [16, "array_new"], + [ + 17, + "felt252_const<7733229381460288120802334208475838166080759535023995805565484692595>" + ], + [18, "store_temp"], + [19, "array_append"], + [20, "struct_construct"], + [21, "struct_construct>>"], + [ + 22, + "enum_init,)>, 1>" + ], + [23, "store_temp"], + [24, "store_temp"], + [ + 25, + "store_temp,)>>" + ], + [26, "get_builtin_costs"], + [27, "store_temp"], + [28, "withdraw_gas_all"], + [ + 29, + "struct_construct" + ], + [30, "struct_construct"], + [31, "store_temp"], + [32, "function_call"], + [ + 33, + "enum_match>" + ], + [34, "drop>"], + [35, "snapshot_take>"], + [36, "drop>"], + [37, "struct_construct>"], + [38, "struct_construct>>"], + [ + 39, + "enum_init,)>, 0>" + ], + [40, "felt252_const<375233589013918064796019>"], + [41, "drop"], + [42, "drop>"], + [ + 43, + "felt252_const<485748461484230571791265682659113160264223489397539653310998840191492913>" + ], + [44, "snapshot_take"], + [45, "drop"], + [46, "function_call"], + [47, "enum_match>"], + [48, "struct_deconstruct>"], + [49, "snapshot_take"], + [50, "store_temp>"], + [51, "function_call"], + [52, "array_snapshot_pop_front"], + [ + 53, + "enum_init>, 0>" + ], + [54, "store_temp>>"], + [ + 55, + "store_temp>>" + ], + [56, "jump"], + [57, "struct_construct"], + [ + 58, + "enum_init>, 1>" + ], + [ + 59, + "enum_match>>" + ], + [60, "unbox"], + [61, "rename"], + [62, "enum_init, 0>"], + [63, "store_temp>"], + [64, "enum_init, 1>"], + [65, "struct_deconstruct"], + [66, "snapshot_take"], + [67, "store_temp"], + [ + 68, + "function_call" + ], + [69, "felt252_add"], + [ + 70, + "function_call" + ], + [ + 71, + "enum_match>" + ], + [ + 72, + "struct_deconstruct>" + ], + [73, "struct_construct>"], + [ + 74, + "enum_init, 0>" + ], + [ + 75, + "store_temp>" + ], + [ + 76, + "enum_init, 1>" + ], + [77, "drop"], + [78, "struct_construct>"], + [79, "enum_init, 0>"], + [80, "store_temp>"], + [81, "enum_init, 1>"], + [82, "store_temp"], + [ + 83, + "storage_base_address_const<254972299075299712015478855430390632050936182311486400521237190787151437163>" + ], + [84, "storage_address_from_base"], + [85, "store_temp"], + [86, "storage_read_syscall"], + [ + 87, + "enum_init>, 0>" + ], + [ + 88, + "store_temp>>" + ], + [ + 89, + "enum_init>, 1>" + ], + [ + 90, + "rename>>" + ], + [ + 91, + "function_call::unwrap_syscall>" + ], + [92, "storage_write_syscall"], + [ + 93, + "enum_init>, 0>" + ], + [ + 94, + "store_temp>>" + ], + [ + 95, + "enum_init>, 1>" + ], + [ + 96, + "rename>>" + ], + [ + 97, + "function_call::unwrap_syscall>" + ], + [98, "enum_match>"], + [99, "struct_deconstruct>"], + [ + 100, + "struct_construct>" + ], + [ + 101, + "enum_init, 0>" + ], + [ + 102, + "store_temp>" + ], + [ + 103, + "enum_init, 1>" + ], + [ + 104, + "enum_match>>" + ], + [ + 105, + "enum_match>>" + ], + [106, "struct_construct>"], + [107, "enum_init, 0>"], + [108, "store_temp>"], + [109, "enum_init, 1>"] + ], + "user_func_names": [ + [0, "counter0::Counter::__wrapper__increase_balance"], + [1, "counter0::Counter::__wrapper__get_balance"], + [2, "core::Felt252Serde::deserialize"], + [3, "counter0::Counter::increase_balance"], + [4, "counter0::Counter::get_balance"], + [5, "core::Felt252Serde::serialize"], + [ + 6, + "counter0::Counter::balance_0::InternalContractMemberStateImpl::read" + ], + [ + 7, + "counter0::Counter::balance_0::InternalContractMemberStateImpl::write" + ], + [ + 8, + "core::starknet::SyscallResultTraitImpl::::unwrap_syscall" + ], + [9, "core::starknet::SyscallResultTraitImpl::<()>::unwrap_syscall"] + ] + }, + "contract_class_version": "0.1.0", + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320", + "function_idx": 0 + }, + { + "selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695", + "function_idx": 1 + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + }, + "abi": [ + { + "type": "function", + "name": "increase_balance", + "inputs": [{ "name": "amount", "type": "core::felt252" }], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_balance", + "inputs": [], + "outputs": [{ "type": "core::felt252" }], + "state_mutability": "view" + }, + { + "type": "event", + "name": "counter0::Counter::Event", + "kind": "enum", + "variants": [] + } + ] +} diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 09067ea708..7fd59a8093 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -25,8 +25,10 @@ async-trait = "0.1" clap = { workspace = true, features = ["derive"] } futures = { workspace = true, features = ["thread-pool"] } log = { workspace = true } +num-bigint = { workspace = true } serde = { workspace = true } sha3 = { workspace = true } +thiserror = { workspace = true } frame-system = { workspace = true } sc-basic-authorship = { workspace = true } @@ -44,6 +46,7 @@ sc-service = { workspace = true } sc-telemetry = { workspace = true } sc-transaction-pool = { workspace = true } sc-transaction-pool-api = { workspace = true } +sp-consensus = { workspace = true } sp-consensus-aura = { workspace = true } sp-consensus-grandpa = { workspace = true } sp-core = { workspace = true } @@ -82,6 +85,7 @@ mc-l1-messages = { workspace = true } mc-mapping-sync = { workspace = true } mc-rpc = { workspace = true } mc-settlement = { workspace = true, features = ["clap"] } +mc-starknet-block-import = { workspace = true, optional = true } mc-storage = { workspace = true } pallet-starknet = { workspace = true, features = ["genesis-loader"] } pallet-starknet-runtime-api = { workspace = true } @@ -124,3 +128,7 @@ disable-transaction-fee = ["madara-runtime/disable-transaction-fee"] sharingan = [] avail = ["mc-data-availability/avail"] celestia = ["mc-data-availability/celestia"] +# Enables Sierra class verification for foreign blocks only + disabled in manual sealing mode +sn-block-import = ["dep:mc-starknet-block-import"] +# Enables Sierra class verification for both own and foreign blocks only + enabled for manual sealing mode +sn-block-import-testing = ["sn-block-import"] diff --git a/crates/node/src/import_queue.rs b/crates/node/src/import_queue.rs new file mode 100644 index 0000000000..8442065fd3 --- /dev/null +++ b/crates/node/src/import_queue.rs @@ -0,0 +1,181 @@ +//! Helpers for building the block import queue and pipeline. +//! +//! Block import queue is an implementation of the chain responsibility pattern, +//! where the very last handler is the client and each preceeding handler wraps the +//! current one forming an extra layer. +//! +//! Read more about the block import pipeline: +//! * https://docs.substrate.io/learn/transaction-lifecycle/#block-authoring-and-block-imports +//! * https://doc.deepernetwork.org/v3/advanced/block-import/ +//! * https://substrate.stackexchange.com/search?q=block+import +//! +//! In order to avoid confusion: +//! - Block import is a trait that all handlers in the queue/pipeline have to implement; +//! - Import queue is a struct that sc_service::build_network accepts as a configuration +//! parameter; +//! - Import pipeline is a helper struct that encapsulates a BlockImport used to import own +//! (authored) blocks plus optionally a link (hook) to Grandpa consensus. +//! +//! Import queue is used to import external blocks (created by other nodes), so typically it would +//! look like: +//! Aura: ImportQueueVerifier -> [Grandpa: BlockImport -> Client: BlockImport] +//! +//! For own (authored) blocks the chain looks similar (although a bit different): +//! Aura: BlockAuthoringTask -> [Grandpa: BlockImport -> Client: BlockImport] +//! +//! Read more about consensus: +//! * https://docs.substrate.io/learn/consensus/ +//! * https://substrate.stackexchange.com/questions/5918/how-can-i-make-my-node-generate-blocks-only-when-they-receive-transactions + +use std::sync::Arc; + +use madara_runtime::opaque::Block; +use sc_consensus::{BasicQueue, BoxBlockImport, BoxJustificationImport}; +use sc_consensus_aura::BuildVerifierParams; +use sc_consensus_grandpa::LinkHalf; +use sc_service::{Configuration, Error as ServiceError, TaskManager}; +use sc_telemetry::Telemetry; +use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; + +use crate::service::{BasicImportQueue, FullClient, FullSelectChain}; +use crate::starknet::MadaraBackend; + +/// The minimum period of blocks on which justifications will be +/// imported and generated. +pub const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; + +/// Grandpa link (hook) type. +/// +/// Import queue provides hooks via the Link trait that can be used to follow its progress. +type GrandpaLinkT = LinkHalf; + +/// Block import pipeline is a helper struct encapsulating the authored (own) block import and +/// optionally a link (hook) to the Grandpa block import. +pub struct BlockImportPipeline { + pub block_import: BoxBlockImport, + pub grandpa_link: Option, +} + +/// Build the import queue for default sealing given the block import. +fn build_aura_import_queue( + client: Arc, + config: &Configuration, + task_manager: &TaskManager, + telemetry: &Option, + block_import: BoxBlockImport, + justification_import: Option>, +) -> Result { + let slot_duration = sc_consensus_aura::slot_duration(&*client)?; + + let create_inherent_data_providers = move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + }; + + // We are not using `import_queue` because it requires knowledge of BlockImportT at compile time, + // although it's not necessary. + let verifier = sc_consensus_aura::build_verifier::(BuildVerifierParams { + client, + create_inherent_data_providers, + check_for_equivocation: Default::default(), + telemetry: telemetry.as_ref().map(|x| x.handle()), + compatibility_mode: sc_consensus_aura::CompatibilityMode::None, + }); + + Ok(BasicQueue::new( + verifier, + block_import, + justification_import, + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + )) +} + +/// Build a block import queue & pipeline for default sealing. +/// +/// If Starknet block import (Sierra class verification) is enabled for prod: +/// Queue (external blocks): AuraVerifier -> StarknetBlockImport -> GrandpaBlockImport -> Client +/// Pipeline (authored blocks): GrandpaBlockImport -> Client +/// +/// If Starknet block import is enabled for testing: +/// Pipeline (authored blocks): StarknetBlockImport -> GrandpaBlockImport -> Client +/// +/// Otherwise: +/// Queue (external blocks): AuraVerifier -> GrandpaBlockImport -> Client +/// Pipeline (authored blocks): GrandpaBlockImport -> Client +#[allow(unused_variables)] +pub fn build_aura_queue_grandpa_pipeline( + client: Arc, + config: &Configuration, + task_manager: &TaskManager, + telemetry: &Option, + select_chain: FullSelectChain, + madara_backend: Arc, +) -> Result<(BasicImportQueue, BlockImportPipeline), ServiceError> { + let (block_import, link) = sc_consensus_grandpa::block_import( + client.clone(), + GRANDPA_JUSTIFICATION_PERIOD, + &client as &Arc<_>, + select_chain, + telemetry.as_ref().map(|x| x.handle()), + )?; + + #[cfg(feature = "sn-block-import")] + let block_import = mc_starknet_block_import::StarknetBlockImport::new(block_import, client.clone(), madara_backend); + + let import_queue = build_aura_import_queue( + client.clone(), + config, + task_manager, + telemetry, + Box::new(block_import.clone()), + Some(Box::new(block_import.clone())), + )?; + + // We do not run Sierra class verification for own blocks, unless it's for testing purposes. + // Here we return GrandpaBlockImport which is wrapped by the outer StarknetBlockImport. + #[cfg(all(feature = "sn-block-import", not(feature = "sn-block-import-testing")))] + let block_import = block_import.unwrap(); + + let import_pipeline = BlockImportPipeline { block_import: Box::new(block_import), grandpa_link: Some(link) }; + + Ok((import_queue, import_pipeline)) +} + +/// Build a block import queue & pipeline for manual/instant sealing. +/// +/// If Starknet block import (Sierra class verification) is enabled for testing: +/// Queue (external blocks): StarknetBlockImport -> Client +/// Pipeline: StarknetBlockImport -> Client +/// +/// Otherwise: +/// Queue (external blocks): Client +/// Pipeline (authored blocks): Client +#[allow(unused_variables)] +pub fn build_manual_seal_queue_pipeline( + client: Arc, + config: &Configuration, + task_manager: &TaskManager, + madara_backend: Arc, +) -> (BasicImportQueue, BlockImportPipeline) { + #[cfg(not(feature = "sn-block-import-testing"))] + let block_import = client.clone(); + + #[cfg(feature = "sn-block-import-testing")] + let block_import = + mc_starknet_block_import::StarknetBlockImport::new(client.clone(), client.clone(), madara_backend); + + let import_queue = sc_consensus_manual_seal::import_queue( + Box::new(block_import.clone()), + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + ); + + let import_pipeline = BlockImportPipeline { block_import: Box::new(block_import), grandpa_link: None }; + + (import_queue, import_pipeline) +} diff --git a/crates/node/src/main.rs b/crates/node/src/main.rs index 58bd3ee0ae..c6a502f924 100644 --- a/crates/node/src/main.rs +++ b/crates/node/src/main.rs @@ -11,6 +11,7 @@ mod commands; mod configs; mod constants; mod genesis_block; +mod import_queue; mod rpc; mod starknet; diff --git a/crates/node/src/service.rs b/crates/node/src/service.rs index 49de5f249b..8a002378e1 100644 --- a/crates/node/src/service.rs +++ b/crates/node/src/service.rs @@ -28,11 +28,11 @@ use sc_basic_authorship::ProposerFactory; use sc_client_api::{Backend, BlockBackend, BlockchainEvents, HeaderBackend}; use sc_consensus::BasicQueue; use sc_consensus_aura::{SlotProportion, StartAuraParams}; -use sc_consensus_grandpa::{GrandpaBlockImport, SharedVoterState}; +use sc_consensus_grandpa::SharedVoterState; pub use sc_executor::NativeElseWasmExecutor; use sc_service::error::Error as ServiceError; use sc_service::{new_db_backend, Configuration, TaskManager, WarpSyncParams}; -use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker}; +use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool::FullPool; use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_api::offchain::OffchainStorage; @@ -41,6 +41,10 @@ use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use sp_offchain::STORAGE_PREFIX; use crate::genesis_block::MadaraGenesisBlockBuilder; +use crate::import_queue::{ + build_aura_queue_grandpa_pipeline, build_manual_seal_queue_pipeline, BlockImportPipeline, + GRANDPA_JUSTIFICATION_PERIOD, +}; use crate::rpc::StarknetDeps; use crate::starknet::{db_config_dir, MadaraBackend}; // Our native executor instance. @@ -67,47 +71,30 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { } pub(crate) type FullClient = sc_service::TFullClient>; -type FullBackend = sc_service::TFullBackend; -type FullSelectChain = sc_consensus::LongestChain; +pub(crate) type FullBackend = sc_service::TFullBackend; +pub(crate) type FullSelectChain = sc_consensus::LongestChain; -type BasicImportQueue = sc_consensus::DefaultImportQueue; +pub(crate) type BasicImportQueue = sc_consensus::DefaultImportQueue; type BoxBlockImport = sc_consensus::BoxBlockImport; -/// The minimum period of blocks on which justifications will be -/// imported and generated. -const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; - #[allow(clippy::type_complexity)] -pub fn new_partial( +pub fn new_partial( config: &Configuration, - build_import_queue: BIQ, + manual_sealing: bool, ) -> Result< sc_service::PartialComponents< FullClient, FullBackend, FullSelectChain, - sc_consensus::DefaultImportQueue, + BasicImportQueue, sc_transaction_pool::FullPool, - ( - BoxBlockImport, - sc_consensus_grandpa::LinkHalf, - Option, - Arc, - ), + (Arc, BlockImportPipeline, Option), >, ServiceError, > where RuntimeApi: ConstructRuntimeApi, RuntimeApi: Send + Sync + 'static, - BIQ: FnOnce( - Arc, - &Configuration, - &TaskManager, - Option, - GrandpaBlockImport, - Arc, - ) -> Result<(BasicImportQueue, BoxBlockImport), ServiceError>, { let telemetry = config .telemetry_endpoints @@ -162,24 +149,20 @@ where client.clone(), ); - let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import( - client.clone(), - GRANDPA_JUSTIFICATION_PERIOD, - &client as &Arc<_>, - select_chain.clone(), - telemetry.as_ref().map(|x| x.handle()), - )?; - let madara_backend = Arc::new(MadaraBackend::open(&config.database, &db_config_dir(config))?); - let (import_queue, block_import) = build_import_queue( - client.clone(), - config, - &task_manager, - telemetry.as_ref().map(|x| x.handle()), - grandpa_block_import, - madara_backend.clone(), - )?; + let (import_queue, import_pipeline) = if manual_sealing { + build_manual_seal_queue_pipeline(client.clone(), config, &task_manager, madara_backend.clone()) + } else { + build_aura_queue_grandpa_pipeline( + client.clone(), + config, + &task_manager, + &telemetry, + select_chain.clone(), + madara_backend.clone(), + )? + }; Ok(sc_service::PartialComponents { client, @@ -189,74 +172,10 @@ where keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, telemetry, madara_backend), + other: (madara_backend, import_pipeline, telemetry), }) } -/// Build the import queue for the template runtime (aura + grandpa). -pub fn build_aura_grandpa_import_queue( - client: Arc, - config: &Configuration, - task_manager: &TaskManager, - telemetry: Option, - grandpa_block_import: GrandpaBlockImport, - _madara_backend: Arc, -) -> Result<(BasicImportQueue, BoxBlockImport), ServiceError> -where - RuntimeApi: ConstructRuntimeApi, - RuntimeApi: Send + Sync + 'static, -{ - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - - let create_inherent_data_providers = move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - Ok((slot, timestamp)) - }; - - let import_queue = - sc_consensus_aura::import_queue::(sc_consensus_aura::ImportQueueParams { - block_import: grandpa_block_import.clone(), - justification_import: Some(Box::new(grandpa_block_import.clone())), - client, - create_inherent_data_providers, - spawner: &task_manager.spawn_essential_handle(), - registry: config.prometheus_registry(), - check_for_equivocation: Default::default(), - telemetry, - compatibility_mode: sc_consensus_aura::CompatibilityMode::None, - }) - .map_err::(Into::into)?; - - Ok((import_queue, Box::new(grandpa_block_import))) -} - -/// Build the import queue for the template runtime (manual seal). -pub fn build_manual_seal_import_queue( - client: Arc, - config: &Configuration, - task_manager: &TaskManager, - _telemetry: Option, - _grandpa_block_import: GrandpaBlockImport, - _madara_backend: Arc, -) -> Result<(BasicImportQueue, BoxBlockImport), ServiceError> -where - RuntimeApi: ConstructRuntimeApi, - RuntimeApi: Send + Sync + 'static, -{ - Ok(( - sc_consensus_manual_seal::import_queue( - Box::new(client.clone()), - &task_manager.spawn_essential_handle(), - config.prometheus_registry(), - ), - Box::new(client), - )) -} - /// Builds a new service for a full client. /// /// # Arguments @@ -268,9 +187,6 @@ pub fn new_full( da_client: Option>, settlement_config: Option<(SettlementLayer, PathBuf)>, ) -> Result { - let build_import_queue = - if sealing.is_default() { build_aura_grandpa_import_queue } else { build_manual_seal_import_queue }; - let sc_service::PartialComponents { client, backend, @@ -279,8 +195,8 @@ pub fn new_full( keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, mut telemetry, madara_backend), - } = new_partial(&config, build_import_queue)?; + other: (madara_backend, BlockImportPipeline { block_import, grandpa_link }, mut telemetry), + } = new_partial(&config, !sealing.is_default())?; let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); @@ -289,12 +205,12 @@ pub fn new_full( &config.chain_spec, ); - let warp_sync_params = if sealing.is_default() { + let warp_sync_params = if let Some(link) = &grandpa_link { net_config .add_notification_protocol(sc_consensus_grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone())); let warp_sync = Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new( backend.clone(), - grandpa_link.shared_authority_set().clone(), + link.shared_authority_set().clone(), Vec::default(), )); Some(WarpSyncParams::WithProvider(warp_sync)) @@ -338,7 +254,6 @@ pub fn new_full( let force_authoring = config.force_authoring; let backoff_authoring_blocks: Option<()> = None; let name = config.network.node_name.clone(); - let enable_grandpa = !config.disable_grandpa && sealing.is_default(); let prometheus_registry = config.prometheus_registry().cloned(); let starting_block = client.info().best_number; @@ -560,7 +475,7 @@ pub fn new_full( task_manager.spawn_essential_handle().spawn_blocking("aura", Some("block-authoring"), aura); } - if enable_grandpa { + if let Some(link) = grandpa_link { // if the node isn't actively participating in consensus then it doesn't // need a keystore, regardless of which protocol we use below. let keystore = if role.is_authority() { Some(keystore_container.keystore()) } else { None }; @@ -585,7 +500,7 @@ pub fn new_full( // could lead to finality stalls. let grandpa_config = sc_consensus_grandpa::GrandpaParams { config: grandpa_config, - link: grandpa_link, + link, network, sync: Arc::new(sync_service), voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(), @@ -708,6 +623,6 @@ type ChainOpsResult = pub fn new_chain_ops(config: &mut Configuration) -> ChainOpsResult { config.keystore = sc_service::config::KeystoreConfig::InMemory; let sc_service::PartialComponents { client, backend, import_queue, task_manager, other, .. } = - new_partial::<_>(config, build_aura_grandpa_import_queue)?; - Ok((client, backend, import_queue, task_manager, other.3)) + new_partial(config, false)?; + Ok((client, backend, import_queue, task_manager, other.0)) } diff --git a/crates/primitives/transactions/src/from_broadcasted_transactions.rs b/crates/primitives/transactions/src/from_broadcasted_transactions.rs index 65378d3b08..d6ef214ac5 100644 --- a/crates/primitives/transactions/src/from_broadcasted_transactions.rs +++ b/crates/primitives/transactions/src/from_broadcasted_transactions.rs @@ -56,8 +56,8 @@ pub enum BroadcastedTransactionConversionError { CasmContractClassConversionFailed, #[error("Compiled class hash does not match the class hash")] InvalidCompiledClassHash, - #[error("Failed to compile to Sierra")] - SierraCompilationFailed, + #[error("Failed to compile to Sierra: {0}")] + SierraCompilationFailed(#[source] StarknetSierraCompilationError), #[error("This transaction version is not supported")] UnsuportedTransactionVersion, #[error("This transaction version is invalid for this tx")] @@ -170,7 +170,7 @@ pub fn try_declare_tx_from_broadcasted_declare_tx( let abi_length = flattened_contract_class.abi.len(); let casm_contract_class = flattened_sierra_to_casm_contract_class(flattened_contract_class) - .map_err(|_| BroadcastedTransactionConversionError::SierraCompilationFailed)?; + .map_err(BroadcastedTransactionConversionError::SierraCompilationFailed)?; // ensure that the user has sign the correct class hash if get_casm_contract_class_hash(&casm_contract_class) != compiled_class_hash { return Err(BroadcastedTransactionConversionError::InvalidCompiledClassHash); @@ -221,7 +221,7 @@ pub fn try_declare_tx_from_broadcasted_declare_tx( let abi_length = flattened_contract_class.abi.len(); let casm_contract_class = flattened_sierra_to_casm_contract_class(flattened_contract_class) - .map_err(|_| BroadcastedTransactionConversionError::SierraCompilationFailed)?; + .map_err(BroadcastedTransactionConversionError::SierraCompilationFailed)?; let tx = starknet_api::transaction::DeclareTransaction::V3(starknet_api::transaction::DeclareTransactionV3 { diff --git a/starknet-rpc-test/README.md b/starknet-rpc-test/README.md new file mode 100644 index 0000000000..42006bb2e3 --- /dev/null +++ b/starknet-rpc-test/README.md @@ -0,0 +1,30 @@ +# Starknet RPC tests + +Starknet RPC rests are run against a single Madara instance (in order to reduce +the CI pipeline time). +In order to run tests locally you will need to: 0. Make sure you have all test +dependencies compiled (see next section) + +1. Build Madara binary: `cargo build --profile release` +2. Setup Madara instance (once): + `./target/release/madara setup --dev --from-local=./configs` +3. Run Madara node: `./target/release/madara --dev --sealing=manual` +4. Run tests + `cargo test --package starknet-rpc-test works_with_storage_change -- --nocapture` + +If you need to reset the state, run `./target/release/madara purge-chain --dev` + +## Generate Cairo contract artifacts + +Make sure you have the exact scarb version installed as in +`contracts/.tool-versions`. Follow the instructions: + + +It's necessary to compile the same contract several times with small +modifications so that it has different class hash. +The artifacts are used for testing the declare class operation. + +```sh +cd starknet-rpc-test/contracts +./generate_declare_contracts.sh 10 +```