Skip to content

Commit

Permalink
refactor: move the panic catch into the compile sierra to casm method
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Aug 6, 2024
1 parent 8bf1bdf commit 2007594
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 1 addition & 9 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -49,12 +46,7 @@ impl GatewayCompiler {
&self,
cairo_lang_contract_class: CairoLangContractClass,
) -> Result<CasmContractClass, GatewayError> {
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)?)
}
}

Expand Down
13 changes: 13 additions & 0 deletions crates/starknet_sierra_compile/src/compile.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,6 +20,17 @@ impl SierraToCasmCompiler {
pub fn compile(
&self,
contract_class: ContractClass,
) -> Result<CasmContractClass, CompilationUtilError> {
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<CasmContractClass, CompilationUtilError> {
contract_class.validate_version_compatible(ListSelector::DefaultList)?;

Expand Down

0 comments on commit 2007594

Please sign in to comment.