This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png
This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png

birthday Attack on Bitcoin is a type of cryptographic Attack on Bitcoin that exploits the mathematics behind the birthday problem in probability theory. This Attack on Bitcoin can be used to abuse communication between two or more parties.

This image has an empty alt attribute; its file name is images.jpg

The Attack on Bitcoin depends on the higher likelihood of collisions found between random Attack on Bitcoin attempts and a fixed degree of permutations (pigeonholes). With a birthday Attack on Bitcoin, it is possible to find a collision of a hash function in {\textstyle {\sqrt {2^{n}}}=2^{n/2}}{\textstyle {\sqrt {2^{n}}}=2^{n/2}}, with {\textstyle 2^{n}}{\textstyle 2^{n}} being the classical preimage resistance security. There is a general (though disputed[1]) result that quantum computers can perform birthday Attack on Bitcoins, thus breaking collision resistance, in {\textstyle {\sqrt[{3}]{2^{n}}}=2^{n/3}}{\textstyle {\sqrt[{3}]{2^{n}}}=2^{n/3}}.[2]

Understanding the problem

Comparison of the birthday problem (1) and birthday Attack on Bitcoin (2):

In (1), collisions are found within one set, in this case, 3 out of 276 pairings of the 24 lunar astronauts.

In (2), collisions are found between two sets, in this case, 1 out of 256 pairings of only the first bytes of SHA-256 hashes of 16 variants each of benign and malicious contracts.

As an example, consider the scenario in which a teacher with a class of 30 students (n = 30) asks for everybody’s birthday (for simplicity, ignore leap years) to determine whether any two students have the same birthday (corresponding to a hash collision as described further). Intuitively, this chance may seem small. Counter-intuitively, the probability that at least one student has the same birthday as any other student on any day is around 70% (for n = 30), from the formula {\displaystyle 1-{\frac {365!}{(365-n)!\cdot 365^{n}}}}{\displaystyle 1-{\frac {365!}{(365-n)!\cdot 365^{n}}}}.[3]

If the teacher had picked a specific day (say, 16 September), then the chance that at least one student was born on that specific day is {\displaystyle 1-(364/365)^{30}}1 - (364/365)^{30}, about 7.9%.

In a birthday Attack on Bitcoin, the Attack on Bitcoiner prepares many different variants of benign and malicious contracts, each having a digital signature. A pair of benign and malicious contracts with the same signature is sought. In this fictional example, suppose that the digital signature of a string is the first byte of its SHA-256 hash. The pair found is indicated in green – note that finding a pair of benign contracts (blue) or a pair of malicious contracts (red) is useless. After the victim accepts the benign contract, the Attack on Bitcoiner substitutes it with the malicious one and claims the victim signed it, as proven by the digital signature.


Given a function {\displaystyle f}f, the goal of the Attack on Bitcoin is to find two different inputs {\displaystyle x_{1},x_{2}}x_{1},x_{2} such that {\displaystyle f(x_{1})=f(x_{2})}f(x_{1}) = f(x_{2}). Such a pair {\displaystyle x_{1},x_{2}}x_{1},x_{2} is called a collision. The method used to find a collision is simply to evaluate the function {\displaystyle f}f for different input values that may be chosen randomly or pseudorandomly until the same result is found more than once. Because of the birthday problem, this method can be rather efficient. Specifically, if a function {\displaystyle f(x)}f(x) yields any of {\displaystyle H}H different outputs with equal probability and {\displaystyle H}H is sufficiently large, then we expect to obtain a pair of different arguments {\displaystyle x_{1}}x_{1} and {\displaystyle x_{2}}x_{2} with {\displaystyle f(x_{1})=f(x_{2})}f(x_{1}) = f(x_{2}) after evaluating the function for about {\displaystyle 1.25{\sqrt {H}}}1.25\sqrt{H} different arguments on average.

