diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index 7b6c683e6..4ec6690ef 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -55,8 +55,9 @@ impl GatewayCompiler { &self, cairo_lang_contract_class: CairoLangContractClass, ) -> Result { - let catch_unwind_result = - panic::catch_unwind(|| compile_sierra_to_casm(cairo_lang_contract_class)); + let catch_unwind_result = panic::catch_unwind(|| { + compile_sierra_to_casm(cairo_lang_contract_class, self.config.max_casm_bytecode_size) + }); let casm_contract_class = catch_unwind_result.map_err(|_| CompilationUtilError::CompilationPanic)??; diff --git a/crates/starknet_sierra_compile/src/compile.rs b/crates/starknet_sierra_compile/src/compile.rs index 23ac70ce3..825c2a086 100644 --- a/crates/starknet_sierra_compile/src/compile.rs +++ b/crates/starknet_sierra_compile/src/compile.rs @@ -7,27 +7,29 @@ use crate::errors::CompilationUtilError; #[cfg(test)] #[path = "compile_test.rs"] pub mod compile_test; -pub struct SierraToCasmCompilationArgs { +struct SierraToCasmCompilationArgs { list_selector: ListSelector, add_pythonic_hints: bool, - max_bytecode_size: usize, +} + +impl Default for SierraToCasmCompilationArgs { + fn default() -> Self { + Self { list_selector: ListSelector::DefaultList, add_pythonic_hints: true } + } } /// This function may panic. pub fn compile_sierra_to_casm( contract_class: ContractClass, + max_bytecode_size: usize, ) -> Result { - let compilation_args = SierraToCasmCompilationArgs { - list_selector: ListSelector::DefaultList, - add_pythonic_hints: true, - max_bytecode_size: 1000000, - }; + let compilation_args = SierraToCasmCompilationArgs::default(); contract_class.validate_version_compatible(compilation_args.list_selector)?; Ok(CasmContractClass::from_contract_class( contract_class, compilation_args.add_pythonic_hints, - compilation_args.max_bytecode_size, + max_bytecode_size, )?) } diff --git a/crates/starknet_sierra_compile/src/compile_test.rs b/crates/starknet_sierra_compile/src/compile_test.rs index 14e0b3d13..f2ed1254d 100644 --- a/crates/starknet_sierra_compile/src/compile_test.rs +++ b/crates/starknet_sierra_compile/src/compile_test.rs @@ -8,6 +8,8 @@ use mempool_test_utils::{get_absolute_path, FAULTY_ACCOUNT_CLASS_FILE, TEST_FILE use crate::compile::{compile_sierra_to_casm, CompilationUtilError}; use crate::test_utils::contract_class_from_file; +const MAX_BYTECODE_SIZE: usize = 81920; + #[test] fn test_compile_sierra_to_casm() { env::set_current_dir(get_absolute_path(TEST_FILES_FOLDER)).expect("Failed to set current dir."); @@ -15,7 +17,7 @@ fn test_compile_sierra_to_casm() { let expected_casm_contract_length = 72304; let contract_class = contract_class_from_file(sierra_path); - let casm_contract = compile_sierra_to_casm(contract_class).unwrap(); + let casm_contract = compile_sierra_to_casm(contract_class, MAX_BYTECODE_SIZE).unwrap(); let serialized_casm = serde_json::to_string_pretty(&casm_contract).unwrap().into_bytes(); assert_eq!(serialized_casm.len(), expected_casm_contract_length); @@ -31,7 +33,7 @@ fn test_negative_flow_compile_sierra_to_casm() { // Truncate the sierra program to trigger an error. contract_class.sierra_program = contract_class.sierra_program[..100].to_vec(); - let result = compile_sierra_to_casm(contract_class); + let result = compile_sierra_to_casm(contract_class, MAX_BYTECODE_SIZE); assert_matches!( result, Err(CompilationUtilError::AllowedLibfuncsError(AllowedLibfuncsError::SierraProgramError))