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

consensus_encoding: fix bug in the composite encoder's exact size

Public commit record

What the developer wrote

Authored by Nick Johnson

73/100 · Adequate
consensus_encoding: fix bug in the composite encoder's exact size

The `ExactSizeEncoder::len` contract states that it should return the
number of bytes *remaining* in the encoder. However, the composite
encoders (e.g. `Encoder2`) return a static, total amount. This fix
only returns amounts for non-finished sub-encoders.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a bookkeeping bug in a Rust Bitcoin library's composite encoder. The encoder is a tool that combines multiple pieces of data into a single byte stream, and it has a method that is supposed to report how many bytes are left to write. The bug made this method report the total size of all pieces even after some pieces had already been written, which could mislead any code that relies on an accurate remaining-byte count. The fix makes the method only count bytes that have not yet been written.

Recommended action

Review all callers of `ExactSizeEncoder::len()` in consensus-encoding and downstream crates to determine whether the overcounting could have caused incorrect length prefixes, fee calculations, or buffer sizing. Apply the patch and run the new regression test. Consider whether this bug warrants a security advisory if any consensus-relevant serialization could be affected.

Security signals we found

01

Incorrect implementation of a documented size/length contract

02

Potential for callers to over-allocate buffers or miscompute transaction/witness sizes

03

Composite encoder used in consensus-critical serialization paths

04

No explicit memory-safety or cryptographic weakness introduced by the diff itself

Risk score

Why this scored 37/100

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