Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check as_int usage in hints #1191

Merged
merged 10 commits into from
Jun 1, 2023
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