Repository navigation
Validate policy keys and hashes before compiling descriptors - #347
Olorunshogo wants to merge 2 commits 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 58.74% 58.99% +0.24%
==========================================
Files 25 25
Lines 4608 4636 +28
==========================================
+ Hits 2707 2735 +28
Misses 1901 1901
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.
bc6cd16 to
62148b0
Compare
tvpeter
left a comment
There was a problem hiding this comment.
I have left some minor comments
vadim-anfv
left a comment
There was a problem hiding this comment.
@Olorunshogo thanks for working on this!
Built the branch and ran the compile scenarios by hand: placeholders, real keys and xpubs, x-only and uncompressed keys across all four script types. Every rejection is a clean error, no crashes.
One note on the tests. check_policy_keys rejects an uncompressed key under --type tr, but no test compiles an uncompressed key for tr, so that check is never exercised - the one test that compiles for tr uses an x-only key, which Tap accepts. It would be great to add that case.
Happy to retest once it is rebased.
…ptors Reject placeholder keys by default, and return an error when a key is the wrong shape for the requested script type.
62148b0 to
51bc443
Compare
|
Addressed both comments, doc comments now sit above the gating attributes in both spots. In addition to that, I wrote a test compiling an uncompressed key under Rebased on master and ready for another look. |
Christopherdominic
left a comment
There was a problem hiding this comment.
Looks good overall. Two small documentation fixes:
- The PR description still mentions --allow-placeholders and TrInternalKey; please update it to match the current implementation.
- The comment above test_compile_rejects_uncompressed_key_for_tr says uncompressed keys are valid under wsh/sh-wsh, but both reject them too. Of the supported types, only sh accepts them.
All 11 compiler integration tests and the formatting check passed locally. No blocking issues found.
… update changelog
51bc443 to
b166c7d
Compare
|
Thanks for testing this. Both fixed:
|
1 similar comment
|
Thanks for testing this. Both fixed:
|
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. It now parses asConcrete<DescriptorPublicKey>by default, validating at parse time. The old permissive behavior moves behind--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 turns 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: FromStrKey>is generic overDescriptorPublicKey/Stringto avoid duplicating thetrbranch's NUMS-tweak internal-key math per key type.trinternal key is built withPk::from_str(&xonly_internal_key.to_string()), which works for both key types sinceFromStrKeyrequiresFromStr.--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 is a no-op forPk = String, sinceStringnever reports itself as uncompressed or x-only.test_compile_policy_beyond_legacy_limitsnow passes--placeholders.test_compile_rejects_x_only_key_for_non_tr_types,test_compile_accepts_x_only_key_for_trandtest_compile_rejects_uncompressed_key_for_trcovering the context checks.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingBugfixes: