Ok, so this isn't really a puzzle so much as a math problem that will likely involve looking stuff up unless your computer has the ability to calculate incredibly large and small numbers accurately.
But here's the question. 1,000 sats to the first, best, complete answer (with cited sources if you aren't doing the computations yourself).
Suppose Bitcoin has
N = 2^{256}
possible private keys. Suppose K
private keys are generated, completely at random.-
Derive a formula for the probability of a private key collision (2 or more private keys are the same), in terms of
N
andK
. -
How many private keys would have to be generated for there to be a 0.1% chance of a collision?
-
Assuming 8 billion people in the world, how many keys would each person have to generate for there to be a 0.1% chance of a collision?
I will post a part 2, harder version of the problem later....
1,000 sats paid
\frac{N-1}{N}
. If they are not colliding, then for a third key, the probability of it not colliding with one of the two existing keys is\frac{N-2}{N}
. ForK
keys, the probability of no collision is:P(\bar C) = \frac{N-1}{N}\times\frac{N-2}{N}\times\cdots\times\frac{N-K+1}{N} = \frac{K!\cdot\binom{N}{K}}{N^K}
K!
is the factorial of K and\binom{N}{K}
is the binomial coefficient.P(C) = 1-P(\bar C) = 1-\frac{K!\cdot\binom{N}{K}}{N^K}
N
and the use of factorial and binomial coefficient, this quickly becomes impossible to compute asK
grows, long beforeP(\bar C)
can even be represented as anything less than 1.0 in a standard 64-bit float.K \ll N
, as will be the case here, a very good approximation is:P(C) \approx 1 - e^{-\frac{K(K-1)}{2N}}
1 - x \approx e^{-x}
for|x| \ll 1
. More details on deriving this approximation can be found in the Wikipedia article.P(C) = 0.1\%
, we need to findK
. Using the approximation above:1 - e^{-\frac{K(K-1)}{2N}} \approx 0.1\%
e^{-\frac{K(K-1)}{2N}} \approx 0.999
\frac{K(K-1)}{2N} \approx -\ln(0.999)
K(K-1) \approx -2N\ln(0.999) \approx 2.317000478165382653381910211899300708 \cdot 10^{74}
K \approx 15221696614258814787271388067615960467 \approx 2^{123.5}
N=2^{256}
, approximately2^{123.5}
or 15.2 undecillion (i.e. 15.2 billion billion billion billion) private keys would have to be generated for there to be a 0.1% chance of collision.\frac{K}{8 \cdot 10^9} \approx 1.90 \cdot 10^{27} \approx 2^{90.6}
2^{90.6}
or 1.9 octillion (i.e. 1.9 billion billion billion) keys.2^{95.3}
hashing operations to get to the current block height. In other words, generating the amount of keypairs necessary for a chance of a single collision would require each and every person in the world to perform computational work comparable to that of all PoW performed on Bitcoin to date.2^{256}
valid private keys, there are actually less Bitcoin addresses. For example singlesig native Segwit addresses (bc1q...) are a bech32 representation of a 160 bit hash.2^{160}
different singlesig native Segwit addresses. So the probability of guessing a private key for a certain Segwit address is actually\frac{1}{2^{160}}
.N = 2^{160}
K \approx \sqrt{−2N*ln(0.999)} \approx 2^{75.5}
2^{75.5}
private keys that would have to be generated for there to be a 0.1% chance of a Segwit address collision.\frac{2^{75.51747}}{8*10^9} = 6.759797398 * 10^{12} = 2^{42.62012}
2^{42.6}
or 6.7 trillion keys for there to be a 0.1% chance of a Segwit address collision.N
andK
>:(