BIP395: Unspendable Internal Keys for Wallet Policies #2340

pull 2099999997690000 wants to merge 18 commits into bitcoin:master from bitryonix:bip-unspendable-internal-keys changing 18 files +6333 −0
  1. 2099999997690000 commented at 6:43 AM on November 1, 2026: none

    This proposes _ as an unspendable Taproot internal-key placeholder in wallet policies. Wallets and signers can reproduce the internal key from the policy and derivation path, without keeping a separate random tweak.

    The construction uses the BIP 341 NUMS point as the public key of a synthetic BIP 32 root. Its chain code commits to the normalized policy, including both the keys and the policy structure. Child keys are then derived using unhardened BIP 32 derivation.

    This builds on the Delving discussion and the earlier work in #1746. I shared an earlier draft on the Bitcoin Development Mailing List.

    I've included a Python reference implementation, fixed JSON test vectors, and instructions for running the checks. All 21 offline tests pass, and the export and derivation cross-check passes all 20 cases against Bitcoin Core 31.0.

  2. first commit version 0.1.0 567848cfa4
  3. added bitcoindev link b636b8ec09
  4. duplicated bitcoindev post to correct the bad title 2c8a3ba22d
  5. Merge branch 'bitcoin:master' into bip-xxxx-unspendable-internal-keys 72c8d77ead
  6. reference implementation added and some editorial changes on the bip file 0f4bab28f8
  7. corrected bip name e18f81a2ac
  8. jonatack added the label New BIP on Nov 1, 2026
  9. jonatack renamed this:
    Add BIP: Unspendable Internal Keys for Wallet Policies
    BIP draft: Unspendable Internal Keys for Wallet Policies
    on Nov 1, 2026
  10. in bip-0395.mediawiki:30 in e18f81a2ac outdated
      25 | +
      26 | +The vendored secp256k1lab files are licensed under the [[bip-unspendable-internal-keys/secp256k1lab/COPYING|MIT license]].
      27 | +
      28 | +== Motivation ==
      29 | +
      30 | +A Taproot policy that uses a fixed unspendable internal key produces outputs that are recognizable when script-path spends reveal that key. [[bip-0341.mediawiki#constructing-and-spending-taproot-outputs|BIP 341]] recommends ''H + rG'' with a fresh ''r''. Current implementations use various approaches, such as taking entropy from the keys or choosing and retaining a random ''r''. Deriving the public tweaks from a policy commitment lets independent implementations reproduce the internal key from a policy backup, without additional secret material. Committing to the policy's structure also distinguishes descriptors that use the same keys under different spending conditions.
    


    jonatack commented at 9:07 PM on November 1, 2026:

    Perhaps worth a line on the post-quantum verification property described in https://groups.google.com/g/bitcoindev/c/se3TkNnbno4/m/NC5TeBFrBAAJ (anyone with the policy can re-derive the internal key and prove the key path was unspendable).

    A Taproot policy that uses a fixed unspendable internal key produces outputs that are recognizable when script-path spends reveal that key. [[bip-0341.mediawiki#constructing-and-spending-taproot-outputs|BIP 341]] recommends ''H + rG'' with a fresh ''r''. Current implementations use various approaches, such as taking entropy from the keys or choosing and retaining a random ''r''. Deriving the public tweaks from a policy commitment lets independent implementations reproduce the internal key from a policy backup, without additional secret material. Committing to the policy's structure also distinguishes descriptors that use the same keys under different spending conditions.
    +
    +Anyone holding the policy can also re-derive the internal key and thereby prove the key path was unspendable. This can be useful in post-quantum settings or for exposure classification.
    

  11. in bip-unspendable-internal-keys.mediawiki:131 in e18f81a2ac outdated
     126 | +
     127 | +== Reference implementation and test vectors ==
     128 | +
     129 | +A [[bip-unspendable-internal-keys/reference.py|reference implementation for Python 3.10 or later]] and standalone [[bip-unspendable-internal-keys/vectors.json|JSON test vectors]] are provided. The implementation is for demonstration and interoperability testing, not production use.
     130 | +
     131 | +The recursive parser and normalizer may exceed Python's recursion limit and raise <code>RecursionError</code> on deeply nested inputs. This is a resource limitation of the reference implementation.
    


    jonatack commented at 9:07 PM on November 1, 2026:
     The recursive parser and normalizer may exceed Python's recursion limit and raise <code>RecursionError</code> on deeply nested inputs. This is a resource limitation of the reference implementation.
    +
    +Production implementations should use iterative parsing (or raise the limit) if deep nesting is expected.
    

  12. in bip-unspendable-internal-keys.mediawiki:121 in e18f81a2ac
     116 | +
     117 | +The policy and selected derivation are enough to reproduce the internal key. Seed backups alone do not reconstruct the policy.
     118 | +
     119 | +== Backward compatibility ==
     120 | +
     121 | +Descriptor consumers that support the exported expressions can use the exported form without recognizing <code>_</code>. Export does not guarantee acceptance by a BIP 388 wallet-policy consumer: for example, this construction permits records with equal public keys and different chain codes, while BIP 388 requires pairwise distinct public keys in its key-information vector.
    


    jonatack commented at 9:08 PM on November 1, 2026:

    Maybe an example would make the BIP 388 rejection clearer.

     Descriptor consumers that support the exported expressions can use the exported form without recognizing <code>_</code>. Export does not guarantee acceptance by a BIP 388 wallet-policy consumer: for example, this construction permits records with equal public keys and different chain codes, while BIP 388 requires pairwise distinct public keys in its key-information vector.
    +
    +An export that lists the same public key under two different chain codes will be rejected by a strict BIP 388 consumer.
    

    2099999997690000 commented at 5:11 AM on November 2, 2026:

    Expanded this paragraph to cover duplicate public keys, repeated MuSig indexes, and overlapping derivation paths, with a link to the relevant BIP 388 rules.

    https://github.com/bitcoin/bips/blob/a2175a1e336eddb80562173bc8863bbaf2269932/bip-unspendable-internal-keys.mediawiki?plain=1#L123

    Also added tests covering them:

    https://github.com/bitcoin/bips/blob/a2175a1e336eddb80562173bc8863bbaf2269932/bip-unspendable-internal-keys/tests.py#L140-L193

    Thank you.

  13. jonatack commented at 9:21 PM on November 1, 2026: member

    Looks good and complete. Ran the tests and check_core.py.

    <details><summary>Test run and check_core run</summary><p>

    (e18f81a2...):~/bitcoin/bips$ python3 -B bip-unspendable-internal-keys/tests.py
    test_all_key_permutations (__main__.ConstructionTests.test_all_key_permutations) ... ok
    test_compressed_parity_is_preserved_between_steps (__main__.ConstructionTests.test_compressed_parity_is_preserved_between_steps) ... ok
    test_equivalences_and_distinctions (__main__.ConstructionTests.test_equivalences_and_distinctions) ... ok
    test_export_preserves_input_and_indexes (__main__.ConstructionTests.test_export_preserves_input_and_indexes) ... ok
    test_fixed_vectors (__main__.ConstructionTests.test_fixed_vectors) ... ok
    test_full_records_control_musig_sorting (__main__.ConstructionTests.test_full_records_control_musig_sorting) ... ok
    test_invalid_vectors (__main__.ConstructionTests.test_invalid_vectors) ... ok
    test_manual_preimages (__main__.ConstructionTests.test_manual_preimages) ... ok
    test_network_only_changes_root_version_and_checksum (__main__.ConstructionTests.test_network_only_changes_root_version_and_checksum) ... ok
    test_no_multipath_has_one_expansion (__main__.ConstructionTests.test_no_multipath_has_one_expansion) ... ok
    test_normalization_idempotence (__main__.ConstructionTests.test_normalization_idempotence) ... ok
    test_record_count_compactsize_boundary (__main__.ConstructionTests.test_record_count_compactsize_boundary) ... ok
    test_recorded_core_results_match_vectors (__main__.ConstructionTests.test_recorded_core_results_match_vectors) ... ok
    test_stops_at_first_invalid_child (__main__.ConstructionTests.test_stops_at_first_invalid_child) ... ok
    test_template_length_compactsize_boundary (__main__.ConstructionTests.test_template_length_compactsize_boundary) ... ok
    test_base58check (__main__.PrimitiveTests.test_base58check) ... ok
    test_bip32_public_derivation (__main__.PrimitiveTests.test_bip32_public_derivation) ... ok
    test_compactsize (__main__.PrimitiveTests.test_compactsize) ... ok
    test_invalid_children_and_zero_tweak (__main__.PrimitiveTests.test_invalid_children_and_zero_tweak) ... ok
    test_invalid_points (__main__.PrimitiveTests.test_invalid_points) ... ok
    test_nums_point_and_fingerprint (__main__.PrimitiveTests.test_nums_point_and_fingerprint) ... ok
    
    ----------------------------------------------------------------------
    Ran 21 tests in 0.758s
    
    OK
    jon|(e18f81a2...):~/bitcoin/bips$ python3 -B bip-unspendable-internal-keys/check_core.py
    {
      "core_version": "/Satoshi:32.1.0/",
      "network": "regtest",
      "checks": [
        {
          "name": "single",
          "expansion": 0,
          "index": 0,
          "internal_key": "c3fdf3b6a04fafa134e5d0c8f9926bf45e3377ae4f27d1d26a880f357bdeb904",
          "addresses": [
            "bcrt1pcf34kqg3n4v0zev84rswat52ysz0a3kgyvlw83pqnz84lcuqq20sek65cu"
          ]
        },
        {
          "name": "single",
          "expansion": 1,
          "index": 0,
          "internal_key": "bf113123683375fd195a4f0df956937fdc5a393d1091900aacba81b3cf77a97b",
          "addresses": [
            "bcrt1paj5g4g8qczcqpnautjwsrmdujud5ylzc3vlweunzxwn69pgq5sjqqrqvgz"
          ]
        },
        {
          "name": "single",
          "expansion": 0,
          "index": 2147483647,
          "internal_key": "a51f4adcf9999994ea499a81d6ff3b2390ee567d57486c81ecc0aed2d140f5b9",
          "addresses": [
            "bcrt1pv5lxmsgnz2855t0c4fje370pl9spdj2q83gptq4sxtaltd5fauqsmnph6w"
          ]
        },
        {
          "name": "single-expanded",
          "expansion": 0,
          "index": 0,
          "internal_key": "c3fdf3b6a04fafa134e5d0c8f9926bf45e3377ae4f27d1d26a880f357bdeb904",
          "addresses": [
            "bcrt1pcf34kqg3n4v0zev84rswat52ysz0a3kgyvlw83pqnz84lcuqq20sek65cu"
          ]
        },
        {
          "name": "single-expanded",
          "expansion": 0,
          "index": 1,
          "internal_key": "66aa19a3b73ca4058d910da7c95cd89e96b7f116a7608b0207d034a03da2a16d",
          "addresses": [
            "bcrt1pgph6mhru3w8s56y5h4lnxeszy4ax0pn7hxfzxl3yvj69fmcetgcqxv0lnv"
          ]
        },
        {
          "name": "four-expansions",
          "expansion": 0,
          "index": 0,
          "internal_key": "82c15b1dd33d5dc1b491bc16a38c5a9c70fbfd00534101d79404c9a5972cca9e",
          "addresses": [
            "bcrt1pcr9frk0qn4vjxmgescfsn3my8t2s0fnjpsnvdjqcfz50qgf6y24qx5gsaa"
          ]
        },
        {
          "name": "four-expansions",
          "expansion": 1,
          "index": 0,
          "internal_key": "65dba4f2e2e730df7cbe8b1d8b8435ca9ee4dfc36d933deb4a9564c392446c97",
          "addresses": [
            "bcrt1pp64wha9y4eeh4kfq3sc8wkfysck690l5g5n6ra3py8h0nt0gyvaqttk5ps"
          ]
        },
        {
          "name": "four-expansions",
          "expansion": 3,
          "index": 17,
          "internal_key": "0f7611b6c84637620caa3f1d7e6db6837187362f45fad0acab86430e82249dff",
          "addresses": [
            "bcrt1p98zgq9q9wtukvtcupyzxzd7f62e9edxf3jklj8ddgrs9n3rzjxzsld0dvs"
          ]
        },
        {
          "name": "sorted",
          "expansion": 0,
          "index": 0,
          "internal_key": "fcea15adb7040910c1dc9c4339045e2647578a216b7ad3cea7fa8a2a86f70ad0",
          "addresses": [
            "bcrt1pl3upn3aw0c0td9y0c78q8qz8px04f7ydqvnpxjgqutefm90rxats9wqpy8"
          ]
        },
        {
          "name": "sorted",
          "expansion": 0,
          "index": 1,
          "internal_key": "87ffa4a79a969cc397fdafcf2dbd7b17040ba22dd6f1cf42fb35830630471fe6",
          "addresses": [
            "bcrt1pmz0aq2ylxmzlcg0ht042ng6a456qkjtrahvjkuwmxd2z97j2mm8qhv40v8"
          ]
        },
        {
          "name": "sorted-permuted",
          "expansion": 0,
          "index": 0,
          "internal_key": "fcea15adb7040910c1dc9c4339045e2647578a216b7ad3cea7fa8a2a86f70ad0",
          "addresses": [
            "bcrt1pl3upn3aw0c0td9y0c78q8qz8px04f7ydqvnpxjgqutefm90rxats9wqpy8"
          ]
        },
        {
          "name": "sorted-permuted",
          "expansion": 0,
          "index": 1,
          "internal_key": "87ffa4a79a969cc397fdafcf2dbd7b17040ba22dd6f1cf42fb35830630471fe6",
          "addresses": [
            "bcrt1pmz0aq2ylxmzlcg0ht042ng6a456qkjtrahvjkuwmxd2z97j2mm8qhv40v8"
          ]
        },
        {
          "name": "musig",
          "expansion": 0,
          "index": 0,
          "internal_key": "be56170918b1939bdd676aab8750ed7ce5183fc8216276c361c3d6335eca0f57",
          "addresses": [
            "bcrt1pr8yxfqf0kadcu43at4svt7rckc7wcwz6drcvgeud2q6t0lppt4fqjcy0fr"
          ]
        },
        {
          "name": "musig",
          "expansion": 0,
          "index": 1,
          "internal_key": "1f4b7a9af7e7e11263c91aa5b68a22b32139020729e7cdea0bc0bd49cebbc0a1",
          "addresses": [
            "bcrt1pr9f55lxma77y5m5pjvc6z7t0c8zezjsk4y0qaufsxtfj24u46pls08w0cy"
          ]
        },
        {
          "name": "tree",
          "expansion": 0,
          "index": 0,
          "internal_key": "01a9ed75464a9fdc15dd77ac565d39e48a4e30179da2a65fbe08c7823837fdd5",
          "addresses": [
            "bcrt1plp0rw0egy7a086nynmq8nwajm5f9acsyzcyqj4h8ks9tyuf8ga4qsgkvsw"
          ]
        },
        {
          "name": "tree",
          "expansion": 0,
          "index": 1,
          "internal_key": "63209dc77a6cfedcc6a2f983d689f3e1331d449db8b827f0786cff1f27cf6a8c",
          "addresses": [
            "bcrt1pzmr5fdal78aq5w6rmfpgtg5en3l78xek8dg4yhvc63ln7h5jpuzslpxk3d"
          ]
        },
        {
          "name": "tree-swapped",
          "expansion": 0,
          "index": 0,
          "internal_key": "01a9ed75464a9fdc15dd77ac565d39e48a4e30179da2a65fbe08c7823837fdd5",
          "addresses": [
            "bcrt1plp0rw0egy7a086nynmq8nwajm5f9acsyzcyqj4h8ks9tyuf8ga4qsgkvsw"
          ]
        },
        {
          "name": "tree-swapped",
          "expansion": 0,
          "index": 1,
          "internal_key": "63209dc77a6cfedcc6a2f983d689f3e1331d449db8b827f0786cff1f27cf6a8c",
          "addresses": [
            "bcrt1pzmr5fdal78aq5w6rmfpgtg5en3l78xek8dg4yhvc63ln7h5jpuzslpxk3d"
          ]
        },
        {
          "name": "timelock",
          "expansion": 0,
          "index": 0,
          "internal_key": "ed2c0c0f14e63b15f9302782b74654b8a7808085e210906fb663d3c242883436",
          "addresses": [
            "bcrt1pz0f3cnsend3832wjc29l8g0kfxgfl05nlezhhvyf9m5jcngv6fuskqmwd5"
          ]
        },
        {
          "name": "timelock",
          "expansion": 0,
          "index": 1,
          "internal_key": "432bffa5c9ea820bd654662756d052d2d19153610b99ce445249e45714c56356",
          "addresses": [
            "bcrt1pxduf9wpjquelxsp6yuru9g6sdtvzp0fct5ph4lm9wmyqqgaynqksdppysq"
          ]
        }
      ]
    }
    

    </p></details>

  14. jonatack added the label Needs number assignment on Nov 1, 2026
  15. fametrano commented at 1:12 AM on November 2, 2026: contributor

    ACK e18f81a2ac192f8c59da7fe9cc2795309b8dd343

    I implemented normalization, the commitment and the export from the BIP text, without the reference code, on btclib-org's BIP 32 and hashing code (btclib-wallet, btclib, ecc), which I maintain. This adds to the runs of tests.py and check_core.py above an implementation that shares no code with the reference. It reproduces every intermediate value of all 51 valid vectors, the 105 internal keys and the 51 exports, agrees with the 11 equivalent groups and 13 distinct pairs, and rejects the 50 invalid vectors at their stated stage. btclib-wallet's descriptor parser reads back the exports of 42 valid vectors and derives the same 86 internal keys; it refuses the leaves of the other 9 as not sane or not satisfiable. Its addresses match the 20 Bitcoin Core results in core-checks.json, and gen_vectors.py prints vectors.json byte for byte. Scripts and output: https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/d26bc4f8de24a38d6389cdfc3e7c2e4c7e4a5f40

  16. added @jonatack suggestions to bip file and added tests demonstrating this bip may process descriptors that bip388 rejects a2175a1e33
  17. fametrano commented at 9:25 AM on November 2, 2026: contributor

    ACK a2175a1e336eddb80562173bc8863bbaf2269932

    Since e18f81a2 only the BIP text and tests.py changed; reference.py, vectors.json and core-checks.json are byte-identical, so the btclib-org reproduction in my earlier review still holds: https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/d26bc4f8de24a38d6389cdfc3e7c2e4c7e4a5f40. On this head tests.py passes its 24 tests, gen_vectors.py still prints vectors.json byte for byte, and the three cases the new Backward compatibility paragraph lists are the ones BIP 388's Additional rules forbid.

    Not blocking: when the policy has keys, the export gives the root the last index but places it first, as in tr(@2/**,{pk(@0/**),pk(@1/**)}), while the same Additional rules say the key vector should be ordered so that @0 appears first; the paragraph could say so. And "Production implementations should use iterative parsing (or raise the limit)" now comes before the RecursionError paragraph, so "the limit" is not yet defined there; it belongs after it.

  18. fixed an editorial misplacement and an implementation discrepancy raised at https://github.com/bitcoin/bips/pull/2340#pullrequestreview-5734401612 9a4073fcd0
  19. 2099999997690000 commented at 4:06 AM on November 3, 2026: none

    ACK a2175a1

    Since e18f81a only the BIP text and tests.py changed; reference.py, vectors.json and core-checks.json are byte-identical, so the btclib-org reproduction in my earlier review still holds: https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/d26bc4f8de24a38d6389cdfc3e7c2e4c7e4a5f40. On this head tests.py passes its 24 tests, gen_vectors.py still prints vectors.json byte for byte, and the three cases the new Backward compatibility paragraph lists are the ones BIP 388's Additional rules forbid.

    Not blocking: when the policy has keys, the export gives the root the last index but places it first, as in tr(@2/**,{pk(@0/**),pk(@1/**)}), while the same Additional rules say the key vector should be ordered so that @0 appears first; the paragraph could say so. And "Production implementations should use iterative parsing (or raise the limit)" now comes before the RecursionError paragraph, so "the limit" is not yet defined there; it belongs after it.

    Thanks, addressed both points in 9a4073f.

    The exporter now assigns the synthetic root to @0 and numbers the other placeholders by first appearance. Your example now exports as tr(@0/**,{pk(@1/**),pk(@2/**)}):

    https://github.com/bitcoin/bips/blob/9a4073fcd0a8edcdd25af8378d7d1630bd3313a5/bip-unspendable-internal-keys/reference.py#L175-L192

    I added a regression test covering the ordering across all 51 valid vectors and updated the expected exports. The resolved descriptors and derived internal keys are unchanged. All 25 tests pass.

    https://github.com/bitcoin/bips/blob/9a4073fcd0a8edcdd25af8378d7d1630bd3313a5/bip-unspendable-internal-keys/tests.py#L142-L153

    Also moved the production guidance after the explanation of the recursion limit:

    https://github.com/bitcoin/bips/blob/9a4073fcd0a8edcdd25af8378d7d1630bd3313a5/bip-unspendable-internal-keys.mediawiki?plain=1#L134

  20. jonatack commented at 3:50 AM on November 4, 2026: member

    Assigned 395. Please update, and add a README entry.

  21. jonatack renamed this:
    BIP draft: Unspendable Internal Keys for Wallet Policies
    BIP395: Unspendable Internal Keys for Wallet Policies
    on Nov 4, 2026
  22. jonatack removed the label Needs number assignment on Nov 4, 2026
  23. Merge branch 'bitcoin:master' into bip-unspendable-internal-keys 0d46f2887e
  24. updated for assignment of bip395 69875aa29c
  25. 2099999997690000 commented at 6:16 AM on November 4, 2026: none

    @jonatack Done. If there's anything more to change, please let me know. Thank you.

  26. fametrano commented at 8:01 AM on November 4, 2026: contributor

    Concept ACK

    One issue should be fixed before merge: the Export section does not say how the exported placeholders are numbered, and the exported templates and key vectors in vectors.json depend on it.

    Both points of my previous review are addressed. Since a2175a1e, vectors.json changes only in the exported templates and key vectors, in 42 of the 51 valid cases; the other 9 have no key but the root. The exported descriptors, intermediate values and derivations are unchanged. On this head tests.py passes its 25 tests and gen_vectors.py prints vectors.json byte for byte. My btclib-org reproduction, written from the text, matches none of the 42 changed exports; with the reference's numbering it matches all 51. Scripts and outputs: https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/4930f34468b34971a06ea52153de72d84b60a703

    One sentence in Export would close it: after _ is replaced, the root is @0, the other placeholders are renumbered by first appearance, and the key vector follows that order, with unreferenced items last, in their input order.

  27. added the export clarification raised by https://github.com/bitcoin/bips/pull/2340#pullrequestreview-5765178135 68bdb208c8
  28. 2099999997690000 commented at 10:12 AM on November 4, 2026: none
  29. 2099999997690000 commented at 11:24 AM on November 4, 2026: none

    BTW, should I change the status to complete?

  30. fametrano commented at 11:27 PM on November 4, 2026: contributor

    ACK 68bdb208c8c649f0220429bea65247c80fb8a897

    The new Export paragraph is enough to reproduce the vectors. I rewrote the export() of my btclib-org reproduction from it, and it now matches all 51 exported templates and key vectors in vectors.json; the version written from the previous text failed 42 of them. The rest still passes: 105 derivations, 50 of 50 invalid vectors rejected at the stated stage, and the 20 recorded Bitcoin Core addresses. Only bip-0395.mediawiki changed since 69875aa2, so the reference code and vectors are the ones I checked there. Script, commands and output: https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/6b4edd1ed4d7524247e26a892468d8696f194f6d

  31. murchandamus commented at 6:14 PM on November 5, 2026: member

    BTW, should I change the status to complete?

    Please leave the status at Draft. Publication usually prompts additional review that often leads to further improvements. This proposal has only been open for a few days, it would be good to get review from some of the mentioned descriptor experts.

  32. 2099999997690000 commented at 3:07 AM on November 6, 2026: none

    Sure, I'll leave it as is. Thank you.

  33. in bip-0395.mediawiki:43 in 68bdb208c8
      38 | +=== Input representation ===
      39 | +
      40 | +The input consists of a descriptor template and a key-information vector in [[bip-0388.mediawiki#formal-definition|BIP 388's representation]], with the following syntax for normalization:
      41 | +
      42 | +* The template is <code>tr(KEY,TREE)</code>, with the binary tree syntax of [[bip-0386.mediawiki#tree-expression|BIP 386]], where <code>KEY</code> is <code>_</code> followed by a derivation suffix. Leaves use the Tapscript fragment syntax and translation table of [[bip-0379.md#translation-table|BIP 379]], or [[bip-0387.mediawiki#sortedmulti_a|BIP 387's]] <code>sortedmulti_a</code> syntax. The latter forms a whole leaf.
      43 | +* A key expression is <code>@i</code> or <code>musig(@i,...)</code>, followed by an optional derivation suffix in the syntax of [[bip-0380.mediawiki#key-expressions|BIP 380]] and [[bip-0389.mediawiki#specification|BIP 389]]. The abbreviation <code>/**</code> means <code>/<0;1>/*</code>.
    


    danielabrozzoni commented at 11:54 AM on November 6, 2026:

    I would change this to: "Every key espression in TREE's leaves is..."

    I was initially a bit confused, I thought this sentence was telling me to use @i in KEY, but that didn't make much sense :)


    2099999997690000 commented at 4:57 AM on November 7, 2026:

    Thanks, clarified that this rule applies to key expressions in TREE's leaves.

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395.mediawiki?plain=1#L43

  34. in bip-0395.mediawiki:97 in 68bdb208c8
      92 | +
      93 | +== Rationale ==
      94 | +
      95 | +The commitment covers the whole normalized policy because committing only to its keys would give every policy over the same keys the same internal key. Script-path spends would then reveal equal internal keys and link those policies. A coordinator could also reuse one wallet's internal keys in another. Binding thresholds, timelocks, roles, ranges, repetition, and tree structure prevents both.
      96 | +
      97 | +The public key and chain code determine every derived key, so these are the only fields in a record. Version bytes, depth, parent fingerprint, child number, and origin do not change derived keys. Including them in the commitment would give an xpub and its tpub form, or the same key with and without an origin, different internal keys for identical addresses. The excluded fields stay in the input because export needs them.
    


    danielabrozzoni commented at 12:32 PM on November 6, 2026:

    Including them in the commitment would give an xpub and its tpub form, or the same key with and without an origin, different internal keys for identical addresses.

    This sentence is correct, but a bit hard to parse, I would restructure it as:

    Including them in the commitment would produce different internal keys for an xpub and its tpub form, or for the same key with and without an origin, even though these generate identical scripts.

    Also I would say identical scripts rather than identical addresses, because in the xpub vs tpub form the address would change, because of different network bytes (e.g. bc1... vs tb1...)


    2099999997690000 commented at 5:04 AM on November 7, 2026:

    Agreed. Restructured the sentence as suggested and changed it to refer to identical derived keys and script trees, avoiding the network-dependent address wording.

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395.mediawiki?plain=1#L97

  35. in bip-0395.mediawiki:64 in 68bdb208c8
      59 | +
      60 | +=== Commitment normalization ===
      61 | +
      62 | +For a referenced key-information item with public key ''K<sub>i</sub>'' and chain code ''c<sub>i</sub>'', define its 65-byte ''record'' as ''R<sub>i</sub> = ser<sub>P</sub>(K<sub>i</sub>) || c<sub>i</sub>''. The operator ''||'' denotes byte concatenation, and ''ser<sub>P</sub>'' is the compressed public-key serialization from [[bip-0032.mediawiki#conventions|BIP 32's conventions]]. Origins, network versions, depth, parent fingerprints, and child numbers are excluded. Unreferenced items are omitted.
      63 | +
      64 | +The following ''serialization rules'' apply to the template and to every key expression, leaf, and subtree in it. They MUST be serialized as ASCII without whitespace or checksum. Integers MUST use their shortest unsigned decimal representation, and hexadecimal MUST be lowercase. Implementations MUST use the syntactic sugar <code>pk</code>, <code>pkh</code>, <code>and_n</code>, <code>t:</code>, <code>l:</code>, and <code>u:</code> from the [[bip-0379.md#translation-table|BIP 379 translation table]] wherever the expanded forms match. They MUST use <code>l:</code> when both <code>l:</code> and <code>u:</code> match, and MUST join adjacent wrappers as specified there. A terminal <code>/<0;1>/*</code> MUST be written as <code>/**</code>. Implementations MUST preserve all other derivation steps and the order of multipath alternatives, and MUST NOT perform any other rewrite.
    


    danielabrozzoni commented at 2:38 PM on November 6, 2026:

    Found by Opus 5: you currently allow both h and ' for hardened derivations, is that on purpose? I also see it in the test vector in bip-0395/gen_vectors.py L112 (hardened-leaf-syntax), where you are mixing both markers in a single template. I think you should either stick with one, to avoid two obviously equivalent expressions to produce different outputs, or explicitly mention that both are allowed.


    2099999997690000 commented at 5:11 AM on November 7, 2026:

    Both spellings remain accepted, but now normalize to h for commitment serialization. This includes fixed steps, multipath alternatives, and hardened wildcards.

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395.mediawiki?plain=1#L64

    Updated the parser accordingly:

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395/policy.py#L88-L101

    Added equivalence cases covering mixed markers, all h, and all apostrophes, and regenerated the vectors. Export still preserves the original input spelling.

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395/gen_vectors.py#L114-L127

  36. in bip-0395.mediawiki:68 in 68bdb208c8 outdated
      63 | +
      64 | +The following ''serialization rules'' apply to the template and to every key expression, leaf, and subtree in it. They MUST be serialized as ASCII without whitespace or checksum. Integers MUST use their shortest unsigned decimal representation, and hexadecimal MUST be lowercase. Implementations MUST use the syntactic sugar <code>pk</code>, <code>pkh</code>, <code>and_n</code>, <code>t:</code>, <code>l:</code>, and <code>u:</code> from the [[bip-0379.md#translation-table|BIP 379 translation table]] wherever the expanded forms match. They MUST use <code>l:</code> when both <code>l:</code> and <code>u:</code> match, and MUST join adjacent wrappers as specified there. A terminal <code>/<0;1>/*</code> MUST be written as <code>/**</code>. Implementations MUST preserve all other derivation steps and the order of multipath alternatives, and MUST NOT perform any other rewrite.
      65 | +
      66 | +An expression's ''resolved string'' is its serialization under these rules, with each <code>@i</code> replaced by the lowercase hexadecimal encoding of its record ''R<sub>i</sub>''. Resolved strings MUST be compared lexicographically by unsigned ASCII byte value.
      67 | +
      68 | +Implementations MUST apply these steps in order:
    


    danielabrozzoni commented at 3:07 PM on November 6, 2026:

    Found by Opus 5: before starting these steps, it's important that the template is rewritten following the serialization rules (integers using their shortest unsigned decimal representation, hex lowercase, syntactic sugars used, etc), otherwise there might be discrepancies in the sorting. This is implemented in the reference, and specified above ("The following ''serialization rules'' apply to the template and to every key expression, leaf, and subtree in it..."), but could be repeated here to make it even more clear.

    Also, a test vector that catches this should be added:

    diff --git a/bip-0395/gen_vectors.py b/bip-0395/gen_vectors.py
    index 54ba2ae..ff46aef 100644
    --- a/bip-0395/gen_vectors.py
    +++ b/bip-0395/gen_vectors.py
    @@ -88,6 +88,8 @@ def generate():
         add("tree-reshaped", "tr(_/**,{{pk(@0/**),pk(@1/**)},pk(@2/**)})", [A, B, C])
         add("tree-repeated", "tr(_/**,{pk(@0/**),pk(@0/**)})", [A])
         add("tree-duplicate-record", "tr(_/**,{pk(@0/**),pk(@1/**)})", [A, A])
    +    add("tree-sugar", "tr(_/**,{pk(@0/**),pk(@1/**)})", [B, A])
    +    add("tree-sugar-expanded", "tr(_/**,{c:pk_k(@0/**),pk(@1/**)})", [B, A])
         add("timelock", "tr(_/**,and_v(v:pk(@0/**),older(144)))", [A])
         add("timelock-changed", "tr(_/**,and_v(v:pk(@0/**),older(145)))", [A])
         add("sugar", "tr(_/**,and_n(pk(@0/**),tv:pkh(@1/**)))", [A, B])
    @@ -117,6 +119,7 @@ def generate():
             ["sorted", "sorted-permuted"], ["musig", "musig-permuted"],
             ["musig-repeated", "musig-duplicate-record"], ["musig-same-point", "musig-same-point-reversed"],
             ["tree", "tree-swapped"], ["tree-repeated", "tree-duplicate-record"],
    +        ["tree-sugar", "tree-sugar-expanded"],
             ["sugar", "sugar-expanded"], ["l-zero", "u-zero", "or-zero"],
             ["numeric-spelling", "numeric-canonical"], ["hashlock", "hashlock-lower"],
         ]
    

    2099999997690000 commented at 5:16 AM on November 7, 2026:

    Thanks, made it explicit in the sorting step that all serialization rules apply before comparison.

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395.mediawiki?plain=1#L70

    Added your proposed tree-sugar and tree-sugar-expanded cases:

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395/gen_vectors.py#L91-L92

    And their equivalence group:

    https://github.com/bitcoin/bips/blob/54321b4b6ef4147edcd4d9d6d1fc3adf9dfeb368/bip-0395/gen_vectors.py#L124

    I also verified that this pair detects an implementation that incorrectly sorts before normalizing syntactic sugar. All 25 offline tests pass.

  37. danielabrozzoni commented at 3:11 PM on November 6, 2026: member

    Reviewed 68bdb208c8c649f0220429bea65247c80fb8a897

    Overall it looks good, I left a few improvement ideas :)

  38. Merge bitcoin/master into bip-unspendable-internal-keys 55e55365d3
  39. fixed the issues and implemented improvements suggested by https://github.com/bitcoin/bips/pull/2340#pullrequestreview-5799707987 54321b4b6e
  40. fametrano commented at 2:50 PM on November 7, 2026: contributor

    ACK 54321b4b

    My reproduction, written from the text, matches all 55 valid vectors on this head, the four new ones and the two new equivalent groups included, and rejects the 50 invalid vectors at their stated stage. Writing every hardened marker as h is the only rule it needed: the version that matched 68bdb208 fails exactly hardened-leaf-syntax, hardened-leaf-apostrophe and their group. The scripts, commands and outputs are in https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/f67efbcfc2eed400f6050fced6fa02cfc21d7b49

  41. bigspider commented at 9:52 AM on November 9, 2026: contributor

    Hello, thanks for bringing this proposal forward - I fully agree on the general principle.

    I did not do an in-depth review, but I would recommend to simplify the specifications as much as possible, as that will increase the chance of adoption and independent implementation (as it is necessary, for example, in hardware signing devices).

    The concern I would like to bring forward is that the entire Commitment normalization section adds a large amount of complexity, for virtually no benefit. The Rationale currently says:

    The commitment covers the whole normalized policy because committing only to its keys would give every policy over the same keys the same internal key. Script-path spends would then reveal equal internal keys and link those policies. A coordinator could also reuse one wallet's internal keys in another. Binding thresholds, timelocks, roles, ranges, repetition, and tree structure prevents both.

    This is problematic, as software wallets and hardware signers are already using descriptors and wallet policies that are not necessarily normalized. So instead of BIP395 being 'just a new feature', these specs require an invasive change to existing implementations.

    If keys/xpubs are reused, it is generally to be expected that it will be possible to correlate independent UTXOs back to the same owner when they are spent. At that point, the fingerprinting vector via the NUMS keypath is a much lesser problem - privacy is already lost. Vice-versa, if xpubs are not reused, then basing the commitment on just the keys is enough to also protect from fingerprinting, with radically simpler specifications.

    Therefore, I recommend getting rid of the Script normalization requirements, and make the NUMS point only commit to keys. It is probably useful to add an explicit recommendation for wallets to strive to never reuse xpubs.

  42. fametrano commented at 8:13 PM on November 10, 2026: contributor

    A keys-only commitment gives the same internal key to 11 of the 13 pairs that vectors.json lists as distinct. Four of them differ in key expressions, such as the same xpub at another path.

    I measured this on 54321b4b to put numbers on @bigspider's point. The whole normalization is 20% of the reference code and 35% of the Specification's words.

    I suggest committing to each key expression with its derivation path. Only policies with the same key expressions, which already share leaf keys, would share an internal key, and the 31 pairs vectors.json lists as equivalent stay together. It still needs MuSig participants sorted, equal records merged and one spelling per path, so part of normalization stays. The trade: the other 7 pairs (threshold, key order, tree shape, repetition, timelock and hashlock changes) would share one, and the Rationale's coordinator-reuse concern stays open. Scripts and outputs are at https://gist.github.com/fametrano/1a363003e55795b5d1a4e39e3c42c81e/2a76db0c3fb67863b9f5cbe7033ebc3cb83aab27.

  43. 2099999997690000 commented at 7:10 AM on November 11, 2026: none

    @bigspider thank you for raising this, and @fametrano thank you for the analysis and the numbers.

    I am leaning towards the keys-only option and would like to check it with you before I rewrite the BIP.

    What is committed. Each xpub in the key vector that the template references, taken as is: its public key and chain code, with no derivation. Duplicates are removed, the rest are sorted and hashed with the tagged hash. Nothing else from the template goes in: no derivation paths, no musig() grouping, no script structure. The _ placeholder, its path rules, the synthetic root and the export stay as they are.

    The assumption. Wallets follow BIP 388's recommendation not to reuse keys across accounts. The BIP will state this and recommend a fresh account per policy.

    What this costs. I want to state the downsides plainly, since they will go into the BIP:

    1. Reusing a whole xpub set links the wallets. Two policies over exactly the same xpubs share internal keys at the same index, and script-path spends reveal them. Partial overlap does not collide.
    2. Keyless policies are recognizable by anyone. They all share one root.
    3. The internal key no longer commits to the policy. Anyone who knows the xpub set can compute it without knowing the policy.

    In all three the loss is privacy. The key path stays unspendable and funds are unaffected.

    Why not paths as well. I considered committing each key expression with its derivation path, as @fametrano suggested. It would narrow the first downside: of the 13 distinct pairs in vectors.json, keys-only merges 11 and this would merge 7. The 4 it saves are the same xpub at different paths and a repeated MuSig participant, and those cases only arise when the recommendation is already broken. In exchange the signer has to walk the template, and the BIP has to define a path encoding. The versioned tag leaves room to add this later if practice shows the need.

    Now the question is whether this is appropriate to be implemented on a signer and adopted by those already solving this issue in other ways, and do these costs look acceptable? Or are those costs dire enough to have the standard go its own way despite the possible adoption hardships.

  44. fametrano commented at 11:17 PM on November 11, 2026: contributor

    Keys-only is acceptable to me. Whether it suits a signer is a question for @bigspider, who wrote BIP 388 and the Ledger Bitcoin app.

  45. pythcoiner commented at 5:34 AM on November 13, 2026: contributor

    Strongly agree with @bigspider , I really dislike the overall complexity, if I had to pick a direction, I would advise to start from #1746 with the addition of _ and sorting only where it matters (musig and sortedmulti iirc)

  46. 2099999997690000 commented at 6:23 AM on November 13, 2026: none

    So it seems we are converging to something like this:

    records = sort(unique(compressed_pubkey || chain_code))
    commitment_input = CompactSize(record_count) || concatenate(records)
    synthetic_chain_code = tagged_hash(specified_tag, commitment_input)
    

    Plain and simple global unique sort. @pythcoiner in this approach there would be no need for sorting the contents of musig and sortedmulti I think.

    Please let me know if we all agree on this or I'm missing anything, so that I move to changing the bip and the implementation.

    Thank you all.

  47. pythcoiner commented at 8:44 AM on November 13, 2026: contributor

    sorry, I realized my previous message was not representing well what I had in mind, so I clauded smth: https://github.com/bitcoin/bitcoin/compare/master...pythcoiner:bitcoin:bip395

  48. 2099999997690000 commented at 4:07 AM on November 14, 2026: none

    @pythcoiner thanks for the clarification. The code shows the distinction. I had read your earlier comment as agreement on a globally sorted, deduplicated key set. Though your implementation preserves traversal order and repetitions, sorting only within musig() and sortedmulti_a() and using only the compressed public keys instead of pubky || chaincode.

    If we are choosing a new construction, I still lean toward the globally sorted unique set of pubkey || chain_code records. That removes the need for special handling of MuSig, sortedmulti, or tree ordering.

    If we could gather more input from those who were involved in the previous works on this topic, it would be great. So we can conclude and move forward.

  49. pythcoiner commented at 4:25 AM on November 14, 2026: contributor

    on a globally sorted, deduplicated key set

    I see several advantages of NOT doing this:

    • Actual implems (Liana and Nunchuk uses the same scheme) stays compatible
    • I can reuse a cosigning key in several similar policies w/o introducing privacy leaks or(musig(A,B),and(C,older(tl))) & or(musig(C,B),and(A,older(tl)))
  50. 2099999997690000 commented at 2:31 PM on November 14, 2026: none

    @pythcoiner thank you for pointing out those issues.

    So, I started with a maximalist approach. Assume key reuse happens and aim for the best normalization attainable short of canonicalization.

    Then the point was raised by @bigspider that key reuse shall be avoided and the protection my first approach provided was no good should key reuse happen and the complexity was too much specially for signer devices and current implementation, which was a valid point. The simplest approach, given that there be no key reuse, was tagged_hash(sorted(unique(pubkey || chaincode).

    Now what @pythcoiner raises here, in its second point of rationale contradicts the assumption we accepted to revert the maximalist approach. If reusing keys is acceptable and an option, why confine it to the limited cases Liana and Nunchuk happen to tolerate in their implementation of NUMS? I cannot see any reason for that.

    I think we have 3 options here:

    1. Just use the simplest approach that is consistent in its assumptions, which is tagged_hash(sorted(unique(pubkey || chaincode) or even tagged_hash(sorted(unique(pubkey).
    2. Use versioning to cover all these approaches even the maximalist one.
    3. Somehow find another middle ground that has a consistent rationale and makes current implementations happy without imposing arbitrary design choices on those who are going to use this bip with a wide variety of requirements and environments.

    I personally lean towards 1 and can accept 2 if it gains consensus and will be open for any 3.

    Thank you for your feedbacks.

  51. Merge branch 'bitcoin:master' into bip-unspendable-internal-keys eacc0d0f54
  52. authors names fixed 2a337e715f
  53. Merge branch 'bitcoin:master' into bip-unspendable-internal-keys bdb1ef1f2b
  54. version 0.2.0 adopting sorted unique keys approach 4083ef503f
  55. 2099999997690000 commented at 3:46 AM on November 20, 2026: none

    Hi all. I made the changes in bip file and implementation to adopt the simple tagged_hash(sorted(unique(pubkey || chaincode) approach as in the first option in my last comment here.

  56. added changelog section 946474c73e

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-23 21:10 UTC

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