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

Merge rust-bitcoin/rust-bitcoin#7001: units: fix serialization of optional amounts

Public commit record

What the developer wrote

Authored by Andrew Poelstra

91/100 · Strong
Merge rust-bitcoin/rust-bitcoin#7001: units: fix serialization of optional amounts

cfa43314a5616e920201cb1c0d40403cff27a155 units: check Optional amount round trip with bincode (jrakibi)
4b4208ceaf5396b85bfb40e6ae8730e5b0b1a19d units: fix serialization of optional amounts (jrakibi)

Pull request description:

Serializing/deserializing an optional amount using `as_btc::opt` or `as_str::opt` does not round trip with bincode.

The issue is in serialization: we directly serialize the inner value instead of `Some` variant. So deserialization can fail or return incorrect value.

The first commit fixes the issue by using `serialize_some`, and updates serde_bincode to include the two missing bytes that encode `Some` (for unsigned_opt_as_btc and signed_opt_as_btc)

The second commit adds tests.

Found while auditing `units` crate with Codex. This may already be tracked in Loupe. I don’t have access to check.


ACKs for top commit:
Abeeujah:
ACK cfa43314a5616e920201cb1c0d40403cff27a155
apoelstra:
ACK cfa43314a5616e920201cb1c0d40403cff27a155; successfully ran local tests; great catch!


Tree-SHA512: 2309b34bd20ca0dad8a9090e2da67ac5bb078eed89180f4125dc62527ee0c222a7f414015f198e9c7e69b12e8b9b7ea6c3205e98d175b65598d2a74da5eab893
✓ 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 commit fixes a bug in how optional Bitcoin amounts are serialized when using certain compact binary formats (like bincode). The code was writing the raw inner value for a Some(amount) instead of properly marking it as 'Some'. This could cause deserialization to fail or produce wrong values when round-tripping optional amounts. The fix changes the serializer to use the standard 'serialize_some' method and adds tests to confirm round-tripping now works.

Recommended action

Upgrade to a version of rust-bitcoin containing this commit if your application serializes optional Amount or SignedAmount values with bincode or other non-self-describing serde formats. Review persisted binary data produced before the fix, as it may lack the Some marker and could deserialize incorrectly with strict deserializers.

Security signals we found

01

Data integrity failure: optional amount may deserialize incorrectly or fail to round-trip in binary serde formats

02

Incorrect Option serialization omitting Some variant tag

03

Fix verified by new bincode round-trip tests

Risk score

Why this scored 48/100

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