Brute Force Bitcoin

Blog

A Private Key Is Just A Number

Every bitcoin is guarded by a number. Here is what that number is, how it turns into an address, and why the board keeps throwing them away.

Bitcoin has no accounts and no passwords. It has numbers. Every coin sits at an address, and every address answers to one secret number called a private key. Whoever knows the number can spend what the address holds. There is nobody to call if you lose it, and nobody to stop someone who finds it.

Any number will do

A private key is a whole number from 1 up to just below this one:

115,792,089,237,316,195,423,570,985,008,687,907,852,837,564,279,074,904,382,605,163,141,518,161,494,337

That is the order of secp256k1, the curve Bitcoin uses. It has 78 digits. Pick any whole number below it, other than zero, and you have a perfectly valid key. Nobody issues them and nobody keeps a list. Your wallet simply picks one at random.

The board writes keys the way software usually does, in hexadecimal: 64 characters from 0 to 9 and a to f. It is the same number, written in base 16 instead of base 10, split into groups of eight so a human can look at it.

From number to address

Turning a key into an address takes three steps, and each one only works in one direction.

  1. Multiply a point on a curve. The key is multiplied by a fixed starting point on the secp256k1 curve. The result is another point: the public key. Going forwards takes a laptop a fraction of a millisecond. Going backwards, from the public key to the number, is the problem nobody knows how to solve.
  2. Hash it twice. The public key goes through SHA-256 and then RIPEMD-160, which squeezes it into 160 bits. Hashes are one-way too: you cannot run them backwards to find what went in.
  3. Write it down. Those 160 bits are spelled out with a checksum as an address: one starting with 1, 3 or bc1q, depending on the format.

One key can make several addresses this way. The board checks four of them for every key: the legacy address from the compressed public key (what wallets have made since about 2012), the legacy address from the uncompressed one (what the very first wallets made), the native SegWit address, and the wrapped SegWit address.

What guessing means

So guessing a key is not hacking anything. It is the same thing a wallet does when it makes a key: pick a number, do the arithmetic, look at the address. The only difference is that you then check whether the address happens to belong to somebody rich.

That is exactly what the board does, hundreds of thousands of times a second. Every key comes from your browser's own random number generator, crypto.getRandomValues, the one built for cryptography. It is checked against the richest million funded addresses and then thrown away. It never leaves the page.

Some numbers really are taken

Not every key is safe. The number 1 is a valid key, and its address, 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH, has been through about two hundred transactions. Anything ever sent there was taken within moments, because everyone who has ever played with keys tries 1 first. The same goes for 2, 3, and every number a person might pick on purpose.

The danger is never a random key. It is a key that was not really random. That story is its own article: What Actually Breaks Bitcoin Wallets.

Next: How Big Is 2256?