Skip to content

Commit ef82ee0

Browse files
fmolettakariy
authored andcommitted
bugfix: Fix hint BIGINT_PACK_DIV_MOD (lambdaclass#1189)
* Use `to_signed_felt` instead of `to_bigint` * fmt * Add changelog entry
1 parent 9a81422 commit ef82ee0

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#### Upcoming Changes
44

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

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

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

src/hint_processor/builtin_hint_processor/bigint.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::{
1414
};
1515
use felt::Felt252;
1616
use num_bigint::BigInt;
17-
use num_bigint::ToBigInt;
1817
use num_traits::{One, Signed, Zero};
1918

2019
use super::hint_utils::insert_value_from_var_name;
@@ -37,27 +36,22 @@ pub fn bigint_pack_div_mod_hint(
3736
ids_data: &HashMap<String, HintReference>,
3837
ap_tracking: &ApTracking,
3938
) -> Result<(), HintError> {
40-
let p: BigInt = BigInt3::from_var_name("P", vm, ids_data, ap_tracking)?
41-
.pack86()
42-
.to_bigint()
43-
.unwrap_or_default();
39+
let p: BigInt = BigInt3::from_var_name("P", vm, ids_data, ap_tracking)?.pack86();
4440

4541
let x: BigInt = {
4642
let x_bigint5 = BigInt5::from_var_name("x", vm, ids_data, ap_tracking)?;
43+
// pack only takes the first three limbs
4744
let x_lower = BigInt3 {
4845
d0: x_bigint5.d0,
4946
d1: x_bigint5.d1,
5047
d2: x_bigint5.d2,
5148
};
52-
let x_lower = x_lower.pack86().to_bigint().unwrap_or_default();
53-
let d3 = x_bigint5.d3.as_ref().to_bigint();
54-
let d4 = x_bigint5.d4.as_ref().to_bigint();
49+
let x_lower = x_lower.pack86();
50+
let d3 = x_bigint5.d3.as_ref().to_signed_felt();
51+
let d4 = x_bigint5.d4.as_ref().to_signed_felt();
5552
x_lower + d3 * BigInt::from(BASE.pow(3)) + d4 * BigInt::from(BASE.pow(4))
5653
};
57-
let y: BigInt = BigInt3::from_var_name("y", vm, ids_data, ap_tracking)?
58-
.pack86()
59-
.to_bigint()
60-
.unwrap_or_default();
54+
let y: BigInt = BigInt3::from_var_name("y", vm, ids_data, ap_tracking)?.pack86();
6155

6256
let res = div_mod(&x, &y, &p);
6357
exec_scopes.insert_value("res", res.clone());

0 commit comments

Comments
 (0)