Skip to content

Commit 73dce7a

Browse files
author
Robert Spigler
authored
BIP2 compliance. Add rationale, addresss discovery, etc.
1 parent f4cea61 commit 73dce7a

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

Modern Hierarchy for Deterministic Multisignature Wallets.mediawiki

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
Status: Proposed
99
Type: Standards Track
1010
Created: 2020-03-11
11+
License: BSD-2-Clause
1112
</pre>
1213

13-
===Copyright===
14-
15-
This BIP is licensed under the 2-clause BSD license.
16-
1714
==Abstract==
1815

1916
This BIP defines a sane hierarchy for deterministic multisig wallets based on an algorithm described in BIP-0032 (BIP32 from now on), purpose scheme described in BIP-0043 (BIP43 from now on), and multi-account hierarchy described in BIP-0044 (BIP44 from now on).
2017

2118
This BIP is a particular application of BIP43.
2219

20+
==Copyright==
21+
22+
This BIP is licensed under the 2-clause BSD license.
23+
2324
==Motivation==
2425

2526
With the increase of more user friendly (offline) multisignature wallets, and adoption of new technologies such as [https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md the descriptor language] and [https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki BIP-0174 (Partially Signed Bitcoin Transactions)] it is necessary to create a common derivation scheme that makes use of all new technologies.
@@ -49,17 +50,19 @@ m / purpose' / coin_type' / account' / script_type' / change / address_index
4950

5051
Rather than following in BIP 44/49/84's path and having a separate BIP per script after P2SH (BIP45), vendors decided to insert <code>script_type'</code> into the derivation path (where P2SH-P2WSH=1, P2WSH=2, Future_Script=3, etc). As described previously, this is unnecessary, as the descriptor sets the script. While it attempts to reduce maintainence work by getting rid of new BIPs-per-script, it still requires maintaining an updated, redundant, <code>script_type</code> list.
5152

52-
The structure proposed later in this paper solves these issues and is quite comprehensive. It allows the handling of multiple accounts, external and internal chains per account, and millions of addresses per chain, in a multi-party multisignature hierarchical deterministic wallet regardless of the script type.
53+
The structure proposed later in this paper solves these issues and is quite comprehensive. It allows the handling of multiple accounts, external and internal chains per account, and millions of addresses per chain, in a multi-party multisignature hierarchical deterministic wallet regardless of the script type <ref>**Why propose this structure only for multisignature wallets?** Currently, single-sig wallets are able to restore funds using just the master private key data (in the format of BIP39 usually). Even if the user doesn't recall the derivation used, the wallet implementation can iterate through common schemes (BIP44/49/84). With this proposed hierarchy, the user would either have to now backup additional data (the descriptor), or the wallet would have to attempt all script types for every account level when restoring. Because of this, even though the descriptor language handles the signature type just like it does the script type, it is best to restrict this script-agnostic hierarchy to multisignature wallets only. Co-signers in multisignature wallets need to backup all other cosigner public keys anyway in order to restore, so the descriptor provides this information with the benefit of key origin information and error detection.</ref>.
5354

5455
Any script that is supported by descriptors (and the specific wallet implementation) is compatible with this BIP.
5556

5657
This paper was inspired from BIP44.
5758

58-
==Key sorting==
59+
==Specification==
60+
61+
===Key sorting===
5962

6063
Any wallet that supports descriptors inherently supports deterministic key sorting as per BIP67 (through the <code>sortedmulti</code> function) so that all possible multisignature addresses/scripts are derived from deterministically sorted public keys.
6164

62-
==Path levels==
65+
===Path levels===
6366

6467
We should not be mixing keys and scripts in the same layer. The wallet should create extended private/public keys independent of the script type, whereas the descriptor language tells wallets to watch the multisig outputs with the specified public keys.
6568

@@ -119,6 +122,37 @@ This number is used as child index in BIP32 derivation.
119122

120123
Public derivation is used at this level.
121124

125+
==Address Discovery==
126+
127+
The multisig descriptor that is generated from the cosigners combined key records should be used to generate and discover addresses. For example:
128+
<code>wsh(sortedmulti(2,[xfpForA/XY'/0'/0']XpubA/*,[xfpForB/XY'/0'/0']XpubB/*))#Checksum</code>
129+
130+
# Derive the wallet's first account's node (index = 0)
131+
# Derive the external chain node of this account (index = 0)
132+
# Scan addresses of the external chain; respect the gap limit described below
133+
# If there are some transactions, increase the account index and go to step 2
134+
# If no transactions are found on the external chain, continue to search the following account indexes in compliance with the account gap limit described below.
135+
136+
Please note that the algorithm works with the transaction history, not account
137+
balances, so you can have an account with 0 total coins and the algorithm will
138+
still continue with discovery.
139+
140+
The wallet implementation should scan the accounts and addresses following the parent descriptor string.
141+
142+
===Address Gap Limit===
143+
144+
Address gap limit is currently set to 20. If the software hits 20 unused addresses in a row, it expects there are no used addresses beyond this point and stops searching the address chain. We scan just the external chains, because internal chains receive only coins that come from the associated external chains.
145+
146+
Wallet software should warn when the user is trying to exceed the gap limit on an external chain by generating a new address.
147+
148+
===Account Gap Limit===
149+
150+
Account gap limit is currently set to 5. When the software hits an account that contains 20 unused addresses in a row, it will search the the next 4 accounts (while obeying the address gap limit), before stoping discovery. If any transactions are found during this process, discovery is restarted (after finding 20 unused addresses) on the next account index, and the account gap limit is reset. Only when the address gap limit is found consecutively for the account gap limit is discovery stopped.
151+
152+
==Rationale==
153+
154+
<references/>
155+
122156
==Examples==
123157

124158
{|
@@ -213,8 +247,13 @@ Public derivation is used at this level.
213247
|m / XY' / 1' / 1' / 1 / 1
214248
|}
215249

250+
==Reference Implementation==
251+
252+
None at the moment.
253+
216254
==Acknowledgement==
217255

256+
Special thanks to SomberNight, Craig Raw, David Harding, Jochen Hoenicke, and others for their feedback on the specification.
218257

219258
==References==
220259

0 commit comments

Comments
 (0)