rpc, descriptor: warn when multipath expansion clones single-path key expressions #36005

Open
pythcoiner wants to merge 4 commits from multipath-clone-warning into master AGit
pythcoiner commented 2026-08-18 04:19:52 +00:00 (Migrated from github.com)

This PR:

  • deduplicate warnings pushed with PushWarnings in RPC calls
  • warn when single-path key expressions or tr() subscripts are cloned into every multipath expansion; surfaced by importdescriptors and by a new warnings field on getdescriptorinfo (which also exposes the existing miniscript older() warnings)

Cloning internal to musig() is not warned: both musig(A,B)/<0;1>/* and musig(A/<1;2>,B) derive a distinct aggregate key per branch, so nothing observable is reused.

closes #35985

This PR: - deduplicate warnings pushed with `PushWarnings` in RPC calls - warn when single-path key expressions or tr() subscripts are cloned into every multipath expansion; surfaced by `importdescriptors` and by a new `warnings` field on `getdescriptorinfo` (which also exposes the existing miniscript `older()` warnings) Cloning internal to musig() is not warned: both `musig(A,B)/<0;1>/*` and `musig(A/<1;2>,B)` derive a distinct aggregate key per branch, so nothing observable is reused. closes #35985
DrahtBot commented 2026-08-18 04:20:05 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK fametrano
Stale ACK jeanpablojp

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36710 (test: Replace hardcoded extended keys with ExtendedKey helpers by nebula-21)
  • #36420 (descriptor: compare x-only public keys in Tapscript Miniscript duplicate check by Yudis-bit)
  • #36402 (refactor: wallet_importdescriptors to separate run_test() contents into specific functions by nebula-21)
  • #36154 (wallet: fill PSBT_GLOBAL_XPUB by jeanpablojp)
  • #31668 (Added rescan option for import descriptors by saikiran57)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36005 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36005.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36005#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [fametrano](https://github.com/bitcoin/bitcoin/pull/36005#pullrequestreview-5817102628) | | Stale ACK | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36005#pullrequestreview-4984346283) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36885](https://github.com/bitcoin/bitcoin/pull/36885) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36885.svg"></sub> (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc) * [#36710](https://github.com/bitcoin/bitcoin/pull/36710) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36710.svg"></sub> (test: Replace hardcoded extended keys with ExtendedKey helpers by nebula-21) * [#36420](https://github.com/bitcoin/bitcoin/pull/36420) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36420.svg"></sub> (descriptor: compare x-only public keys in Tapscript Miniscript duplicate check by Yudis-bit) * [#36402](https://github.com/bitcoin/bitcoin/pull/36402) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36402.svg"></sub> (refactor: `wallet_importdescriptors` to separate `run_test()` contents into specific functions by nebula-21) * [#36154](https://github.com/bitcoin/bitcoin/pull/36154) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36154.svg"></sub> (wallet: fill PSBT_GLOBAL_XPUB by jeanpablojp) * [#31668](https://github.com/bitcoin/bitcoin/pull/31668) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31668.svg"></sub> (Added rescan option for import descriptors by saikiran57) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
DrahtBot commented 2026-08-18 06:18:58 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task previous releases: https://github.com/bitcoin/bitcoin/actions/runs/32101345101/job/95602400388
LLM reason (✨ experimental): CI failed due to a GCC 12 internal compiler error (segmentation fault) while compiling src/rpc/blockchain.cpp.

Edit: Looks like the ICE was due to a corrupt VM/hardware

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `previous releases`: https://github.com/bitcoin/bitcoin/actions/runs/32101345101/job/95602400388</sub> <sub>LLM reason (✨ experimental): CI failed due to a GCC 12 internal compiler error (segmentation fault) while compiling `src/rpc/blockchain.cpp`.</sub> Edit: Looks like the ICE was due to a corrupt VM/hardware
jeanpablojp (Migrated from github.com) reviewed 2026-08-20 15:14:04 +00:00
jeanpablojp (Migrated from github.com) left a comment

tACK 13ef865f84

Built and ran the unit tests plus rpc_getdescriptorinfo.py and wallet_importdescriptors.py. I dropped each of the four multipath_cloned = true lines one at a time and each one fails on a different descriptor in the new unit test, and reverting only the PushWarnings dedup fails both functional tests.

tACK 13ef865f84fc5d0f7073e11a6b4167b2dcd45e92 Built and ran the unit tests plus `rpc_getdescriptorinfo.py` and `wallet_importdescriptors.py`. I dropped each of the four `multipath_cloned = true` lines one at a time and each one fails on a different descriptor in the new unit test, and reverting only the `PushWarnings` dedup fails both functional tests.
jeanpablojp (Migrated from github.com) commented 2026-08-20 15:14:05 +00:00

nit: this only allows one warning. I hit both with wsh(and_v(v:pk(A/<0;1>/*),and_v(v:pk(B/0/*),older(65536)))), which nothing covers at the moment. Worth adding one?

nit: this only allows one warning. I hit both with `wsh(and_v(v:pk(A/<0;1>/*),and_v(v:pk(B/0/*),older(65536))))`, which nothing covers at the moment. Worth adding one?
DrahtBot commented 2026-09-09 16:17:17 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sedited commented 2026-10-02 12:58:37 +00:00 (Migrated from github.com)

Ping @pythcoiner this has been in need of a rebase for a while. Are you still working on this change?

Ping @pythcoiner this has been in need of a rebase for a while. Are you still working on this change?
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 93673215444a · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:0e38ad26af922abdc0fc36c9379e17efd2a72b80 --> <!-- ralph-head:93673215444ab07b64c39213c5eceb3bb979652e --> <!-- ralph-case:e3929f7de015003359632177442e21738e9e4803c31fe208eb804a9449f9ac99 --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`93673215444a`](<https://git.fish.foo/bitcoin/bitcoin/commit/93673215444ab07b64c39213c5eceb3bb979652e>) · [Full review report](<https://review.fish.foo/traces/36005-93673215444ab07b64c39213c5eceb3bb979652e-2203-2.html>) · [Previous reports](<https://review.fish.foo/traces/36005/>) [permalink](<https://review.fish.foo/traces/36005-93673215444ab07b64c39213c5eceb3bb979652e-2203-2.html>)
pythcoiner commented 2026-10-04 09:22:01 +00:00 (Migrated from github.com)

@sedited, this is still on my todo-list (but not at the top atm tbh)

@sedited, this is still on my todo-list (but not at the top atm tbh)
pythcoiner commented 2026-11-05 05:56:48 +00:00 (Migrated from github.com)

rebased on master

@jeanpablojp thanks for the review, added your descriptor to the test, and modified the check to count only expected warnings

rebased on master @jeanpablojp thanks for the review, added your descriptor to the test, and modified the check to count only expected warnings
fametrano (Migrated from github.com) reviewed 2026-11-08 07:51:26 +00:00
fametrano (Migrated from github.com) left a comment

tACK 9367321544

I compared the new warning with key reuse computed outside Core. bip32-descriptors, a library I maintain, expanded 291 multipath descriptors. They cover multi, sortedmulti, multi_a, tr() trees, miniscript and musig(), with ranged, fixed and plain single-path keys. For each expansion it collected the keys in its scripts plus the taproot internal key, at indexes 0 to 2 where the descriptor is ranged. In 272 descriptors two expansions share a key. The warning fires on 270 of them and on none of the other 19. The two it misses clone no single-path key: each shared key comes from two multipath expressions on the same xpub. deriveaddresses matches the library's addresses on all 291. importdescriptors warns exactly where getdescriptorinfo does. With the tr() internal-key flag removed, 17 more descriptors disagree, so the comparison catches a missing flag.

Gist: https://gist.github.com/fametrano/7ef458c65cf3d8c4bdab96688745b80d/1d0f3d2371525bda975201f8f987e7bdf54dcf21

tACK 93673215444ab07b64c39213c5eceb3bb979652e I compared the new warning with key reuse computed outside Core. bip32-descriptors, a library I maintain, expanded 291 multipath descriptors. They cover multi, sortedmulti, multi_a, tr() trees, miniscript and musig(), with ranged, fixed and plain single-path keys. For each expansion it collected the keys in its scripts plus the taproot internal key, at indexes 0 to 2 where the descriptor is ranged. In 272 descriptors two expansions share a key. The warning fires on 270 of them and on none of the other 19. The two it misses clone no single-path key: each shared key comes from two multipath expressions on the same xpub. `deriveaddresses` matches the library's addresses on all 291. `importdescriptors` warns exactly where `getdescriptorinfo` does. With the `tr()` internal-key flag removed, 17 more descriptors disagree, so the comparison catches a missing flag. Gist: https://gist.github.com/fametrano/7ef458c65cf3d8c4bdab96688745b80d/1d0f3d2371525bda975201f8f987e7bdf54dcf21
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36005
No description provided.