Repository navigation
BIP395: Unspendable Internal Keys for Wallet Policies - #2340
2099999997690000 wants to merge 18 commits into
Conversation
jonatack
left a comment
There was a problem hiding this comment.
Looks good and complete. Ran the tests and check_core.py.
Test run and check_core run
(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"
]
}
]
}|
|
||
| == Motivation == | ||
|
|
||
| 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. |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Added, thanks.
|
|
||
| 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. | ||
|
|
||
| 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. |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Added the note for production implementations.
bips/bip-unspendable-internal-keys.mediawiki
Line 133 in a2175a1
|
|
||
| == Backward compatibility == | ||
|
|
||
| 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. |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Expanded this paragraph to cover duplicate public keys, repeated MuSig indexes, and overlapping derivation paths, with a link to the relevant BIP 388 rules.
bips/bip-unspendable-internal-keys.mediawiki
Line 123 in a2175a1
Also added tests covering them:
bips/bip-unspendable-internal-keys/tests.py
Lines 140 to 193 in a2175a1
Thank you.
fametrano
left a comment
There was a problem hiding this comment.
ACK e18f81a
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
… this bip may process descriptors that bip388 rejects
fametrano
left a comment
There was a problem hiding this comment.
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 bips/bip-unspendable-internal-keys/reference.py Lines 175 to 192 in 9a4073f 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. bips/bip-unspendable-internal-keys/tests.py Lines 142 to 153 in 9a4073f Also moved the production guidance after the explanation of the recursion limit: bips/bip-unspendable-internal-keys.mediawiki Line 134 in 9a4073f |
|
Assigned 395. Please update, and add a README entry. |
|
@jonatack Done. If there's anything more to change, please let me know. Thank you. |
fametrano
left a comment
There was a problem hiding this comment.
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 a2175a1, 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.
|
@fametrano Thanks, addressed in 68bdb20. The Export section now explicitly states: |
|
BTW, should I change the status to complete? |
fametrano
left a comment
There was a problem hiding this comment.
ACK 68bdb20
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 69875aa, so the reference code and vectors are the ones I checked there. Script, commands and output: https://gist.github.com/fametrano/d8966a1925a4f8d1800c05f2422d365a/6b4edd1ed4d7524247e26a892468d8696f194f6d
murchandamus
left a comment
There was a problem hiding this comment.
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.
|
Sure, I'll leave it as is. Thank you. |
danielabrozzoni
left a comment
There was a problem hiding this comment.
Reviewed 68bdb20
Overall it looks good, I left a few improvement ideas :)
| 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: | ||
|
|
||
| * 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. | ||
| * 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>. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Thanks, clarified that this rule applies to key expressions in TREE's leaves.
Line 43 in 54321b4
|
|
||
| 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. | ||
|
|
||
| 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. |
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
Agreed. Restructured the sentence as suggested and changed it to refer to identical derived keys and script trees, avoiding the network-dependent address wording.
Line 97 in 54321b4
|
|
||
| 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. | ||
|
|
||
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Both spellings remain accepted, but now normalize to h for commitment serialization. This includes fixed steps, multipath alternatives, and hardened wildcards.
Line 64 in 54321b4
Updated the parser accordingly:
Lines 88 to 101 in 54321b4
Added equivalence cases covering mixed markers, all h, and all apostrophes, and regenerated the vectors. Export still preserves the original input spelling.
Lines 114 to 127 in 54321b4
|
|
||
| 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. | ||
|
|
||
| Implementations MUST apply these steps in order: |
There was a problem hiding this comment.
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"],
]There was a problem hiding this comment.
Thanks, made it explicit in the sorting step that all serialization rules apply before comparison.
Line 70 in 54321b4
Added your proposed tree-sugar and tree-sugar-expanded cases:
Lines 91 to 92 in 54321b4
And their equivalence group:
Line 124 in 54321b4
I also verified that this pair detects an implementation that incorrectly sorts before normalizing syntactic sugar. All 25 offline tests pass.
fametrano
left a comment
There was a problem hiding this comment.
ACK 54321b4
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 68bdb20 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
|
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
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. 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. |
|
A keys-only commitment gives the same internal key to 11 of the 13 pairs that I measured this on 54321b4 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 |
|
@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 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:
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 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. |
|
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. |
|
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 |
|
So it seems we are converging to something like this: 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. |
|
sorry, I realized my previous message was not representing well what I had in mind, so I clauded smth: bitcoin/bitcoin@master...pythcoiner:bitcoin:bip395 |
|
@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. |
I see several advantages of NOT doing this:
|
|
@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 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:
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. |
|
Hi all. I made the changes in bip file and implementation to adopt the simple |
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.