AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 19 Bitcoin

Merge rust-bitcoin/rust-bitcoin#6812: units: Separate mathematical operation and failure mode in `NumOpError`

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6812: units: Separate mathematical operation and failure mode in `NumOpError`

eb8cbe95d92df9249e936172bdd966cdbc3b57a8 units: Replace NumOpError internals with MathErrorKind (Mitchell Bagot)
d6822db9072576dfd5f53ba5f47473f7be5b00c1 units: Remove assumption that div cannot overflow (Tobin C. Harding)

Pull request description:

This is a replacement of #6772, attempting to implement the NumOpErrorType, as suggested in https://github.com/rust-bitcoin/rust-bitcoin/pull/6772#issuecomment-5395337886.

Adjust docs, MathOp and NumOpError to remove the assumption that div cannot overflow.
Introduce NumOpErrorType to separate failure mode from attempted mathematical operation.

Original work by: Tobin C. Harding \<me@tobin.cc>

Closes #4672


ACKs for top commit:
apoelstra:
ACK eb8cbe95d92df9249e936172bdd966cdbc3b57a8; successfully ran local tests


Tree-SHA512: a312cf7ba1752e3231626aab73dfcd3e5b7f54ff6e4d6803d56a64f34f2c1ecfd44c32a5f1f3a97df82a9229d619d537f4fd6eb731d03912cdfb668b37605cb3
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This is a code-quality refactor in the rust-bitcoin library. It renames and restructures how arithmetic errors (overflow, divide-by-zero, remainder-by-zero) are reported, so callers can tell what specifically went wrong. It does not change the actual safety checks—overflows and divisions by zero were already caught before this change. The patch also fixes a minor behavior quirk where combining an error result with a valid value would overwrite the original error type; now the original error is preserved.

Recommended action

No immediate security action required. This is an API refactor. Downstream users relying on NumOpError::is_overflow() or is_div_by_zero() will need to update their code, and should verify that the new error-preservation behavior in AddAssign/SubAssign matches their expectations.

Security signals we found

01

Refactor of error reporting for checked arithmetic operations

02

Removal of public is_overflow()/is_div_by_zero() predicates on NumOpError

03

Preservation of original error kind in NumOpResult AddAssign/SubAssign

04

No change to checked_add, checked_sub, checked_mul, checked_div, checked_rem logic

05

No new unsafe code, no new dependencies, no network or serialization changes

Risk score

Why this scored 19/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 3/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.