Skip to content

Commit 9f21705

Browse files
phrwlkgabrielbosio
andauthored
fix(vrf): use div_mod_unsigned and remove unwrap_or_default (#2262)
* fix(vrf): use div_mod_unsigned and remove unwrap_or_default * Update CHANGELOG.md --------- Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com>
1 parent b6ba12b commit 9f21705

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* fix: use div_mod_unsigned and remove unwrap_or_default in inv_mod_p_uint256 and uint384_div [#2262](https://github.com/lambdaclass/cairo-vm/pull/2262)
6+
57
* Refactor: Remove unused error variants [#1760](https://github.com/lambdaclass/cairo-vm/pull/1760/)
68

79
* opt(breaking): Avoid cloning constants when compiling hints [#2208](https://github.com/lambdaclass/cairo-vm/pull/2208)

vm/src/hint_processor/builtin_hint_processor/vrf/fq.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use crate::{
66
builtin_hint_processor::secp::bigint_utils::Uint512,
77
hint_processor_definition::HintReference,
88
},
9-
math_utils::div_mod,
9+
math_utils::div_mod_unsigned,
1010
serde::deserialize_program::ApTracking,
1111
stdlib::{collections::HashMap, prelude::*},
1212
types::errors::math_errors::MathError,
1313
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
1414
};
15-
use num_bigint::{BigInt, ToBigInt};
15+
use num_bigint::BigUint;
1616
use num_integer::div_rem;
1717
use num_traits::{One, Zero};
1818

@@ -98,19 +98,13 @@ pub fn inv_mod_p_uint256(
9898
ap_tracking: &ApTracking,
9999
) -> Result<(), HintError> {
100100
// 'a' is not used here or in following hints, so we skip it
101-
let b = Uint256::from_var_name("b", vm, ids_data, ap_tracking)?
102-
.pack()
103-
.to_bigint()
104-
.unwrap_or_default();
105-
let p = Uint256::from_var_name("p", vm, ids_data, ap_tracking)?
106-
.pack()
107-
.to_bigint()
108-
.unwrap_or_default();
101+
let b = Uint256::from_var_name("b", vm, ids_data, ap_tracking)?.pack();
102+
let p = Uint256::from_var_name("p", vm, ids_data, ap_tracking)?.pack();
109103

110104
// Main logic:
111-
let b_inverse_mod_p = div_mod(&BigInt::one(), &b, &p)?;
105+
let b_inverse_mod_p = div_mod_unsigned(&BigUint::one(), &b, &p)?;
112106

113-
let res = Uint256::from(&b_inverse_mod_p.to_biguint().unwrap_or_default());
107+
let res = Uint256::from(&b_inverse_mod_p);
114108
res.insert_from_var_name("b_inverse_mod_p", vm, ids_data, ap_tracking)
115109
}
116110

0 commit comments

Comments
 (0)