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

Fix PSBT key deserialisation byte size

Public commit record

What the developer wrote

Authored by Mitchell Bagot

68/100 · Adequate
Fix PSBT key deserialisation byte size

The PSBT Key decoding makes an assumption that the key type will always
encoding in a single byte in it's compact form. While this is often
correct, this is not correct according to the spec and may fail in
cases where key type values are large.

Fix the encode and decode implementations on Key to correctly calculate
the type value size to add to the key length size.
✓ 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 bug in how Partially Signed Bitcoin Transactions (PSBTs) read and write their internal 'key' fields. The old code assumed the key's type number always fits in one byte when encoded as a compact size. That assumption is wrong for large type numbers, so the code could misread the key's length and either reject valid PSBTs or, in the worst case, allocate too much memory. The fix makes the encoder and decoder correctly account for the actual number of bytes the type number occupies.

Recommended action

Review whether the decode path can be induced to allocate an oversized vector or read out-of-bounds before the fix, and consider adding regression tests with key type values > 0xFC. Users should upgrade if they parse untrusted PSBTs.

Security signals we found

01

Incorrect length calculation in deserialization

02

Possible oversized vector allocation due to wrong size subtraction

03

Spec non-compliance with BIP-174 compact-size encoding

04

Memory allocation check bypass risk

Risk score

Why this scored 50/100

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