mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 13:42:10 +02:00
b42f7fade0descriptor: don't prepend key origins twice (Shuvam Pandey)7b15e2cb44descriptor: fix duplicate check for hardened keys (Shuvam Pandey) Pull request description: Fixes #34273. Importing a descriptor that uses the same `musig()` participants twice in one tapleaf, with different musig subderivations, fails with `is not sane: contains duplicate public keys`. It only fails when one of the participants is a private key on a hardened path. The all-xpub version of the same descriptor imports fine. That's what gave it away. The duplicate check (`KeyCompare`) resolves each key expression to a pubkey and compares the results. It does this at index 0, and the old code used an empty signing provider. With that empty provider, a `musig()` expression can't resolve when one of its participants is on a hardened path, because deriving that participant needs its private key, so the whole aggregate key comes back empty. Two different musig expressions both came back empty, so the check treated them as duplicates. The fix derives against the signing provider populated during parsing, which holds the private keys, and only compares the expression strings when neither side resolves. 151henry151 had suggested looking at the empty signing provider on the issue. scgbckbone found a second, separate bug in the same descriptors. When another expression that reuses those participants is handled in the same expansion, its participant origin in the PSBT is added twice, so `m/86h/1h/0h` becomes `m/86h/1h/0h/86h/1h/0h` in both the input and output Taproot BIP32 derivation maps. `OriginPubkeyProvider::GetPubKey()` now derives into a temporary provider, merges it, and writes the corrected origin once, so a later expression can't prepend the same origin again. Tested: ``` ./build/bin/test_bitcoin --run_test=descriptor_tests ./build/bin/test_bitcoin --run_test=miniscript_tests ./build/bin/test_bitcoin --run_test=bip328_tests ./build/bin/test_bitcoin --run_test=psbt_wallet_tests ./build/test/functional/test_runner.py wallet_musig.py --jobs=1 ``` ACKs for top commit: achow101: ACKb42f7fade0scgbckbone: ACKb42f7fade0Tree-SHA512: ab36caa6bc484fa1fc3289c79e9a3d713278d82f80de478e53e1bdbe645037e07776ac798eba085733abc139c11a9dbf0d3f49d3c0eee9632e4ddf33d2242f92