Repository navigation
Validate policy keys and hashes before compiling descriptors - #347
Olorunshogo wants to merge 1 commit into
Conversation
|
Concept ACK a139efc Also, a |
|
Thanks for catching this, Jennycj. Confirmed and reproduced it exactly as you described: an x-only key compiled with Root cause: the current validation checks that a key parses as a valid Implemented your suggestion: added a I alsoAdded two regression tests ( |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #347 +/- ##
==========================================
+ Coverage 61.46% 61.77% +0.30%
==========================================
Files 23 23
Lines 3989 4021 +32
==========================================
+ Hits 2452 2484 +32
Misses 1537 1537
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tvpeter
left a comment
There was a problem hiding this comment.
Hello @Olorunshogo , thank you for working on this.
In addition to the comments, you should squash all the commits into probably just two. You should aim for a clean rebase each time you have to get changes from master. Having merge branch ... will pollute the git history.
…ptors Reject placeholder keys by default, and return an error when a key is the wrong shape for the requested script type.
bc6cd16 to
62148b0
Compare
PR summary
Description
compileparsed policies asConcrete<String>, so placeholder strings (pk(ABC)) or hashes were accepted as "keys" with no validation, failing only later when a real consumer used the descriptor. Now parses asConcrete<DescriptorPublicKey>by default, validating at parse time; the old permissive behavior moves behind--allow-placeholdersfor inspecting a policy's compiled shape without real keys.A key can pass that parse-time check and still be the wrong shape for the chosen script type (e.g. an x-only key under
wsh), which miniscript's compiler turned into a panic instead of an error.compilenow validates every key against the chosen script context (Legacy/Segwitv0/Tap) before compiling, so this returns a cleanInvalid policyerror instead of crashing.Fixes #344
Notes to reviewers
compile_policy<Pk>is generic overDescriptorPublicKey/Stringto avoid duplicating thetrbranch's NUMS-tweak internal-key math per key type.Stringcan't implFrom<XOnlyPublicKey>here (orphan rules), sotr's internal-key construction goes through a localTrInternalKeytrait.--typenow usesValueEnum(ScriptType) instead of a raw string withvalue_parser, so this PR also closes UseValueEnumfor--typeincompilecommand #345.check_policy_keyswalks the policy viaForEachKey::for_each_keyand callsScriptContext::check_pkper key; it's a no-op forPk = StringsinceStringnever reports itself as uncompressed or x-only.test_compile_policy_beyond_legacy_limitsnow passes--allow-placeholders.test_compile_rejects_x_only_key_for_non_tr_typesandtest_compile_accepts_x_only_key_for_trcovering the panic fix.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingBugfixes: