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

Merge rust-bitcoin/rust-bitcoin#6862: units: Preserve error in NumOpResult add and sub

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6862: units: Preserve error in NumOpResult add and sub

b0d240127f78cffa4cfdba72c5b85bcfcd0a0810 units: Test add and sub preserve div-by-zero error (Jamil Lambert, PhD)
0004180290e08500d3833e7289451fdf78b8049a units: Preserve error in NumOpResult add and sub (Jamil Lambert, PhD)

Pull request description:

Adding or subtracting `NumOpResults` replaced any error operand with a fresh overflow error.

Propagate the original error instead of constructing a new overflow error.

Closes project-loupe/audit-rust-bitcoin#167
Closes project-loupe/audit-rust-bitcoin#168


ACKs for top commit:
tcharding:
ACK b0d240127f78cffa4cfdba72c5b85bcfcd0a0810
Kixunil:
ACK b0d240127f78cffa4cfdba72c5b85bcfcd0a0810
apoelstra:
ACK b0d240127f78cffa4cfdba72c5b85bcfcd0a0810; successfully ran local tests


Tree-SHA512: f4f8ae1aaa011842fa0e350a43f1dff3b6fd3a944f971beeae85f6422a4b81d3e8f9c23df9c42ec870a72eeb09f13d16508eb1c977790e7b78147f702640d960
✓ 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 commit fixes a bug in how the library handles math errors. Previously, if you added or subtracted two values and one of them already had an error (for example, dividing by zero), the library would silently replace that original error with a misleading 'overflow' error. Now it correctly keeps and reports the original error. This is a defensive correctness fix: it prevents error details from being lost, which could hide the true cause of a failure in downstream software.

Recommended action

Review whether other binary operations on NumOpResult (Mul, Div, Rem, etc.) have the same error-replacement behavior and apply consistent propagation if needed. Ensure downstream callers do not rely on the previous overflow-error behavior. No urgent deployment action is required; treat as a routine correctness/security-hardening fix.

Security signals we found

01

Error-state information loss in arithmetic wrapper type

02

Incorrect error propagation could mask prior failures such as division by zero

03

Defensive correctness fix in numeric operation result handling

04

No input validation bypass or memory-safety issue present in diff

Risk score

Why this scored 49/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 10/15
Affected reach 7/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.