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

Merge bitcoin/bitcoin#35069: Refactor keypath parser

Public commit record

What the developer wrote

Authored by Ava Chow

81/100 · Strong
Merge bitcoin/bitcoin#35069: Refactor keypath parser

777aee77d12069718f7a92c5d73a87eddc3e0924 refactor: deduplicate keypath element parsing (pythcoiner)
7d8fddfba2587a1b3481c380c826324311b74900 refactor: define BIP32_HARDENED and BIP32_UNHARDENED constants (pythcoiner)

Pull request description:

The codebase used raw `0x80000000` (and implicit `0`) as the bip32 hardened / unhardened flag.

`ParseHDKeypath` and `ParseKeyPathNum` were two separate parsers for BIP32 keypath elements, #32784 aligned their rules (both accept ' and h as hardened marker and reject indexes > 0x7FFFFFFF), but the parsing logic itself was still duplicated.

This PR:
- Define `BIP32_HARDENED_FLAG` / `BIP32_UNHARDENED_FLAG` constants to replace magic `0x80000000` and `0` literals.
- Add `ParseKeyPathElement` as bip32 parsing util and use it consistantly in `ParseHDKeyPath` and the descriptor keypath parser.

ACKs for top commit:
Sjors:
ACK 777aee77d12069718f7a92c5d73a87eddc3e0924
achow101:
ACK 777aee77d12069718f7a92c5d73a87eddc3e0924

Tree-SHA512: fb096eef82bb5a90baa7de41f5562b935665ee4b64c41586cf89e06c5633be44063a35a89d01a1432c8e63222d94bd06840bafc2a837f252013e317de0f5837a
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This is a code cleanup (refactor) that replaces scattered hard-coded numbers with named constants and merges two nearly identical BIP32 key-path parsers into one shared utility. It does not add new features or fix a known security bug, but it reduces the chance of future parser inconsistencies and makes the code easier to audit. A few extra test cases were added to confirm invalid inputs are still rejected.

Recommended action

No immediate action required. Treat as routine maintenance. Reviewers may want to verify that ParseKeyPathElement preserves the exact rejection behavior of the old parsers (e.g., hardened marker only at end, numeric cap at 2^31-1) and that the new error messages do not break downstream consumers.

Security signals we found

01

Refactoring of BIP32 key-path parsing to a single shared parser

02

Replacement of magic 0x80000000 literals with named constants

03

No change to hardened-marker semantics or numeric range checks

04

Additional unit tests for invalid key-path elements

05

No vendor disclosure of a security vulnerability

Risk score

Why this scored 19/100

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