Repository navigation
fix(compile): validate policy keys and hashes before compiling descriptors - #347
Open
Olorunshogo wants to merge 1 commit into
Open
Olorunshogo wants to merge 1 commit into
Olorunshogo wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
PR summary
Description
compileparsed policies asConcrete<String>, so any placeholder string (pk(ABC))or hash (
sha256(H)) was accepted as a "key" with zero validation. The command wouldsucceed and print a syntactically valid descriptor that only failed later, when a real
consumer (e.g.
bitcoin-cli deriveaddresses) tried to use it.This PR parses as
Concrete<DescriptorPublicKey>by default, so keys and hashes arevalidated at parse time. The old permissive behavior is kept behind a new
--allow-placeholdersflag, sincepk(A)-style policies are still useful forinspecting a policy's compiled shape without real keys.
Fixes #344
Notes to reviewers
sh/wsh/sh-wsh/trcompile logic (including thetrbranch's randomizedNUMS-tweak internal key) is written once, as a new generic
compile_policy<Pk>, andinstantiated with either
DescriptorPublicKeyorStringdepending on the flag.Duplicating that match per key type was the alternative, but it would have meant two
copies of the internal-key/tweak math to keep in sync.
Stringcan't get aFrom<XOnlyPublicKey>impl in this crate (orphan rules), so thetrbranch's internal-key construction goes through a small localTrInternalKeytrait implemented for both key types instead.
--allow-placeholdersonly changes how strictly the policy is parsed;--typeisuntouched (out of scope here - see Use
ValueEnumfor--typeincompilecommand #345).test_compile_policy_beyond_legacy_limitsuses placeholder keys on purpose (it onlytests script-size limits, not key validity), so it now passes
--allow-placeholders.Behavior change
compilewithout--allow-placeholdersnow rejects invalid keys and hashes at parsetime instead of silently producing an unusable descriptor:
Real keys and xpubs are unaffected.
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingBugfixes: