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 79ec169 commit bb73e86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 1 addition & 10 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,13 +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_sierra_to_casm(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_sierra_to_casm(cairo_lang_contract_class)?)
}
}

Expand Down
14 changes: 14 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,18 @@ impl SierraToCasmCompiler {
pub fn compile_sierra_to_casm(
&self,
contract_class: ContractClass,
) -> Result<CasmContractClass, CompilationUtilError> {
let catch_unwind_result =
panic::catch_unwind(|| self.compile_sierra_to_casm_inner(contract_class));
let casm_contract_class =
catch_unwind_result.map_err(|_| CompilationUtilError::CompilationPanic)??;

Ok(casm_contract_class)
}

fn compile_sierra_to_casm_inner(
&self,
contract_class: ContractClass,
) -> Result<CasmContractClass, CompilationUtilError> {
contract_class.validate_version_compatible(ListSelector::DefaultList)?;

Expand Down

0 comments on commit bb73e86

Please sign in to comment.