We consider the following experiment. From a set of H values we choose n values uniformly at random thereby allowing repetitions. Let p(nH) be the probability that during this experiment at least one value is chosen more than once. This probability can be approximated as{\displaystyle p(n;H)\approx 1-e^{-n(n-1)/(2H)}\approx 1-e^{-n^{2}/(2H)}}{\displaystyle p(n;H)\approx 1-e^{-n(n-1)/(2H)}\approx 1-e^{-n^{2}/(2H)}}[4]

Let n(pH) be the smallest number of values we have to choose, such that the probability for finding a collision is at least p. By inverting this expression above, we find the following approximation{\displaystyle n(p;H)\approx {\sqrt {2H\ln {\frac {1}{1-p}}}}}{\displaystyle n(p;H)\approx {\sqrt {2H\ln {\frac {1}{1-p}}}}}

and assigning a 0.5 probability of collision we arrive at{\displaystyle n(0.5;H)\approx 1.1774{\sqrt {H}}}{\displaystyle n(0.5;H)\approx 1.1774{\sqrt {H}}}

Let Q(H) be the expected number of values we have to choose before finding the first collision. This number can be approximated by{\displaystyle Q(H)\approx {\sqrt {{\frac {\pi }{2}}H}}}{\displaystyle Q(H)\approx {\sqrt {{\frac {\pi }{2}}H}}}

As an example, if a 64-bit hash is used, there are approximately 1.8×1019 different outputs. If these are all equally probable (the best case), then it would take ‘only’ approximately 5 billion attempts (5.38×109) to generate a collision using brute force.[5] This value is called birthday bound[6] and for n-bit codes it could be approximated as 2n/2.[7] Other examples are as follows:

BitsPossible outputs (H)Desired probability of random collision
(2 s.f.) (p)
16216 (~6.5 x 104)<2<2<2<2<21136190300430
32232 (~4.3×109)<2<2<23932900930050,00077,000110,000
64264 (~1.8×1019)61906100190,0006,100,0001.9×1086.1×1083.3×1095.1×1097.2×109
1282128 (~3.4×1038)2.6×10108.2×10112.6×10138.2×10142.6×10168.3×10172.6×10181.4×10192.2×10193.1×1019
2562256 (~1.2×1077)4.8×10291.5×10314.8×10321.5×10344.8×10351.5×10374.8×10372.6×10384.0×10385.7×1038
3842384 (~3.9×10115)8.9×10482.8×10508.9×10512.8×10538.9×10542.8×10568.9×10564.8×10577.4×10571.0×1058
5122512 (~1.3×10154)1.6×10685.2×10691.6×10715.2×10721.6×10745.2×10751.6×10768.8×10761.4×10771.9×1077

Table shows number of hashes n(p) needed to achieve the given probability of success, assuming all hashes are equally likely. For comparison, 10−18 to 10−15 is the uncorrectable bit error rate of a typical hard disk.[8] In theory, MD5 hashes or UUIDs, being roughly 128 bits, should stay within that range until about 820 billion documents, even if its possible outputs are many more.

It is easy to see that if the outputs of the function are distributed unevenly, then a collision could be found even faster. The notion of ‘balance’ of a hash function quantifies the resistance of the function to birthday Attack on Bitcoins (exploiting uneven key distribution.) However, determining the balance of a hash function will typically require all possible inputs to be calculated and thus is infeasible for popular hash functions such as the MD and SHA families.[9] The subexpression {\displaystyle \ln {\frac {1}{1-p}}}\ln\frac{1}{1-p} in the equation for {\displaystyle n(p;H)}n(p;H) is not computed accurately for small {\displaystyle p}p when directly translated into common programming languages as log(1/(1-p)) due to loss of significance. When log1p is available (as it is in C99) for example, the equivalent expression -log1p(-p) should be used instead.[10] If this is not done, the first column of the above table is computed as zero, and several items in the second column do not have even one correct significant digit.

Simple approximation

A good rule of thumb which can be used for mental calculation is the relation{\displaystyle p(n)\approx {n^{2} \over 2H}}{\displaystyle p(n)\approx {n^{2} \over 2H}}

