Skip to content

Commit

Permalink
Check as_int usage in hints (lambdaclass#1191)
Browse files Browse the repository at this point in the history
* Add `as_int` logic to `assert_250_bit` hint

* Remove uneeded to_signed_felt in `SIGNED_DIV_REM` hint

* Add changelog entry

* Clippy

* Update CHANGELOG.md

Co-authored-by: Tomás <47506558+MegaRedHand@users.noreply.github.com>

---------

Co-authored-by: Juan Bono <juanbono94@gmail.com>
Co-authored-by: Tomás <47506558+MegaRedHand@users.noreply.github.com>
  • Loading branch information
3 people authored and kariy committed Jun 23, 2023
1 parent 8816fcb commit b99a7f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

* fix: Handle the deserialization of serde_json::Number with scientific notation (e.g.: Number(1e27)) in felt_from_number function [#1188](https://github.com/lambdaclass/cairo-rs/pull/1188)

* fix: Fix 'as_int' conversion usage in hints `ASSERT_250_BIT` & `SIGNED_DIV_REM` [#1191](https://github.com/lambdaclass/cairo-rs/pull/1191)

* fix: Fix hint `BIGINT_PACK_DIV_MOD` [#1189](https://github.com/lambdaclass/cairo-rs/pull/1189)

* bugfix: Use cairo constants in `ASSERT_250_BIT` hint [#1187](https://github.com/lambdaclass/cairo-rs/pull/1187)

* bugfix: Fix `EC_DOUBLE_ASSIGN_NEW_X_V2` hint not taking `SECP_P` value from the current execution scope [#1186](https://github.com/lambdaclass/cairo-rs/pull/1186)
Expand Down
13 changes: 7 additions & 6 deletions src/hint_processor/builtin_hint_processor/math_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ pub fn signed_div_rem(
}

let int_value = value.to_signed_felt();
let int_div = div.to_signed_felt();
let int_bound = bound.to_signed_felt();
let int_div = div.to_bigint();
let int_bound = bound.to_bigint();
let (q, r) = int_value.div_mod_floor(&int_div);

if int_bound.abs() < q.abs() {
Expand Down Expand Up @@ -564,11 +564,12 @@ pub fn assert_250_bit(
let shift = constants
.get(SHIFT)
.map_or_else(|| get_constant_from_var_name("SHIFT", constants), Ok)?;
let value = get_integer_from_var_name("value", vm, ids_data, ap_tracking)?;
let value = Felt252::from(
get_integer_from_var_name("value", vm, ids_data, ap_tracking)?.to_signed_felt(),
);
//Main logic
//can be deleted
if value.as_ref() > upper_bound {
return Err(HintError::ValueOutside250BitRange(value.into_owned()));
if &value > upper_bound {
return Err(HintError::ValueOutside250BitRange(value));
}
let (high, low) = value.div_rem(shift);
insert_value_from_var_name("high", high, vm, ids_data, ap_tracking)?;
Expand Down

0 comments on commit b99a7f9

Please sign in to comment.