-
Notifications
You must be signed in to change notification settings - Fork 210
fix: overflow in n_pair_bits
#1209
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
Conversation
Replace a substraction and shift-based logic by `.checked_sub` and finding the right bit to avoid a `panic`. Also fixed a bug where `m >= 253` would store the result with the wrong id for `DI_BIT` hint. Fixes #1205
2bc7808 to
7d01145
Compare
|
Benchmark Results for unmodified programs 🚀
|
Codecov Report
@@ Coverage Diff @@
## main #1209 +/- ##
=======================================
Coverage 97.59% 97.59%
=======================================
Files 89 89
Lines 36113 36159 +46
=======================================
+ Hits 35243 35289 +46
Misses 870 870
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
MegaRedHand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| let m = m_cow.as_ref().to_u32().unwrap_or(253); | ||
| if m >= 253 { | ||
| return insert_value_from_var_name("quad_bit", 0, vm, ids_data, ap_tracking); | ||
| return insert_value_from_var_name(result_name, 0, vm, ids_data, ap_tracking); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
| // ↓↓ | ||
| // 1010101__ -> 101010110 | ||
| let get_bit = | ||
| |x: &BigUint, i| m.checked_sub(i).map(|i| x.bit(i.into())).unwrap_or(false) as u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
| |x: &BigUint, i| m.checked_sub(i).map(|i| x.bit(i.into())).unwrap_or(false) as u32; | |
| |x: &BigUint, i| m.checked_sub(i).map(|j| x.bit(j.into())).unwrap_or(false) as u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your suggestion needs to change the closure parameter name too right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Both the closure and the closure inside the closure have a parameter named i. My suggestion is to rename the inner one to j to avoid variable shadowing.
* fix: overflow in `n_pair_bits` Replace a substraction and shift-based logic by `.checked_sub` and finding the right bit to avoid a `panic`. Also fixed a bug where `m >= 253` would store the result with the wrong id for `DI_BIT` hint. Fixes lambdaclass#1205 * fix changelog.md --------- Co-authored-by: Pedro Fontana <[email protected]>
Replace a substraction and shift-based logic by
.checked_subandfinding the right bit to avoid a
panic.Also fixed a bug where
m >= 253would store the result with the wrongid for
DI_BIThint.Added tests for both cases that confirm the bugs.
Fixes #1205
TITLE
Description
Description of the pull request changes and motivation.
Checklist