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

Merge rust-bitcoin/rust-bitcoin#6893: units: Reject malformed amount strings

Public commit record

What the developer wrote

Authored by Andrew Poelstra

91/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6893: units: Reject malformed amount strings

87797456b4cdb15ac25c085eb6cfb8b8e49b5a35 units: Test rejection of malformed amount strings (Jamil Lambert)
a05b597f78f5986b5381d22d6870fc7d3f0cf9f6 units: Reject malformed amount strings (Jamil Lambert)

Pull request description:

`parse_signed_to_satoshi` did not require the input to contain a digit and did not validate the position of separator underscores. As a result `.` and `._` parsed as zero, and trailing or decimal-adjacent underscores such as `1_`, `1_.0` and `1._0` parsed as ordinary amounts.

Require at least one digit and only allow underscores between two digits, matching Rust's numeric literal rules. One existing round-trip test relied on the old behaviour and is updated to a valid equivalent with the same value.

Closes project-loupe/audit-rust-bitcoin#86


ACKs for top commit:
tcharding:
ACK 87797456b4cdb15ac25c085eb6cfb8b8e49b5a35
apoelstra:
ACK 87797456b4cdb15ac25c085eb6cfb8b8e49b5a35; successfully ran local tests


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

What changed, and why it matters

This update fixes a bug in how the library reads Bitcoin amount strings like '1.5 BTC'. Previously, certain malformed inputs such as '.', '._', '1_', '1_.0', and '1._0' were incorrectly accepted and treated as valid amounts (often zero), instead of being rejected as errors. The fix now requires at least one digit and only allows underscore separators between two digits, matching Rust's numeric literal rules. This prevents silent misinterpretation of invalid amount strings.

Recommended action

Review any code that parses Bitcoin amount strings from untrusted input and ensure the updated library version is used. Validate that downstream applications do not rely on the previously accepted malformed formats. Consider adding integration tests for amount parsing at application boundaries.

Security signals we found

01

Input validation bypass in amount parser

02

Malformed strings silently parsed as zero or ordinary amounts

03

Underscore separator placement not enforced

04

Missing digit requirement in numeric parser

05

Silent misinterpretation of invalid amount strings

Risk score

Why this scored 52/100

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