<blockquote>
<p>Does it create a public key based of private?</p>
</blockquote>
<p>Yes, a cryptographic routine exists that computes the public key from the private key.</p>
<blockquote>
<p>maybe on the wallet.dat file?</p>
</blockquote>
<p>All modern wallet software generates keys derministically from some sort of master key, or seed phrase. That master key is stored in the wallet, and all other private keys are derived from it, and the public keys are derived from that. For every new receive address, a distinct key is used. The fact that they're all computed from one piece of data means that a backup of your wallet allows generation of all future addresses - even the ones created after the backup was made.</p>
<blockquote>
<p>How would you be prevented from getting a private key if you have the public key?</p>
</blockquote>
<p>Cryptography. The function to compute the public key from the private is fairly efficient in one direction (~50 microseconds on a modern desktop CPU), but the best known algorithm for going the other way around (<a href="https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm_for_logarithms" rel="noreferrer">Pollard's rho</a>) would take around 300 trillion times the age of the universe on the same computer. With many computers it becomes faster of course, but even billions of times faster isn't remotely close to being able to realistically break any key. The security is based on the assumed hardness of a number theoretical problem, the elliptic curve discrete logarithm problem (<a href="https://en.wikipedia.org/wiki/Elliptic-curve_cryptography" rel="noreferrer">ECDLP</a>).</p>
<blockquote>
<p>and what stops someone from looping over a bunch of private keys to find one with some coins in?</p>
</blockquote>
<p>There are 115792089237316195423570985008687907852837564279074904382605163141518161494336 valid private keys (that's the actual number). Attempts to brute force them are futile due to the sheer number. The duration I gave above doesn't rely on brute force - it uses a much more efficient algorithm. Brute force would be 600 trillion trillion trillion times slower still.</p>

CC BY-SA 4.0
2021-02-06T23:48:07.700Z
Thank you very much! Greatly appreciate the response.
Martin Bradley
CC BY-SA 4.0
2021-02-06T01:40:48.177Z
2021-02-06T02:00:18.947Z
2021-02-06T02:00:18.947Z
Pieter Wuille
<p>It may seem like a vague question, but what I understand so far is, you have a public key (address) which people can send coins too, and then you have the private key which you need to send coins to someone else.</p>
<p>My question is, how does the program itself work?</p>
<p>Does it create a public key based of private? maybe on the wallet.dat file? How would you be prevented from getting a private key if you have the public key? and what stops someone from looping over a bunch of private keys to find one with some coins in?</p>

<wallet><wallet.dat><wallet-security>
How do wallets work?
Martin Bradley
# How do wallets work?

(Asked by: username_0 on 2021-02-06)

It may seem like a vague question, but what I understand so far is, you have a public key (address) which people can send coins too, and then you have the private key which you need to send coins to someone else.

My question is, how does the program itself work?

Does it create a public key based of private? maybe on the wallet.dat file? How would you be prevented from getting a private key if you have the public key? and what stops someone from looping over a bunch of private keys to find one with some coins in?

**Tags:** wallet, wallet.dat, wallet-security


---

## 1 answers

### Answer by username_1 on 2021-02-06. Score: 5

> Does it create a public key based of private?

Yes, a cryptographic routine exists that computes the public key from the private key.

> maybe on the wallet.dat file?

All modern wallet software generates keys derministically from some sort of master key, or seed phrase. That master key is stored in the wallet, and all other private keys are derived from it, and the public keys are derived from that. For every new receive address, a distinct key is used. The fact that they're all computed from one piece of data means that a backup of your wallet allows generation of all future addresses - even the ones created after the backup was made.

> How would you be prevented from getting a private key if you have the public key?

Cryptography. The function to compute the public key from the private is fairly efficient in one direction (~50 microseconds on a modern desktop CPU), but the best known algorithm for going the other way around ([Pollard's rho](https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm_for_logarithms)) would take around 300 trillion times the age of the universe on the same computer. With many computers it becomes faster of course, but even billions of times faster isn't remotely close to being able to realistically break any key. The security is based on the assumed hardness of a number theoretical problem, the elliptic curve discrete logarithm problem ([ECDLP](https://en.wikipedia.org/wiki/Elliptic-curve_cryptography)).

> and what stops someone from looping over a bunch of private keys to find one with some coins in?

There are 115792089237316195423570985008687907852837564279074904382605163141518161494336 valid private keys (that's the actual number). Attempts to brute force them are futile due to the sheer number. The duration I gave above doesn't rely on brute force - it uses a much more efficient algorithm. Brute force would be 600 trillion trillion trillion times slower still.

> **Comments:**
> **username_0**: Thank you very much! Greatly appreciate the response.  

---

