Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: racezefi on April 19, 2016, 07:04:14 AM



Title: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: racezefi on April 19, 2016, 07:04:14 AM
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.


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: racezefi on April 19, 2016, 05:20:48 PM
In case anyone is wondering:

https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: bitdumper on April 19, 2016, 05:21:18 PM
Generally it's 20. If 20 address balance is 0 then it's considered that master key was not used.


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: CIYAM on April 19, 2016, 05:24:27 PM
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).


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: danda on April 19, 2016, 05:52:28 PM
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


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: racezefi on April 20, 2016, 09:14:28 PM
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.


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: belcher on April 21, 2016, 03:24:57 PM
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.


Title: Re: When deriving addresses from a PubKey, when to stop checking addresses for BTC?
Post by: luv2drnkbr on April 23, 2016, 03:21:46 PM
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".