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

primitives: Implement ExactSizeEncoder for WitnessEncoder

Public commit record

What the developer wrote

Authored by awn

83/100 · Strong
primitives: Implement ExactSizeEncoder for WitnessEncoder

WitnessEncoder wraps Encoder2<CompactSizeEncoder, BytesEncoder>. Both inner
encoders implement ExactSizeEncoder, but WitnessEncoder only manually
implemented Encoder and was therefore missing an ExactSizeEncoder impl for
no reason.

The manual struct definition and Encoder impl is replaced with the
encoder_newtype_exact! macro, consistent with the other encoder newtypes in
the codebase. This adds the missing ExactSizeEncoder implementation.

Also add a test asserting that the encoder's reported length matches the
actual encoded length, including the CompactSize one-byte boundary for both
element length and element count.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit adds a missing 'ExactSizeEncoder' implementation for the WitnessEncoder in the rust-bitcoin library. Previously, WitnessEncoder only implemented the basic Encoder trait, even though the underlying encoders already supported exact-size reporting. The change uses an existing macro to automatically provide the exact-size capability and adds tests to verify the reported length matches the actual encoded bytes. There is no direct security vulnerability being fixed; it is a correctness and API-completeness improvement.

Recommended action

No urgent security action required. Treat as a normal library correctness update. Consumers using ExactSizeEncoder with WitnessEncoder can now rely on precise length reporting; consider updating if they previously worked around the missing impl.

Security signals we found

01

Missing trait implementation could have caused callers relying on ExactSizeEncoder to use fallback length estimation or fail to compile

02

No memory safety issue, no input validation bypass, no cryptographic weakness evident in diff

03

Change is API-completeness/correctness rather than a vulnerability patch

Risk score

Why this scored 18/100

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