Fix overflow bug in Currency.MulWithOverflow#420
Conversation
dace2bd to
e94a834
Compare
There was a problem hiding this comment.
Claude Code Review
Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
Pull request overview
Fixes incorrect overflow detection/handling in Currency.MulWithOverflow, preventing silent wraparound (and incorrect results) for certain 129-bit products.
Changes:
- Corrected the 128-bit multiplication carry handling so the “middle-word” carry is counted as overflow rather than folded into the result.
- Added a targeted regression test case for the 129-bit product scenario.
- Added a changeset documenting the patch-level fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| types/currency.go | Fixes MulWithOverflow carry propagation to correctly report overflow and preserve low 128-bit result. |
| types/types_test.go | Adds a regression vector and a randomized stress test around MulWithOverflow. |
| .changeset/fix_overflow_bug_in_currencymulwithoverflow.md | Records the change as a patch-level update via changeset metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR fixes an overflow bug in
Currency.MulWithOverflow. It was passing the carry from the first high-word add into the second add instead of counting it as overflow, so when that carry hit and the second one didn’t, it reported no overflow on a 129-bit product and returned a result off by 2^64. Net effect: Mul would silently wrap instead of panicking.