Repository navigation
fix(signer): match key origins by path components - #91
Closed
artofbitcoin wants to merge 1 commit into
Closed
artofbitcoin wants to merge 1 commit into
artofbitcoin wants to merge 1 commit into
Conversation
Signer::get_key decided whether a key origin covers a Bip32 key request by comparing the two derivation paths as strings. That matches on character boundaries, so an origin m/1 covered a request for m/10, and an unhardened step matched its hardened counterpart. When both paths had the same length, the signer then returned the key at the origin path for a request it did not cover. Compare the paths component by component instead, and add a test with the false positives from the issue. Fixes bitcoindevkit#90 Co-authored-by: Claude <noreply@anthropic.com>
Contributor
|
Duplicate of #81 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #90.
Signer::get_keydecided whether a key origin(fingerprint, path)covers aKeyRequest::Bip32derivation withderivation.to_string().starts_with(&path.to_string()). That compares characters rather than path components, so:m/1covered a request form/10;84h/1h/0h/1covered84h/1h/0h/10and84h/1h/0h/12/0;0covered its hardened counterpart0h.When both paths had the same length,
skip(path.len())left an empty suffix and the signer returned the key at the origin path for a request it did not cover.The check now uses
derivation.as_ref().starts_with(path.as_ref())on theChildNumberslices. A request equal to the origin path, or extending it, still matches, as covered by the existingget_key_bip32cases.Notes to the reviewers
get_key_bip32_origin_is_not_a_string_prefixbuilds a descriptor with each origin and checks that the non-covered requests returnOk(None). It fails onmasterand passes with this change.alloc::string::ToStringis no longer used in the non-test code, so its import moved to the test module.cargo test(31 passed),cargo check --no-default-features --features miniscript/no-std,cargo clippy --all-targets --all-features -- -Dwarnings,cargo fmt --all -- --check.Changelog notice
Fixed:
Signerno longer returns a key for a BIP32 request whose derivation only shares a string prefix with the key origin path.Before submitting