diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index 17a7b5abb7d..0baf666195c 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -1,12 +1,9 @@ -use std::panic; - use blockifier::execution::contract_class::{ClassInfo, ContractClass, ContractClassV1}; 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; use starknet_sierra_compile::compile::SierraToCasmCompiler; -use starknet_sierra_compile::errors::CompilationUtilError; use starknet_sierra_compile::utils::into_contract_class_for_compilation; use crate::errors::{GatewayError, GatewayResult}; @@ -49,12 +46,7 @@ impl GatewayCompiler { &self, cairo_lang_contract_class: CairoLangContractClass, ) -> Result { - let catch_unwind_result = - panic::catch_unwind(|| self.sierra_to_casm_compiler.compile(cairo_lang_contract_class)); - let casm_contract_class = - catch_unwind_result.map_err(|_| CompilationUtilError::CompilationPanic)??; - - Ok(casm_contract_class) + Ok(self.sierra_to_casm_compiler.compile(cairo_lang_contract_class)?) } } diff --git a/crates/starknet_sierra_compile/src/compile.rs b/crates/starknet_sierra_compile/src/compile.rs index dcc364a1ec5..b07e281e276 100644 --- a/crates/starknet_sierra_compile/src/compile.rs +++ b/crates/starknet_sierra_compile/src/compile.rs @@ -1,3 +1,5 @@ +use std::panic; + use cairo_lang_starknet_classes::allowed_libfuncs::ListSelector; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use cairo_lang_starknet_classes::contract_class::ContractClass; @@ -18,6 +20,17 @@ impl SierraToCasmCompiler { pub fn compile( &self, contract_class: ContractClass, + ) -> Result { + let catch_unwind_result = panic::catch_unwind(|| self.compile_inner(contract_class)); + let casm_contract_class = + catch_unwind_result.map_err(|_| CompilationUtilError::CompilationPanic)??; + + Ok(casm_contract_class) + } + + fn compile_inner( + &self, + contract_class: ContractClass, ) -> Result { contract_class.validate_version_compatible(ListSelector::DefaultList)?;