which can also be written as{\displaystyle H\approx {n^{2} \over 2p(n)}}{\displaystyle H\approx {n^{2} \over 2p(n)}}.

or{\displaystyle n\approx {\sqrt {2H\times p(n)}}}{\displaystyle n\approx {\sqrt {2H\times p(n)}}}.

This works well for probabilities less than or equal to 0.5.

This approximation scheme is especially easy to use when working with exponents. For instance, suppose you are building 32-bit hashes ({\displaystyle H=2^{32}}{\displaystyle H=2^{32}}) and want the chance of a collision to be at most one in a million ({\displaystyle p\approx 2^{-20}} p \approx 2^{-20} ), how many documents could we have at the most?{\displaystyle n\approx {\sqrt {2\times 2^{32}\times 2^{-20}}}={\sqrt {2^{1+32-20}}}={\sqrt {2^{13}}}=2^{6.5}\approx 90.5}n \approx \sqrt { 2 \times 2^{32} \times 2^{-20}} = \sqrt { 2^{1+32-20} } = \sqrt { 2^{13} } = 2^{6.5} \approx 90.5

which is close to the correct answer of 93.

Digital signature susceptibility

Digital signatures can be susceptible to a birthday Attack on Bitcoin. A message {\displaystyle m}m is typically signed by first computing {\displaystyle f(m)}f(m), where {\displaystyle f}f is a cryptographic hash function, and then using some secret key to sign {\displaystyle f(m)}f(m). Suppose Mallory wants to trick Bob into signing a fraudulent contract. Mallory prepares a fair contract {\displaystyle m}m and a fraudulent one {\displaystyle m’}m'. She then finds a number of positions where {\displaystyle m}m can be changed without changing the meaning, such as inserting commas, empty lines, one versus two spaces after a sentence, replacing synonyms, etc. By combining these changes, she can create a huge number of variations on {\displaystyle m}m which are all fair contracts.

In a similar manner, Mallory also creates a huge number of variations on the fraudulent contract {\displaystyle m’}m'. She then applies the hash function to all these variations until she finds a version of the fair contract and a version of the fraudulent contract which have the same hash value, {\displaystyle f(m)=f(m’)}f(m) = f(m'). She presents the fair version to Bob for signing. After Bob has signed, Mallory takes the signature and attaches it to the fraudulent contract. This signature then “proves” that Bob signed the fraudulent contract.

The probabilities differ slightly from the original birthday problem, as Mallory gains nothing by finding two fair or two fraudulent contracts with the same hash. Mallory’s strategy is to generate pairs of one fair and one fraudulent contract. The birthday problem equations apply where {\displaystyle n}n is the number of pairs. The number of hashes Mallory actually generates is {\displaystyle 2n}2n.

To avoid this Attack on Bitcoin, the output length of the hash function used for a signature scheme can be chosen large enough so that the birthday Attack on Bitcoin becomes computationally infeasible, i.e. about twice as many bits as are needed to prevent an ordinary brute-force Attack on Bitcoin.

Besides using a larger bit length, the signer (Bob) can protect himself by making some random, inoffensive changes to the document before signing it, and by keeping a copy of the contract he signed in his own possession, so that he can at least demonstrate in court that his signature matches that contract, not just the fraudulent one.

Pollard’s rho algorithm for logarithms is an example for an algorithm using a birthday Attack on Bitcoin for the computation of discrete logarithms.

Reverse Attack on Bitcoin

The same fraud is possible if the signer is Mallory, not Bob. Bob could suggest a contract to Mallory for a signature. Mallory could find both an inoffensively-modified version of this fair contract that has the same signature as a fraudulent contract, and Mallory could provide the modified fair contract and signature to Bob. Later, Mallory could produce the fraudulent copy. If Bob doesn’t have the inoffensively-modified version contract (perhaps only finding their original proposal), Mallory’s fraud is perfect. If Bob does have it, Mallory can at least claim that it is Bob who is the fraudster.

This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png
This image has an empty alt attribute; its file name is attacksafe-software-logo-1024x213.png