From 47853d822bdec8d729632f3ed5e4c15416a680a0 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Mon, 5 Aug 2024 09:17:05 +0300 Subject: [PATCH] refactor: move the panic catch into the compile sierra to casm method --- crates/gateway/src/compilation.rs | 10 +--------- crates/starknet_sierra_compile/src/compile.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) 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)?;