Author

Topic: When deriving addresses from a PubKey, when to stop checking addresses for BTC? (Read 1097 times)

hero member
Activity: 793
Merit: 1016
The standard for most HD wallets is some variant of this:

Main account:  m/0/i
Change account:  m/1/i

where i is an index number, and starts at 0.

Some wallets use longer ones, like m/44'/0'/0'/0/i for main, and m/44'/0'/0'/1/i for change, but you can see the last three parts of the string still have the general format of "m/0/i" (from m/44'/0'/0'/0/i) and "m/1/i" (from m/44'/0'/0'/1/i).

The standard way to scan it is:  You increment i and scan until you find 20 consecutive addresses with no transaction history (not just 0 balance, but no history either), and then you assume that there's nothing more after that.  You do that for the main and for the change account.

That number 20 is arbitrary but is the standard used by most places, and it is referred to as the "gap limit".
sr. member
Activity: 261
Merit: 518
There is the concept of a gap limit.

It is explained here because it's also used in JoinMarket https://github.com/JoinMarket-Org/joinmarket/wiki/Using-the-JoinMarket-internal-wallet#what-is-the-gap-limit

It's generally a good idea for it to be configurable so users recovering wallets can try different values.
member
Activity: 80
Merit: 14
The default is to stop after 20.   Unfortunately some wallet software such as very old versions of Copay generated a new address each time the user clicks "receive" button, and therefore may have gaps larger than 20.   As far as I know, they all use contiguous addresses.  Also, if you need change addresses you must check (relative) 1/n in addition to 0/n.

If you're just looking for a quick tool for wallet discovery, you may find this helpful:
CLI: https://github.com/dan-da/hd-wallet-addrs
Web: https://mybitprices.info/hd-wallet-addrs.html

That's very useful, thanks, danda!

Thanks everyone for their input.
full member
Activity: 201
Merit: 157
The default is to stop after 20.   Unfortunately some wallet software such as very old versions of Copay generated a new address each time the user clicks "receive" button, and therefore may have gaps larger than 20.   As far as I know, they all use contiguous addresses.  Also, if you need change addresses you must check (relative) 1/n in addition to 0/n.

If you're just looking for a quick tool for wallet discovery, you may find this helpful:
CLI: https://github.com/dan-da/hd-wallet-addrs
Web: https://mybitprices.info/hd-wallet-addrs.html
legendary
Activity: 1890
Merit: 1072
Ian Knowles - CIYAM Lead Developer
Generally it's 20. If 20 address balance is 0 then it's considered that master key was not used.

It's not address balance but usage history that matters (as of course the balance might be zero for thousands of used addresses).

(i.e. the algorithm will be searching the spent as well as unspent outputs)

Unfortunately those with ad-sigs tend to post incorrect things (as all they care about is getting paid to post).
sr. member
Activity: 266
Merit: 250
One world One currency, Bitcoin.
Generally it's 20. If 20 address balance is 0 then it's considered that master key was not used.
member
Activity: 80
Merit: 14
Hey people, what's up?

Let's say you are deriving the path m/0/0/.
When do you stop deriving addresses and checking their balance? Do all HD implementations (Electrum, myCelium, MultibitHD) use contiguous indexes when creating a new address?

Example, m/0/0/0, m/0/0/1, m/0/0/2.

Hope I'm being clear.

Thanks.
Jump to: