diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index e1c4ea213..2eaf81017 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -1,10 +1,7 @@ use std::panic; -use std::sync::OnceLock; use blockifier::execution::contract_class::{ClassInfo, ContractClass, ContractClassV1}; -use cairo_lang_starknet_classes::casm_contract_class::{ - CasmContractClass, CasmContractEntryPoints, -}; +use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use cairo_lang_starknet_classes::contract_class::ContractClass as CairoLangContractClass; use starknet_api::core::CompiledClassHash; use starknet_api::rpc_transaction::RPCDeclareTransaction; @@ -14,7 +11,6 @@ use starknet_sierra_compile::utils::into_contract_class_for_compilation; use crate::config::GatewayCompilerConfig; use crate::errors::{GatewayError, GatewayResult}; -use crate::utils::is_subsequence; #[cfg(test)] #[path = "compilation_test.rs"] @@ -42,7 +38,6 @@ impl GatewayCompiler { let casm_contract_class = self.compile(cairo_lang_contract_class)?; validate_compiled_class_hash(&casm_contract_class, &tx.compiled_class_hash)?; - validate_casm_class(&casm_contract_class)?; Ok(ClassInfo::new( &ContractClass::V1(ContractClassV1::try_from(casm_contract_class)?), @@ -65,37 +60,6 @@ impl GatewayCompiler { } } -// TODO(Arni): Add test. -fn validate_casm_class(contract_class: &CasmContractClass) -> Result<(), GatewayError> { - let CasmContractEntryPoints { external, l1_handler, constructor } = - &contract_class.entry_points_by_type; - let entry_points_iterator = external.iter().chain(l1_handler.iter()).chain(constructor.iter()); - - for entry_point in entry_points_iterator { - let builtins = &entry_point.builtins; - if !is_subsequence(builtins, supported_builtins()) { - return Err(GatewayError::UnsupportedBuiltins { - builtins: builtins.clone(), - supported_builtins: supported_builtins().to_vec(), - }); - } - } - Ok(()) -} - -// TODO(Arni): Add to a config. -// TODO(Arni): Use the Builtin enum from Starknet-api, and explicitly tag each builtin as supported -// or unsupported so that the compiler would alert us on new builtins. -fn supported_builtins() -> &'static Vec { - static SUPPORTED_BUILTINS: OnceLock> = OnceLock::new(); - SUPPORTED_BUILTINS.get_or_init(|| { - // The OS expects this order for the builtins. - const SUPPORTED_BUILTIN_NAMES: [&str; 7] = - ["pedersen", "range_check", "ecdsa", "bitwise", "ec_op", "poseidon", "segment_arena"]; - SUPPORTED_BUILTIN_NAMES.iter().map(|builtin| builtin.to_string()).collect::>() - }) -} - /// Validates that the compiled class hash of the compiled contract class matches the supplied /// compiled class hash. fn validate_compiled_class_hash( diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index 10af93406..64040f64e 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -17,10 +17,6 @@ use starknet_mempool_types::mempool_types::ThinTransaction; use crate::errors::StatefulTransactionValidatorResult; -#[cfg(test)] -#[path = "utils_test.rs"] -mod utils_test; - macro_rules! implement_ref_getters { ($(($member_name:ident, $member_type:ty));* $(;)?) => { $(fn $member_name(&self) -> &$member_type { @@ -160,20 +156,3 @@ pub fn get_tx_hash(tx: &AccountTransaction) -> TransactionHash { AccountTransaction::Invoke(tx) => tx.tx_hash, } } - -/// Checks whether 'subsequence' is a subsequence of 'sequence'. -pub fn is_subsequence(subsequence: &[T], sequence: &[T]) -> bool { - let mut offset = 0; - - for item in sequence { - if offset == subsequence.len() { - return true; - } - - if item == &subsequence[offset] { - offset += 1; - } - } - - offset == subsequence.len() -} diff --git a/crates/gateway/src/utils_test.rs b/crates/gateway/src/utils_test.rs deleted file mode 100644 index 7b9d2fdb9..000000000 --- a/crates/gateway/src/utils_test.rs +++ /dev/null @@ -1,78 +0,0 @@ -use pretty_assertions::assert_eq; -use rstest::rstest; - -use crate::utils::is_subsequence; - -#[rstest] -#[case::empty( - &[], - &[], - true -)] -#[case::empty_subsequence( - &[], - &["a", "b"], - true -)] -#[case::empty_sequence( - &["a"], - &[], - false -)] -#[case::subsequence_1( - &["a"], - &["a", "b", "c"], - true -)] -#[case::subsequence_2( - &["b"], - &["a", "b", "c"], - true -)] -#[case::subsequence_3( - &["c"], - &["a", "b", "c"], - true -)] -#[case::subsequence_4( - &["a", "b"], - &["a", "b", "c"], - true -)] -#[case::subsequence_5( - &["a", "c"], - &["a", "b", "c"], - true -)] -#[case::subsequence_6( - &["b", "c"], - &["a", "b", "c"], - true -)] -#[case::subsequence_7( - &["a", "b", "c"], - &["a", "b", "c"], - true -)] -#[case::out_of_order_1( - &["b", "a"], - &["a", "b", "c"], - false -)] -#[case::out_of_order_2( - &["b", "a", "c"], - &["a", "b", "c"], - false -)] -#[case::unrelated( - &["a", "b", "d"], - &["a", "b", "c"], - false -)] -fn test_is_subsequence( - #[case] subsequence: &[&str], - #[case] sequence: &[&str], - #[case] expected_result: bool, -) { - assert_eq!(is_subsequence(subsequence, sequence), expected_result); -}