Skip to content

Commit

Permalink
Handle starknet compilation error (#2297)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan authored and wojciechos committed Dec 2, 2024
1 parent b1bca98 commit b9fe28d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions starknet/compiler/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[profile.release]
overflow-checks = true

[dependencies]
serde = "1.0.208"
serde_json = { version = "1.0.125", features = ["raw_value"] }
Expand Down
16 changes: 14 additions & 2 deletions starknet/compiler/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::casm_contract_class::{CasmContractClass, StarknetSierraCompilationError};
use std::ffi::{c_char, CStr, CString};
use std::panic::{self,AssertUnwindSafe};

#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
Expand All @@ -24,7 +25,18 @@ pub extern "C" fn compileSierraToCasm(sierra_json: *const c_char, result: *mut *
}
};

let casm_class = match CasmContractClass::from_contract_class(sierra_class, true, usize::MAX) {
let mut casm_class_result: Option<Result<CasmContractClass, StarknetSierraCompilationError>> = None;
let compilation_result = panic::catch_unwind(AssertUnwindSafe(|| {
casm_class_result = Some(CasmContractClass::from_contract_class(sierra_class, true, usize::MAX));
}));
if let Err(_) = compilation_result {
unsafe {
*result = raw_cstr("panic during compilation".to_string());
}
return 0;
}

let casm_class = match casm_class_result.unwrap() {
Ok(value) => value,
Err(e) => {
unsafe {
Expand Down

0 comments on commit b9fe28d

Please sign in to comment.