Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.

key_map: check wildcard step in DescriptorSecretKey::get_key - #1072

Closed
milah-247 wants to merge 1 commit into
rust-bitcoin:masterfrom
milah-247:fix-1068-get-key-wildcard
Closed

milah-247 wants to merge 1 commit into
rust-bitcoin:masterfrom
milah-247:fix-1068-get-key-wildcard

Conversation

@milah-247

@milah-247 milah-247 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Related to #1068.

This PR fixes an issue where get_key could return a key that didn't match the descriptor's allowed key path.

The problem was that wildcard paths weren't fully checked, so requests with the wrong hardenedness could still return a key.

I've added checks in get_key to reject unsupported paths while keeping the existing matching logic unchanged. Requests with an empty path now return None, since there is no matching key to return.

The same behavior applies to MultiXPrv keys. I also added tests covering wildcard paths, key origins, and multipath keys to make sure the issue is handled correctly.

`get_key` for a `KeyRequest::Bip32` on an extended private key relied
solely on `DescriptorXKey::matches()`, which drops the last element of
the requested path for wildcard keys without looking at it. As a result
a wildcard key would hand out keys outside its key space:

- `xprv/0/*` returned the key at `m/0/1h`
- `xprv/0/*h` returned the key at `m/0/1`
- `xprv/*` returned the master key for an empty request path

Check the wildcard step in `get_key`: return `Ok(None)` if the request
has no wildcard step, and `GetKeyError::NotSupported` if its
hardenedness does not match the descriptor's wildcard.

Fixes rust-bitcoin#1068

Assisted-by: Claude Opus 5.5
@apoelstra

Copy link
Copy Markdown
Member

who the hell are these people?

Violates LLM policy.

@apoelstra apoelstra closed this Oct 16, 2026
@milah-247

milah-247 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@apoelstra, I’m so sorry. I used an AI tool as a guide while working on this and noted it in the commit trailer, but I should have read the project’s LLM policy before opening the PR. I understand why it was closed and won’t reopen it. I’ll read the policy carefully before contributing again.

@apoelstra

Copy link
Copy Markdown
Member

For future reference -- there was another poster in this PR who was also posting slop. Github has removed those comments without a trace.

I will prioritize moving this repo off of Github.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants