From 9c5eb751d289e650dac54538118b6cb330aaa538 Mon Sep 17 00:00:00 2001 From: Alon Haramati <91828241+alonh5@users.noreply.github.com> Date: Mon, 10 Jul 2023 18:45:39 +0300 Subject: [PATCH] Fix uint256_mul_div_mod bug. (#1320) --- CHANGELOG.md | 2 ++ .../builtin_hint_processor/uint256_utils.rs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2571888305..d47b2fdd6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* fix: fix `UINT256_MUL_DIV_MOD` hint [#1320](https://github.com/lambdaclass/cairo-vm/pull/1320) + * feat: add dependency installation script `install.sh` [#1298](https://github.com/lambdaclass/cairo-vm/pull/1298) * fix: specify resolver version 2 in the virtual workspace's manifest [#1311](https://github.com/lambdaclass/cairo-vm/pull/1311) diff --git a/vm/src/hint_processor/builtin_hint_processor/uint256_utils.rs b/vm/src/hint_processor/builtin_hint_processor/uint256_utils.rs index 3c4b9352cc..52238bcc24 100644 --- a/vm/src/hint_processor/builtin_hint_processor/uint256_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/uint256_utils.rs @@ -431,10 +431,10 @@ pub fn uint256_mul_div_mod( let div_high = div_high.as_ref(); // Main Logic - let a = a_high.shl(128_usize) + a_low; - let b = b_high.shl(128_usize) + b_low; - let div = div_high.shl(128_usize) + div_low; - let (quotient, remainder) = (a.to_biguint() * b.to_biguint()).div_mod_floor(&div.to_biguint()); + let a = a_high.to_biguint().shl(128_usize) + a_low.to_biguint(); + let b = b_high.to_biguint().shl(128_usize) + b_low.to_biguint(); + let div = div_high.to_biguint().shl(128_usize) + div_low.to_biguint(); + let (quotient, remainder) = (a * b).div_mod_floor(&div); // ids.quotient_low.low vm.insert_value(