From 6abd6e0b59632cc5bf5563613e2929db745960a8 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 3 Jan 2025 14:59:21 -0300 Subject: [PATCH] better check in bounded int trim --- src/libfuncs/bounded_int.rs | 5 +++-- src/types.rs | 25 ------------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/libfuncs/bounded_int.rs b/src/libfuncs/bounded_int.rs index a240310b5..7a652d215 100644 --- a/src/libfuncs/bounded_int.rs +++ b/src/libfuncs/bounded_int.rs @@ -728,14 +728,14 @@ fn build_trim<'ctx, 'this>( value.r#type(), )?; let trim_type = registry.get_type(&info.param_signatures()[0].ty)?; - let is_invalid = entry.cmpi(context, CmpiPredicate::Eq, value, trimmed_value, location)?; + let int_range = trim_type.integer_range(registry)?; // There is no need to truncate the value type since we're only receiving power-of-two integers // and constraining their range a single value from either the lower or upper limit. However, // since we're returning a `BoundedInt` we need to offset its internal representation // accordingly. - let value = if info.trimmed_value == BigInt::ZERO || trim_type.is_signed(registry)? { + let value = if info.trimmed_value == BigInt::ZERO || int_range.lower < BigInt::ZERO { let offset = entry.const_int_from_type( context, location, @@ -748,6 +748,7 @@ fn build_trim<'ctx, 'this>( }; entry.append_operation(helper.cond_br(context, is_invalid, [0, 1], [&[], &[value]], location)); + Ok(()) } diff --git a/src/types.rs b/src/types.rs index 8f94d3e5b..8c0f0a0ca 100644 --- a/src/types.rs +++ b/src/types.rs @@ -123,13 +123,6 @@ pub trait TypeBuilder { registry: &ProgramRegistry, ) -> Result; - /// Return whether the type is signed, either directly or indirectly (ex. through - /// `Const`). - fn is_signed( - &self, - registry: &ProgramRegistry, - ) -> Result; - /// Return whether the type is a `felt252`, either directly or indirectly (ex. through /// `NonZero>`). fn is_felt252( @@ -889,24 +882,6 @@ impl TypeBuilder for CoreTypeConcrete { }) } - fn is_signed( - &self, - registry: &ProgramRegistry, - ) -> Result { - Ok(match self { - CoreTypeConcrete::Sint8(_) - | CoreTypeConcrete::Sint16(_) - | CoreTypeConcrete::Sint32(_) - | CoreTypeConcrete::Sint64(_) - | CoreTypeConcrete::Sint128(_) => true, - CoreTypeConcrete::Const(info) => { - let inner_ty = registry.get_type(&info.inner_ty)?; - inner_ty.is_signed(registry)? - } - _ => false, - }) - } - fn is_felt252( &self, registry: &ProgramRegistry,