From 6222bb5f071117456506688517fefb815bc332a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 17:51:26 -0300 Subject: [PATCH 01/10] Remove panics in starknet libfuncs --- src/libfuncs/starknet.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libfuncs/starknet.rs b/src/libfuncs/starknet.rs index cb2253d490..966180a6cf 100644 --- a/src/libfuncs/starknet.rs +++ b/src/libfuncs/starknet.rs @@ -145,7 +145,9 @@ pub fn build<'ctx, 'this>( } #[cfg(not(feature = "with-cheatcode"))] StarkNetConcreteLibfunc::Testing(TestingConcreteLibfunc::Cheatcode(_)) => { - unimplemented!("feature 'with-cheatcode' is required to compile with cheatcode syscall") + crate::native_panic!( + "feature 'with-cheatcode' is required to compile with cheatcode syscall" + ) } } } From 74e52df8e81dc605e184f071c33e13d07e1fc196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 17:55:16 -0300 Subject: [PATCH 02/10] Remove panics in poseidon libfuncs --- src/libfuncs/poseidon.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libfuncs/poseidon.rs b/src/libfuncs/poseidon.rs index 3dea59a098..67d6dce97d 100644 --- a/src/libfuncs/poseidon.rs +++ b/src/libfuncs/poseidon.rs @@ -3,7 +3,7 @@ use super::LibfuncHelper; use crate::{ - error::Result, + error::{panic::ToNativeAssertError, Result}, metadata::{runtime_bindings::RuntimeBindingsMeta, MetadataStorage}, utils::{get_integer_layout, BlockExt, ProgramRegistryExt}, }; @@ -50,7 +50,7 @@ pub fn build_hades_permutation<'ctx>( ) -> Result<()> { metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; let poseidon_builtin = super::increment_builtin_counter(context, entry, location, entry.arg(0)?)?; @@ -91,7 +91,7 @@ pub fn build_hades_permutation<'ctx>( let runtime_bindings = metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; runtime_bindings .libfunc_hades_permutation(context, helper, entry, op0_ptr, op1_ptr, op2_ptr, location)?; From db84c42ca6ae3ed5bca4991cd0d0d5971295e9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 17:56:23 -0300 Subject: [PATCH 03/10] Remove panics in pedersen libfuncs --- src/libfuncs/pedersen.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libfuncs/pedersen.rs b/src/libfuncs/pedersen.rs index 7e5657cca3..4c42fe98ba 100644 --- a/src/libfuncs/pedersen.rs +++ b/src/libfuncs/pedersen.rs @@ -3,7 +3,7 @@ use super::LibfuncHelper; use crate::{ - error::Result, + error::{panic::ToNativeAssertError, Result}, metadata::{runtime_bindings::RuntimeBindingsMeta, MetadataStorage}, utils::{get_integer_layout, BlockExt, ProgramRegistryExt}, }; @@ -49,7 +49,7 @@ pub fn build_pedersen<'ctx>( ) -> Result<()> { metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; let pedersen_builtin = super::increment_builtin_counter(context, entry, location, entry.arg(0)?)?; @@ -83,7 +83,7 @@ pub fn build_pedersen<'ctx>( let runtime_bindings = metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; runtime_bindings .libfunc_pedersen(context, helper, entry, dst_ptr, lhs_ptr, rhs_ptr, location)?; From 8a27e7cefe74de36f94d5080d490b4df82065eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 17:59:27 -0300 Subject: [PATCH 04/10] Remove panic in int libfuncs --- src/libfuncs/int.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libfuncs/int.rs b/src/libfuncs/int.rs index 9198769100..aefce779cb 100644 --- a/src/libfuncs/int.rs +++ b/src/libfuncs/int.rs @@ -880,8 +880,7 @@ fn build_wide_mul<'ctx, 'this>( let ext_fn = if registry .get_type(&info.signature.param_signatures[0].ty)? - .integer_range(registry) - .unwrap() + .integer_range(registry)? .lower .is_zero() { From e072f4007ae30286dad85538097fc666837617b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 18:01:21 -0300 Subject: [PATCH 05/10] Remove gas libfuncs panics --- src/libfuncs/gas.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libfuncs/gas.rs b/src/libfuncs/gas.rs index fdfc6109a3..d1132e00eb 100644 --- a/src/libfuncs/gas.rs +++ b/src/libfuncs/gas.rs @@ -2,7 +2,7 @@ use super::LibfuncHelper; use crate::{ - error::{Error, Result}, + error::{panic::ToNativeAssertError, Error, Result}, metadata::{gas::GasCost, runtime_bindings::RuntimeBindingsMeta, MetadataStorage}, native_panic, utils::{BlockExt, GepIndex}, @@ -91,7 +91,7 @@ pub fn build_withdraw_gas<'ctx, 'this>( let gas_cost = metadata .get::() - .expect("withdraw_gas should always have a gas cost") + .to_native_assert_error("withdraw_gas should always have a gas cost")? .clone(); let u64_type: melior::ir::Type = IntegerType::new(context, 64).into(); @@ -172,7 +172,7 @@ pub fn build_redeposit_gas<'ctx, 'this>( let gas_cost = metadata .get::() - .expect("redeposit_gas should always have a gas cost") + .to_native_assert_error("redeposit_gas should always have a gas cost")? .clone(); let u64_type: melior::ir::Type = IntegerType::new(context, 64).into(); @@ -247,7 +247,7 @@ pub fn build_builtin_withdraw_gas<'ctx, 'this>( let gas_cost = metadata .get::() - .expect("builtin_withdraw_gas should always have a gas cost") + .to_native_assert_error("builtin_withdraw_gas should always have a gas cost")? .clone(); let u64_type: melior::ir::Type = IntegerType::new(context, 64).into(); From ad35fe7b3a15aae4333e7c3946e841d746980abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 18:02:23 -0300 Subject: [PATCH 06/10] Remove felt252_dict panics --- src/libfuncs/felt252_dict.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libfuncs/felt252_dict.rs b/src/libfuncs/felt252_dict.rs index b13394ab26..e6f2b95d49 100644 --- a/src/libfuncs/felt252_dict.rs +++ b/src/libfuncs/felt252_dict.rs @@ -2,7 +2,7 @@ use super::LibfuncHelper; use crate::{ - error::Result, + error::{panic::ToNativeAssertError, Result}, metadata::{ felt252_dict::Felt252DictOverrides, runtime_bindings::RuntimeBindingsMeta, MetadataStorage, }, @@ -112,7 +112,7 @@ pub fn build_new<'ctx, 'this>( let runtime_bindings = metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; let dict_ptr = runtime_bindings.dict_new( context, helper, @@ -143,7 +143,7 @@ pub fn build_squash<'ctx, 'this>( let runtime_bindings = metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; let gas_refund = runtime_bindings .dict_gas_refund(context, helper, entry, dict_ptr, location)? From dbddd9267ba9fe1a70b5ab1590b6f804d18e22ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 18:04:06 -0300 Subject: [PATCH 07/10] Remove panic un enum libfuncs --- src/libfuncs/enum.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libfuncs/enum.rs b/src/libfuncs/enum.rs index 7e4fd6b70a..2a774b8354 100644 --- a/src/libfuncs/enum.rs +++ b/src/libfuncs/enum.rs @@ -145,13 +145,7 @@ pub fn build_enum_value<'ctx, 'this>( let tag_val = entry .append_operation(arith::constant( context, - IntegerAttribute::new( - tag_ty, - variant_index - .try_into() - .expect("couldnt convert index to i64"), - ) - .into(), + IntegerAttribute::new(tag_ty, variant_index.try_into()?).into(), location, )) .result(0)? @@ -425,7 +419,7 @@ pub fn build_snapshot_match<'ctx, 'this>( .get::() .ok_or(Error::MissingMetadata)? .get_variants(&info.param_signatures()[0].ty) - .expect("enum should always have variants") + .to_native_assert_error("enum should always have variants")? .clone(); match variant_ids.len() { 0 => { From 37ea8c892c5636257c6fc11530de1aa2c8032ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 18:06:16 -0300 Subject: [PATCH 08/10] Remove panic in debug libfuncs --- src/libfuncs/debug.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libfuncs/debug.rs b/src/libfuncs/debug.rs index 9a4b0cb47a..16b81a9fa7 100644 --- a/src/libfuncs/debug.rs +++ b/src/libfuncs/debug.rs @@ -11,7 +11,7 @@ use super::LibfuncHelper; use crate::{ - error::{Error, Result}, + error::{panic::ToNativeAssertError, Error, Result}, metadata::{ drop_overrides::DropOverridesMeta, runtime_bindings::RuntimeBindingsMeta, MetadataStorage, }, @@ -82,7 +82,7 @@ pub fn build_print<'ctx>( let runtime_bindings = metadata .get_mut::() - .expect("Runtime library not available."); + .to_native_assert_error("runtime library should be available")?; let values_len = entry.append_op_result(arith::subi(values_end, values_start, location))?; From 248dc94f6a0dc5781e546abc1f6d7a3662f8b108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 18:07:42 -0300 Subject: [PATCH 09/10] Remove panics in bool libfuncs --- src/libfuncs/bool.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libfuncs/bool.rs b/src/libfuncs/bool.rs index 003ed336d7..c9ca75bf39 100644 --- a/src/libfuncs/bool.rs +++ b/src/libfuncs/bool.rs @@ -2,7 +2,7 @@ use super::LibfuncHelper; use crate::{ - error::Result, + error::{panic::ToNativeAssertError, Result}, metadata::MetadataStorage, types::TypeBuilder, utils::{BlockExt, ProgramRegistryExt}, @@ -94,7 +94,7 @@ fn build_bool_binary<'ctx, 'this>( let enum_ty = registry.get_type(&info.param_signatures()[0].ty)?; let tag_bits = enum_ty .variants() - .expect("bool is a enum and has variants") + .to_native_assert_error("bool is a enum and has variants")? .len() .next_power_of_two() .trailing_zeros(); @@ -143,7 +143,7 @@ pub fn build_bool_not<'ctx, 'this>( let enum_ty = registry.get_type(&info.param_signatures()[0].ty)?; let tag_bits = enum_ty .variants() - .expect("bool is a enum and has variants") + .to_native_assert_error("bool is a enum and has variants")? .len() .next_power_of_two() .trailing_zeros(); @@ -192,7 +192,7 @@ pub fn build_bool_to_felt252<'ctx, 'this>( let tag_bits = enum_ty .variants() - .expect("bool is a enum and has variants") + .to_native_assert_error("bool is a enum and has variants")? .len() .next_power_of_two() .trailing_zeros(); From c0501ffcdcf64a318d1b6c978d72e43185c4d91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Tue, 25 Feb 2025 18:10:05 -0300 Subject: [PATCH 10/10] Remove panics in array libfuncs --- src/libfuncs/array.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libfuncs/array.rs b/src/libfuncs/array.rs index 60724afcfc..0d05df10e0 100644 --- a/src/libfuncs/array.rs +++ b/src/libfuncs/array.rs @@ -946,7 +946,7 @@ fn build_pop<'ctx, 'this, const CONSUME: bool, const REVERSE: bool>( if CONSUME { metadata .get::() - .unwrap() + .to_native_assert_error("drop overrides metadata should be available")? .invoke_override(context, error_block, location, self_ty, array_obj)?; } else { branch_values.push(array_obj); @@ -1061,7 +1061,7 @@ pub fn build_get<'ctx, 'this>( // Drop the input array. metadata .get::() - .unwrap() + .to_native_assert_error("drop overrides metadata should be available")? .invoke_override( context, valid_block, @@ -1076,7 +1076,7 @@ pub fn build_get<'ctx, 'this>( { metadata .get::() - .unwrap() + .to_native_assert_error("drop overrides metadata should be available")? .invoke_override( context, error_block, @@ -1192,7 +1192,7 @@ pub fn build_len<'ctx, 'this>( metadata .get::() - .unwrap() + .to_native_assert_error("drop overrides metadata should be available")? .invoke_override( context, entry,