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

units: fix serialization of optional amounts

Public commit record

What the developer wrote

Authored by jrakibi

80/100 · Strong
units: fix serialization of optional amounts

Optional amounts do not round trip with bincode because we
directly serialize the inner value instead of `Some` variant.
Deserialization can therefore fail or return incorrect values.

Use serialize_some in as_btc::opt and as_str::opt.

Also update serde_bincode to include the two missing bytes that
encode `Some` (for unsigned_opt_as_btc and signed_opt_as_btc)
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a bug in how optional Bitcoin amounts are serialized when using the bincode format. Previously, an optional amount like `Some(1 BTC)` was written as just the raw number/string, without the marker that says "this value is present." That meant when reading it back, the code could misinterpret the data or fail. The fix uses the standard `serialize_some` method so the `Some` wrapper is preserved. The test data file was also updated to include the two missing bytes that represent `Some`.

Recommended action

Review whether any persisted bincode data produced by these helpers before the fix needs migration or re-serialization, since old payloads may deserialize incorrectly or fail. Confirm the updated test fixture covers both signed and unsigned optional amount cases. Consider auditing other optional serde helpers in the crate for the same pattern.

Security signals we found

01

Data integrity / serialization round-trip failure

02

Incorrect deserialization of optional values

03

Potential silent misinterpretation of `None` vs `Some(0)` depending on format

Risk score

Why this scored 50/100

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