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

bugfix: Fix hint BIGINT_PACK_DIV_MOD #1189

Merged
merged 4 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#### Upcoming Changes

* 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)
* fix: Fix hint `BIGINT_PACK_DIV_MOD` [#1189](https://github.com/lambdaclass/cairo-rs/pull/1189)

* Fix possible subtraction overflow in `QUAD_BIT` & `DI_BIT` hints [#1185](https://github.com/lambdaclass/cairo-rs/pull/1185)
* fix: 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)

* fix: Fix possible subtraction overflow in `QUAD_BIT` & `DI_BIT` hints [#1185](https://github.com/lambdaclass/cairo-rs/pull/1185)

* These hints now return an error when ids.m equals zero

Expand Down
18 changes: 6 additions & 12 deletions src/hint_processor/builtin_hint_processor/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
};
use felt::Felt252;
use num_bigint::BigInt;
use num_bigint::ToBigInt;
use num_traits::{One, Signed, Zero};

use super::hint_utils::insert_value_from_var_name;
Expand All @@ -37,27 +36,22 @@ pub fn bigint_pack_div_mod_hint(
ids_data: &HashMap<String, HintReference>,
ap_tracking: &ApTracking,
) -> Result<(), HintError> {
let p: BigInt = BigInt3::from_var_name("P", vm, ids_data, ap_tracking)?
.pack86()
.to_bigint()
.unwrap_or_default();
let p: BigInt = BigInt3::from_var_name("P", vm, ids_data, ap_tracking)?.pack86();

let x: BigInt = {
let x_bigint5 = BigInt5::from_var_name("x", vm, ids_data, ap_tracking)?;
// pack only takes the first three limbs
let x_lower = BigInt3 {
d0: x_bigint5.d0,
d1: x_bigint5.d1,
d2: x_bigint5.d2,
};
let x_lower = x_lower.pack86().to_bigint().unwrap_or_default();
let d3 = x_bigint5.d3.as_ref().to_bigint();
let d4 = x_bigint5.d4.as_ref().to_bigint();
let x_lower = x_lower.pack86();
let d3 = x_bigint5.d3.as_ref().to_signed_felt();
let d4 = x_bigint5.d4.as_ref().to_signed_felt();
x_lower + d3 * BigInt::from(BASE.pow(3)) + d4 * BigInt::from(BASE.pow(4))
};
let y: BigInt = BigInt3::from_var_name("y", vm, ids_data, ap_tracking)?
.pack86()
.to_bigint()
.unwrap_or_default();
let y: BigInt = BigInt3::from_var_name("y", vm, ids_data, ap_tracking)?.pack86();

let res = div_mod(&x, &y, &p);
exec_scopes.insert_value("res", res.clone());
Expand Down
Loading