Bitcoin Forum
May 21, 2024, 03:39:08 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How does wallet recovery work?  (Read 99 times)
chrisotherwise (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
September 13, 2022, 07:59:10 AM
 #1

When I recover a wallet from a seed I end up with a master private key. That key is then used to generate other private keys. How does the wallet software know which private keys to generate, which are in use, and when to stop generating them? Surely it could generate an infinite number? Say I'd done 10,000 transactions in my wallet so there were 10,000 private keys. How would it know just to generate those 10,000?
NeuroticFish
Legendary
*
Offline Offline

Activity: 3682
Merit: 6406


Looking for campaign manager? Contact icopress!


View Profile
September 13, 2022, 08:33:55 AM
 #2

When I recover a wallet from a seed I end up with a master private key. That key is then used to generate other private keys. How does the wallet software know which private keys to generate, which are in use, and when to stop generating them? Surely it could generate an infinite number? Say I'd done 10,000 transactions in my wallet so there were 10,000 private keys. How would it know just to generate those 10,000?

I think that you've used the wrong word. Recovery is usually about finding removed wallets removed on HDDs. I think that you've meant restore from seed.

Wallets don't just generate randomly 1000s of addresses, there's a rather low gap limit, making only some tens of addresses being generated ad first. Then, when those addresses are all used, more will be generated, but, again, not too many.
My guess is that at restoring the wallet will pretty much do the same: generate the first tens of addresses, check if they're used, if so generate some more tens and so on, until it gets to a "gap" that's not used at all, then stops.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10566



View Profile
September 13, 2022, 11:35:12 AM
Merited by hosseinimr93 (1)
 #3

How does the wallet software know which private keys to generate,
There are standards that most wallets follow in order to decide what BIP32 derivation path to use to derive each child key.
Sometimes the software has to ask you the type of address to set that derivation path or lets you enter it manually.
Sometimes they modify the mnemonic (like Electrum) to already include that information.

Quote
which are in use, and when to stop generating them?
The software usually has a hard coded max/cap constant that it uses to decide how many keys to derive at first. Like 20. Then they usually check if these addresses are used before, if they are then they derive more keys and check those too until it reaches an unused set of keys to stop.
The software usually has an option to manually set this value (eg. setting gap in Electrum).

Quote
Surely it could generate an infinite number?
Technically the number of keys is finite Roll Eyes

Quote
Say I'd done 10,000 transactions in my wallet so there were 10,000 private keys. How would it know just to generate those 10,000?
It will generate 20 keys, sees they are used so derives 20 more and continues until it reaches 10,020th key and sees that the last 20 keys were not used.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
chrisotherwise (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
September 13, 2022, 11:39:45 AM
 #4

Say I'd done 10,000 transactions in my wallet so there were 10,000 private keys. How would it know just to generate those 10,000?
It will generate 20 keys, sees they are used so derives 20 more and continues until it reaches 10,020th key and sees that the last 20 keys were not used.


So If I generate 25 keys in my wallet but don't use them, then generate some more and *do* use them, this gap might mean that my wallet could not be rebuilt successfully?

pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10566



View Profile
September 13, 2022, 11:47:52 AM
 #5

So If I generate 25 keys in my wallet but don't use them, then generate some more and *do* use them, this gap might mean that my wallet could not be rebuilt successfully?
Yes, since the wallet can not guess that you did something that is not the default behavior of the wallet software. Which is why they offer the option to manually modify that limit.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
chrisotherwise (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
September 13, 2022, 11:50:08 AM
 #6

So If I generate 25 keys in my wallet but don't use them, then generate some more and *do* use them, this gap might mean that my wallet could not be rebuilt successfully?
Yes, since the wallet can not guess that you did something that is not the default behavior of the wallet software. Which is why they offer the option to manually modify that limit.

Ok, got it, thanks for the clear explanation.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!