Hash Collision
Two different inputs producing the same hash output, which would break the assumptions signatures rely on.
Basically
A hash is a digital fingerprint for data. A collision means two different pieces of data get the same fingerprint.
Key Takeaways
- A hash collision happens when two distinct inputs produce the same output from a hash function. Collisions are mathematically inevitable under the pigeonhole principle, but cryptographic hash functions are designed to make finding them computationally infeasible.
- The birthday paradox limits collision resistance to half the hash output's bit length. SHA-256 therefore provides 128-bit collision resistance, requiring approximately 2^128 operations to find a collision.
- Bitcoin uses double-SHA-256 to protect against length extension attacks, not to strengthen collision resistance. Practical SHA-256 collisions would threaten Merkle trees, transaction IDs and block header integrity across the network.
What Is a Hash Collision?
A hash collision occurs when two different inputs, x and y, produce the same hash output: H(x) = H(y). A hash function maps an arbitrarily large input space to a fixed-size output. The pigeonhole principle therefore guarantees collisions: if there are more possible inputs than outputs, some inputs must share an output.
Cryptographic security depends on collisions being unfindable, not impossible. A well-designed hash function such as SHA-256 makes collision discovery so computationally expensive that no attacker can succeed with current or foreseeable technology. When a hash function loses this property, as MD5 and SHA-1 both did, every system that relies on it becomes vulnerable.
How It Works
Hash functions have three distinct security properties. You need to distinguish them to understand why collisions matter.
Collision resistance is the weakest of these properties. An attacker who can find collisions may be able to forge documents, certificates or transactions that appear legitimate under a hash-based verification scheme.
The Birthday Paradox
The birthday paradox is the mathematical principle behind collision attacks. In a room of just 23 people, there is a greater than 50% chance that two people share a birthday. The result feels counterintuitive because you may think about someone sharing your specific birthday, while the actual question is whether any pair matches.
An n-bit hash has 2^n possible outputs, but you only need approximately 2^(n/2) random inputs before a collision becomes likely. The square-root relationship means collision resistance is always half the output length in bits.
A birthday attack systematically exploits this bound by generating large numbers of candidate inputs, hashing each one and checking for matches. The attack is generic and works against any hash function, regardless of its internal design.
Why Differential Cryptanalysis Beats the Birthday Bound
The birthday bound represents the best a generic attack can do. Specialised techniques such as differential cryptanalysis can find collisions faster by exploiting the internal structure of a specific hash algorithm. Real-world collision attacks against MD5 and SHA-1 succeeded through mathematical shortcuts within the algorithm itself, not brute force.
MD5: From Standard to Broken
MD5 is a 128-bit hash published by Ronald Rivest in 1991, and its history shows how collision resistance degrades over time. Hans Dobbertin found collisions in MD5's compression function in 1996. In 2004, Xiaoyun Wang and colleagues demonstrated practical full MD5 collisions requiring only about 2^39 operations, executable in under an hour.
MD5 collisions could be generated in under a minute on a standard laptop by 2006. In 2008, researchers used a chosen-prefix collision attack to forge a Certificate Authority (CA) certificate, enabling man-in-the-middle attacks against HTTPS; in 2012, the Flame malware used a novel MD5 collision technique to forge a Microsoft code-signing certificate, distributing malware disguised as a legitimate Windows Update. Today, MD5 collisions can be produced in seconds on commodity hardware.
SHA-1: The SHAttered Attack
SHA-1 (160-bit) was the dominant cryptographic hash for over a decade. In February 2017, researchers from CWI Amsterdam and Google published the SHAttered attack, producing two visually distinct PDF files with the same SHA-1 hash. The attack required approximately 2^63.1 SHA-1 computations, well below the theoretical birthday bound of 2^80, by using differential cryptanalysis to find shortcuts.
The computational cost was approximately 6,500 CPU-years and 110 GPU-years, with an estimated cost of around $110,000 on cloud infrastructure. The attack was expensive but more than 100,000 times faster than a brute-force birthday attack. The demonstration confirmed that SHA-1 was no longer safe for any application requiring collision resistance.
Why Bitcoin Uses Double-SHA-256
Bitcoin hashes block headers, transaction IDs and Merkle tree nodes using double-SHA-256, which applies SHA-256 twice as SHA-256(SHA-256(data)). A common misconception is that this doubles collision resistance. Double hashing still provides 128-bit collision security, the same as single SHA-256.
The actual purpose is protection against length extension attacks. SHA-256 uses the Merkle-Damgård construction, which has a structural vulnerability: an attacker who knows H(message) can compute H(message // padding // extra_data) without knowing the original message. A second round of SHA-256 resets the internal state and eliminates this attack vector entirely.
Ferguson and Schneier proposed this defence in their book "Practical Cryptography" years before Bitcoin's genesis block in 2009. They named the construction SHA-256d, and Satoshi Nakamoto adopted it throughout the Bitcoin protocol.
What Happens If SHA-256 Collision Resistance Breaks
Practical SHA-256 collisions would have severe implications for Bitcoin. Merkle trees, transaction IDs and block header integrity across the network would all be threatened.
Satoshi Nakamoto addressed this scenario directly, writing that Bitcoin could transition to a new hash function after a specified block height if SHA-256 were ever compromised. All nodes would need to upgrade before that block, and old block hashes could be hardcoded to prevent retroactive substitution attacks. Such a change would require BIPs and a hard fork.
Current State of SHA-256 Security
Full SHA-256 (64 rounds) remains unbroken. No practical collision or preimage attack exists against the complete algorithm.
The most significant cryptanalytic progress came at ASIACRYPT 2024. Researchers demonstrated the first practical collision for 31-step SHA-256 out of 64 total steps, computed in 1.2 hours using 64 threads. The result improved the previous best practical collision attack by three steps, jumping from the 28-step result published at EUROCRYPT 2013.
Reaching 31 of 64 steps is notable progress, but each additional step increases difficulty dramatically. The gap between 31 and 64 steps represents an enormous security margin. SHA-256 remains the foundation of Bitcoin's cryptographic security, with no foreseeable practical threat from classical computing.
Quantum Computing Implications
Quantum computers introduce new attack vectors against hash functions through specialised algorithms. For collision resistance, the Brassard-Hoyer-Tapp (BHT) algorithm from 1997 offers a cube-root speedup.
Grover's algorithm halves the bit security of preimage attacks, reducing SHA-256 from 2^256 to 2^128, which remains computationally secure. The BHT algorithm reduces collision resistance from 2^128 to approximately 2^85. The reduction is meaningful, but 2^85 operations with quantum hardware remain far beyond current or near-term capabilities.
A critical practical constraint is that the BHT algorithm requires enormous quantum random-access memory (QRAM): finding SHA-256 collisions would need approximately 2^85 hash outputs stored in QRAM, which is astronomically beyond any foreseeable quantum hardware. Research into post-quantum cryptography continues, but NIST considers SHA-256 and longer hash functions secure for the foreseeable future. For further analysis, see post-quantum threats to Bitcoin.
Use Cases for Collision Resistance
Collision resistance is not an abstract concern. It underpins the security of systems that billions of people rely on.
Gradual Degradation, Not Sudden Failure
Hash function security does not break overnight. MD5 took 13 years from its first compression-function weakness in 1996 to weaponised real-world exploitation through the Flame malware in 2012, while SHA-1 took over a decade from theoretical weaknesses to the SHAttered demonstration in 2017. Reduced-round attacks on SHA-256, currently at 31 of 64 steps, are therefore an early warning signal worth monitoring, not an imminent threat.
Cryptographic Agility
Systems that hardcode a single hash function face upgrade risks if that function weakens. Cryptographic agility is the ability to swap algorithms without redesigning the entire system, providing insurance against future breakthroughs. Bitcoin's reliance on SHA-256 throughout its protocol stack makes a hash migration particularly complex, requiring coordinated network-wide upgrades via a hard fork.
Collision vs. Preimage Attacks in Practice
Not every application that uses a hash function requires collision resistance. Proof-of-work mining requires preimage-like properties, meaning finding an input below a target, rather than collision resistance, so an attacker who can find SHA-256 collisions cannot mine blocks any faster. Proof of work remains secure against collision attacks specifically, though it faces separate considerations from quantum preimage speedups via Grover's algorithm.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.