descriptors: check duplicate keys in all multipath Miniscript branches #35742

pull yashbhutwala wants to merge 1 commits into bitcoin:master from yashbhutwala:fix/multipath-miniscript-sanity changing 2 files +38 −2
  1. yashbhutwala commented at 8:36 PM on July 17, 2026: contributor

    Fixes #35629.

    Multipath Miniscript descriptors performed duplicate-key sanity checking while parsing the template, when key comparison used the first multipath branch. As a result, duplicate keys present only in a later branch were accepted.

    Select each expanded multipath branch and rerun the existing duplicate-key check before constructing the final descriptors. If a branch contains a duplicate, report the offending concrete Miniscript expression.

    The regression test covers:

    • a valid two-branch wsh control;
    • a duplicate in the second wsh branch;
    • a duplicate in the third of three tr branches.

    Tested with:

    build/bin/test_bitcoin --run_test=descriptor_tests/multipath_miniscript_duplicate_keys
    build/bin/test_bitcoin --run_test=descriptor_tests
    build/bin/test_bitcoin
    
  2. descriptor: check duplicate keys in all multipath branches 560cfa24a8
  3. DrahtBot added the label Descriptors on Jul 17, 2026
  4. DrahtBot commented at 8:36 PM on July 17, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35742.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35918 (descriptor: Expose key expression parsing by pseudoramdom)
    • #34697 (descriptor: fix musig() duplicate key checks and doubled PSBT origin paths by shuv-amp)

    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-->

  5. yashbhutwala marked this as ready for review on Aug 2, 2026
  6. Zeegaths commented at 9:05 AM on August 4, 2026: none

    I ran this on master and on pr-35742,

    bitcoin-cli getdescriptorinfo "wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/<0;1>),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/<2;1>)))"
    

    and this is what I got:

    On master Same public key is generated

    {
      "descriptor": "wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/2)))#kzwg47ay",
      "multipath_expansion": [
        "wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/2)))#kzwg47ay",
        "wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1)))#jkt2efkp"
      ],
      "checksum": "mn7hqkkh",
      "isrange": false,
      "issolvable": true,
      "hasprivatekeys": false
    }
    

    On branch

    error code: -5
    error message:
    or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1)) is not sane: contains duplicate public keys
    

    I also checked using importdescriptors to observe wallet action.

    On master, the unsafe branch is added to the wallet:

    bitcoin-cli -rpcwallet=testwallet_master importdescriptors '[{"desc": "wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/<0;1>),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/<2;1>)))#mn7hqkkh", "timestamp": "now", "active": false}]'
    
    [
      {
        "success": true
      }
    ]
    

    On the PR:

    [
      {
        "success": false,
        "error": {
          "code": -5,
          "message": "or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1)) is not sane: contains duplicate public keys"
        }
      }
    ]
    

    This shows exactly how the PR fixes the silent passing on master


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-17 03:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me