<blockquote>
  <p>Is wallet generates an address from index 1 and scan blockchain whether an address is used or not, until wallet finds an unspent address?</p>
</blockquote>

<p>No. The wallet software generates a seed (pseudo-random). With that seed, it generates private keys. With those private keys, it generates public keys and with those public keys, it generates addresses. And this address is (almost) always unused.</p>

<blockquote>
  <p>and checks whether the index is used or not until it reaches address that has not been used.
  ---- and ----
  If the wallet is stateless, then determining unused address by generating the address from very first and looking up blockchain for the unused address is expensive?</p>
</blockquote>

<p>That's not how it works. The probability to hit an address that is already used (by the method seed->SK->PK->address) is almost 0 because you don't know the seed of other people. You don't need to check that because it's almost impossible (unless you have a lot of computer power and want to waste electricity).</p>

<blockquote>
  <p>Is the wallet keeps state of unused address?</p>
</blockquote>

<p>The wallet simply check the funds of all your addresses, recognizes that your first address is used (has funds on it) and provides you a new one (also created by the same seed (seed->SK->PK->address).</p>

CC BY-SA 3.0
2018-03-01T14:35:52.340Z
I think you did not understand my question or I could not explain it clearly.  I have knowlege of how private key is generated from seed, as it is explained int detail BIP 32.
Infinity
CC BY-SA 3.0
2018-03-01T14:35:57.840Z
Suppose i want to receive payment and i requests wallet to generate new address. I have already suppose recieve or spent amounts corresponding to first 50 addresses. Now this time when i request wallet to generate address, is wallet will generate address1 then checks via blockchain whether it is used or not. If used, then it generates address2 then checks via blockchain whether it is used or not. Until it generates address50 then it finds that address is unused.
Infinity
CC BY-SA 3.0
2018-03-01T14:37:20.093Z
In other words, how does wallet generates an address and finds whether an address is previously used or not
Infinity
CC BY-SA 3.0
2018-03-01T15:08:48.487Z
As far as I know: A HD wallet stores an ID (integer) in the wallet file on your computer. In the beginning, it's 0 => it shows you address1. Then, you get funds on that address => wallet recognizes that if it's synced => It increments the ID => ID is 1 => it shows you a address2 to receive coins.... That should be possible 2^32 times. It does not check the synced blockchain everytime because it knows that you used the first 100 addresses if the stored ID is 100. But if you would remove the wallet data and restore everything from the seed, then it must check all the 100 addresses again.
hardfork
CC BY-SA 3.0
2018-03-01T15:30:44.583Z
Means it store index locally, and each time it refers that index to generate the address. In case it lost index, wallet traverse all indexes from beginning to generate the unused address.
Infinity
CC BY-SA 3.0
2018-03-01T14:26:32.023Z
2018-03-01T14:26:32.023Z
hardfork
<p>As we know, address reusability compromises both privacy and security.</p>
<p>My question is how Bitcoin wallets avoid address reusability?</p>
<p>Is wallet generates an address from index 1 and scan blockchain whether an address is used or not, until wallet finds an unspent address?</p>
<p>In case of <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" rel="nofollow noreferrer">HD</a> wallets, whenever the user requests to generate a new address to receive address. Wallet generates an address from the very first index and checks whether the index is used or not until it reaches address that has not been used.</p>
<p>Is the wallet keeps state of unused address?</p>
<p>If the wallet is stateless, then determining unused address by generating the address from very first and looking up blockchain for the unused address is <strong>expensive</strong>?</p>
<p>I tried to find documentation of wallets such as Ledger, Airbitz, but i did not found it.</p>
<p><strong>Edit:</strong> Note that I have knowledge of how seed, private and public keys are generated, as it is explained in detail BIP 32.</p>
<p>My question here is When a user requests to generate a new address how does wallet find that the address is previously unused?</p>
<p>If wallet generates an address from the very first index, scans blockchain whether the address is previously spent or not? until it finds the index new address to receive payment.</p>

<wallet><security><privacy><address-generation><address-reuse>
How Bitcoin wallets avoid address re-usability?
Infinity
# How Bitcoin wallets avoid address re-usability?

(Asked by: username_0 on 2018-03-01)

As we know, address reusability compromises both privacy and security.

My question is how Bitcoin wallets avoid address reusability?

Is wallet generates an address from index 1 and scan blockchain whether an address is used or not, until wallet finds an unspent address?

In case of [HD](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) wallets, whenever the user requests to generate a new address to receive address. Wallet generates an address from the very first index and checks whether the index is used or not until it reaches address that has not been used.

Is the wallet keeps state of unused address?

If the wallet is stateless, then determining unused address by generating the address from very first and looking up blockchain for the unused address is **expensive**?

I tried to find documentation of wallets such as Ledger, Airbitz, but i did not found it.

**Edit:** Note that I have knowledge of how seed, private and public keys are generated, as it is explained in detail BIP 32.

My question here is When a user requests to generate a new address how does wallet find that the address is previously unused?

If wallet generates an address from the very first index, scans blockchain whether the address is previously spent or not? until it finds the index new address to receive payment.

**Tags:** wallet, security, privacy, address-generation, address-reuse


---

## 1 answers

### Answer by username_1 on 2018-03-01. Score: 1

> Is wallet generates an address from index 1 and scan blockchain whether an address is used or not, until wallet finds an unspent address?

No. The wallet software generates a seed (pseudo-random). With that seed, it generates private keys. With those private keys, it generates public keys and with those public keys, it generates addresses. And this address is (almost) always unused.

> and checks whether the index is used or not until it reaches address that has not been used.
> ---- and ----
> If the wallet is stateless, then determining unused address by generating the address from very first and looking up blockchain for the unused address is expensive?

That's not how it works. The probability to hit an address that is already used (by the method seed->SK->PK->address) is almost 0 because you don't know the seed of other people. You don't need to check that because it's almost impossible (unless you have a lot of computer power and want to waste electricity).

> Is the wallet keeps state of unused address?

The wallet simply check the funds of all your addresses, recognizes that your first address is used (has funds on it) and provides you a new one (also created by the same seed (seed->SK->PK->address).

> **Comments:**
> **username_0**: I think you did not understand my question or I could not explain it clearly.  I have knowlege of how private key is generated from seed, as it is explained int detail BIP 32.  
> **username_0**: Suppose i want to receive payment and i requests wallet to generate new address. I have already suppose recieve or spent amounts corresponding to first 50 addresses. Now this time when i request wallet to generate address, is wallet will generate address1 then checks via blockchain whether it is used or not. If used, then it generates address2 then checks via blockchain whether it is used or not. Until it generates address50 then it finds that address is unused.  
> **username_0**: In other words, how does wallet generates an address and finds whether an address is previously used or not  
> **username_1**: As far as I know: A HD wallet stores an ID (integer) in the wallet file on your computer. In the beginning, it's 0 => it shows you address1. Then, you get funds on that address => wallet recognizes that if it's synced => It increments the ID => ID is 1 => it shows you a address2 to receive coins.... That should be possible 2^32 times. It does not check the synced blockchain everytime because it knows that you used the first 100 addresses if the stored ID is 100. But if you would remove the wallet data and restore everything from the seed, then it must check all the 100 addresses again.  
> **username_0**: Means it store index locally, and each time it refers that index to generate the address. In case it lost index, wallet traverse all indexes from beginning to generate the unused address.  

---

