Skip to content

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

Open
pythcoiner wants to merge 4 commits into
bitcoin:masterfrom
pythcoiner:multipath-clone-warning
Open

pythcoiner wants to merge 4 commits into
bitcoin:masterfrom
pythcoiner:multipath-clone-warning

Conversation

@pythcoiner

Copy link
Copy Markdown
Contributor

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

DrahtBot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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.

@pythcoiner
pythcoiner force-pushed the multipath-clone-warning branch from 5c1d615 to 3628dcc Compare August 18, 2026 04:20
@pythcoiner
pythcoiner marked this pull request as ready for review August 18, 2026 04:23
pythcoiner added a commit to pythcoiner/bitcoin that referenced this pull request Aug 18, 2026
@pythcoiner
pythcoiner force-pushed the multipath-clone-warning branch from 3628dcc to cf98aaa Compare August 18, 2026 05:00
pythcoiner added a commit to pythcoiner/bitcoin that referenced this pull request Aug 18, 2026
@pythcoiner
pythcoiner force-pushed the multipath-clone-warning branch from cf98aaa to 13ef865 Compare August 18, 2026 05:02
@DrahtBot

DrahtBot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🚧 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

@jeanpablojp jeanpablojp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 13ef865

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.

Comment thread src/test/descriptor_tests.cpp Outdated
for (const auto& d : descs) {
const auto warnings = d->Warnings();
if (expect_warning) {
BOOST_REQUIRE_MESSAGE(warnings.size() == 1U, desc);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@sedited

sedited commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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

@pythcoiner

Copy link
Copy Markdown
Contributor Author

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

@pythcoiner
pythcoiner force-pushed the multipath-clone-warning branch from 13ef865 to 9367321 Compare November 5, 2026 05:55
@pythcoiner

Copy link
Copy Markdown
Contributor Author

rebased on master

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

@fametrano fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 9367321

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

importdescriptors: multipath expansion silently reuses key material across branches

5 participants