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

common/amount: prevent scaling with invalid factors in amount scale functions

Public commit record

What the developer wrote

Authored by Chandra Pratap

73/100 · Adequate
common/amount: prevent scaling with invalid factors in amount scale functions

Changelog-Fixed: Add checks in `amount_msat_scale` and
`amount_sat_scale` to return false when the scaling factor
is -NaN or negative.

This is important as the scaling factor may come from external
sources like wire, which can cause runtime errors if not handled
properly.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit adds safety checks to two internal functions that multiply cryptocurrency amounts by a scaling factor. Previously, if the scaling factor was a malformed 'not-a-number' value or a negative number, the function could produce undefined or nonsensical results. Now the functions reject those inputs outright. The commit message says the factor can come from network data, so this is a hardening fix against bad or malicious input.

Recommended action

Review all callers of amount_msat_scale() and amount_sat_scale() to ensure they handle a false return value safely, especially code paths that parse scale factors from peer messages. Consider adding unit tests covering NaN, negative, zero, very large, and subnormal scale values.

Security signals we found

01

Input validation added to functions consuming externally supplied scaling factors

02

NaN and negative scale values now rejected instead of producing invalid double results

03

Commit message explicitly notes the scaling factor may come from the wire

04

Functions are marked WARN_UNUSED_RESULT, encouraging callers to check return value

Risk score

Why this scored 51/100

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