Author

Topic: How does the wallets know which addresses to recover in Hardware Wallet recovery (Read 231 times)

sr. member
Activity: 616
Merit: 250
I have been reading the BIP32 proposal explaining how HD works but it didn't mention on any point how one wallet in one phone can recover from a simple mnemonic seed.

   1. Does it just try all possible addresses related to that seed's master key by doing the entire blockchain look up for addresses at the same time ? (This seems impractical imo).

   2. Are there standards on the max nth of address to generate from the wallet side ?


As far as I know there are standard recommendation drafts that determine how to generate it from the wallet side.

You should reach out to the support of the appropriate hardware wallet you are using, like Trezor or similar.
sr. member
Activity: 322
Merit: 363
39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD
Quote
Does it just try all possible addresses related to that seed's master key by doing the entire blockchain look up for addresses at the same time ? (This seems impractical imo).
When a HD wallet syncs it generates a set of addresses from the derivation path m/k'/0/i, then it scans the blockchain for transactions related to those addresses. If there are transactions related to that address (even if the address is empty), it generates more addresses until the gap limit is reached.
The gap limit is a certain number of addresses in a row which have no transactions at all.

Quote
Are there standards on the max nth of address to generate from the wallet side ?
The default gap limit is 20.
Other wallets may have different implementations.
HCP
legendary
Activity: 2086
Merit: 4363
I have been reading the BIP32 proposal explaining how HD works but it didn't mention on any point how one wallet in one phone can recover from a simple mnemonic seed.
   1. Does it just try all possible addresses related to that seed's master key by doing the entire blockchain look up for addresses at the same time ? (This seems impractical imo).
Most wallet implement what is known as the "Gap Limit" method of address generation. Essentially, they will continue to generate (and check) addresses until they have found N consecutive addresses that are "unused". In this instance, "unused" means there are no transactions to said address on the blockchain. It is generally NOT related to current balance... but to whether or not the address shows up in any transactions

For instance, imagine that our Gap Limit was 5... and we had a wallet that looked like this:
Address1 - 2 txes - Balance 0 BTC
Address2 - unused
Address3 - unused
Address4 - 1 tx - Balance 0.1 BTC
Address5 - unused
Address6 - unused
Address7 - unused
Address8 - unused
Address9 - unused
Address10 - 1 tx - Balance 0.1 BTC

With a Gap Limit of 5... during a restore... the wallet would likely stop generating addresses at Address9, and tell us we only have 0.1 BTC, as Address9 would have been the 5th address in a row with no transaction history found.

If the Gap Limit was more than 5, then during the restore, it would also find Address10 and show the full balance of 0.2 BTC.


Quote
   2. Are there standards on the max nth of address to generate from the wallet side ?
Not really... it is usually up to the wallet developer what value they use... and likely related to the wallets system of generating new addresses.

I know that, by default, Electrum uses a Gap Limit of 25 for receive addresses (and only 5 for change addresses). I believe MultiBit HD used to use a Gap Limit of 50 or 100... but MultiBit HD had this weird system where every single time you displayed the "receive" tab, it would generate a new address (regardless of whether or not you wanted a new address). So you could end up with a LOT of unused addresses and large "gaps".

It's a balancing act really... gap limit too large means a long wait for the user while the wallet generates and checks addresses during restore... gap limit too small means you might miss addresses/balance during restore.
hero member
Activity: 854
Merit: 658
rgbkey.github.io/pgp.txt
I believe they generate up to a certain amount by default, that can be configured to be larger if it's not generating all the addresses that you've used.
newbie
Activity: 112
Merit: 0
I have been reading the BIP32 proposal explaining how HD works but it didn't mention on any point how one wallet in one phone can recover from a simple mnemonic seed.

   1. Does it just try all possible addresses related to that seed's master key by doing the entire blockchain look up for addresses at the same time ? (This seems impractical imo).

   2. Are there standards on the max nth of address to generate from the wallet side ?

Jump to: