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

key: Fix PublicKey::from_slice compressed key prefix check

Public commit record

What the developer wrote

Authored by Mitchell Bagot

85/100 · Strong
key: Fix PublicKey::from_slice compressed key prefix check

Currently, PublicKey::from_slice only checks that the prefix byte for
uncompressed keys has a value of 4. Compressed keys should also be
checked to ensure that their prefix byte is either 2 or 3.
✓ Specific, 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 the library reads Bitcoin public keys from raw bytes. Previously, when a caller said the key was 'compressed', the code did not verify that the first byte was a valid compressed-key prefix (2 or 3). That meant invalid or even attacker-chosen prefix bytes could be accepted for compressed keys, while uncompressed keys were already checked. The fix now rejects any compressed key whose first byte is not 2 or 3, matching the Bitcoin protocol rules.

Recommended action

Upgrade to a version containing this commit. If upgrading is not possible, validate public-key bytes before passing them to PublicKey::from_slice, ensuring compressed keys begin with 0x02 or 0x03 and uncompressed keys begin with 0x04.

Security signals we found

01

Missing input validation on compressed public-key prefix byte

02

Protocol rule enforcement gap in cryptographic deserialization

03

Potential acceptance of malformed secp256k1 public key inputs

Risk score

Why this scored 60/100

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