Bitcoin and SHA-256: what if the hash function fell
How badly Bitcoin would suffer if SHA-256 were broken depends on exactly what fell: a collision would cause mainly confusion, a fast preimage search would endanger mining, and a quantum computer would speed the search up only a little. And for the full SHA-256 nobody today knows an attack faster than brute force, that is, plain trying; reports of its “weakness” so far concern shortened versions. SHA-256 is a mill that Bitcoin could not do without. You pour any data into it and out comes a hash, a string of 64 characters that stands for the data as a fingerprint stands for a person. The same data always give the same hash, even a tiny change gives a completely different one, and from the hash you cannot work your way back to the data. That is why Bitcoin needs it: whoever changes the data changes the hash too, and the fraud shows.
Why know this? From time to time a headline appears such as “researchers have broken SHA-256”, and straight after it the question of whether it is the end of Bitcoin.
Where Bitcoin computes hashes
Think of Bitcoin as a ledger of payments kept jointly by thousands of computers around the world, the so-called nodes. Each holds a copy of the ledger and checks that payments follow the rules. Payments are written into it in bundles called blocks, roughly one every ten minutes. SHA-256 works in it in three places:
- The block header. Each block carries a short label, the header, 80 bytes long. Miners compute a hash from it, and do so twice in a row: SHA-256 of the header and then SHA-256 of the result. The block is valid only if the hash comes out small enough, that is, begins with a long run of zeros. Such a hash can be found only by enormous trial and error, and that is why it is proof of work done. How it is found is described in the part on Bitcoin mining. The header also contains the hash of the previous block, and that is what links the blocks into a chain.
- The tree of payments. The thousands of payments in a block are condensed into a single hash that fits into the header. The hashes of the payments are paired up, a new hash is computed from each pair, those are paired up again, and so on until one is left. This is called a Merkle tree, and the part on the blockchain goes into it in more detail.
- The address. The owner of coins has a secret number, the private key, with which they sign payments. From it the public key is made, with which anyone can check the signature. The address is a hash of the public key: SHA-256 is computed from the key, and from the result another hash by a second function, RIPEMD-160, which gives a shorter hash of 160 bits. The result is called HASH160, and the Bitcoin address is built from it.
That Bitcoin computes the header and the tree with a double SHA-256 and the address with SHA-256 and RIPEMD-160 is described in the developer documentation at developer.bitcoin.org and on the wiki Bitcoin Wiki (checked in December 2026).
Collision or preimage
An attacker has three routes against a hash function. We rank them from hardest to easiest:
- Preimage. Eva knows only the hash and looks for data that produce it. For instance for the hash of somebody else’s address.
- Second preimage. Eva knows the whole message, say Adam’s payment, and looks for a different message with the same hash.
- Collision. Eva looks for any two different messages with the same hash. She chooses both herself.
A collision sounds almost the same as a second preimage, but it is much easier. We can convince ourselves of that. A full SHA-256 hash has 256 bits; a bit is a single zero or one. Nobody has time for that many attempts, so we cut the hash down to its first 16 bits. Sixteen zeros and ones give 216 = 65,536 possibilities, and they are written as the first four characters of the hash. A hash is written with the characters 0–9 and a–f, and each character carries four bits; that is why the whole hash has 64 characters.
Collision. We hash the messages “Adam posílá Báře 1 Kč” (Czech for “Adam sends Bára 1 koruna”), “Adam posílá Báře 2 Kč” and so on, and watch whether the shortened hash repeats. The first match came at message number 405. Its hash begins 4fc3, just like that of message number 209:
Preimage. And now the other way round. The message “Adam posílá Báře 1 Kč” has a hash beginning 8343, and Eva wants her own message with the same beginning. She tries “Eva posílá Evě 1 Kč” (“Eva sends Eva 1 koruna”), “Eva posílá Evě 2 Kč”… (writing the numbers without separators). She hit it only with the message “Eva posílá Evě 49131 Kč”, after 49,131 attempts. That is a hundred times more work than for the collision, with a hash that is equally short.
Where does that difference come from? Eva, searching for a preimage, compares each new message with a single hash. Each attempt has a chance of
pairs. For 405 messages that is
So by the 405th message a collision has appeared in about 71% of cases, on average already at the 321st message. Chance did not favour us much this time. When we repeated the experiment a thousand times with different messages, an average of 317 messages was enough. That is no contradiction, just chance: a thousand experiments give an average close to 321, not exactly 321.
Why the square root? n messages give roughly n2/2 pairs, and once there are about as many pairs as possible hashes, a collision is already more likely than not. It therefore arrives after about the square root of the number of hashes:
A SHA-256 collision costs roughly 2128 attempts, a preimage and a second preimage 2256. The part on Bitcoin’s security converts those numbers into years: for 2128 steps the whole mining network, which today computes nearly a sextillion hashes per second, would need about 11 billion years.
What a collision would mean
Of the three attacks, a collision is the easiest, but it would harm Bitcoin the least. The attacker chooses both messages, so a collision gives them only two of their own messages with the same hash. It does not reach somebody else’s payment, for which they would have to find a second preimage.
What could they do with it? For example, make two payments with the same hash and get one of them into a block. The tree of payments is built only from hashes, so its root in the header would fit both payments, and with it the number found in the header that gives a hash with zeros. Two versions of the same block would arise, and each would look valid. Nodes might argue about which version they saw, and a merchant might not know what they had actually received. It would be confusion and probably fraud with the attacker’s own coins, not theft of other people’s. Only with payments signed by several people could the attacker get the others to sign the honest version and then use the signature for the other one.
More sensitive are the shared “two of three” addresses, where a founder could slip the others a different condition with the same hash; that is why they have the newer hash of 256 bits, as the part on Bitcoin’s security describes.
What a preimage would mean
One floor up lies the preimage, and here things get serious.
Mining. A miner looks for a header whose hash comes out smaller than the target number. That is a preimage search, only not for a single hash but for a whole group of small hashes. Today nobody knows a shortcut and all that is left is trying. But whoever searched for preimages faster would mine many times more briskly than the others. It would be enough for them to keep the shortcut secret: they alone would have more power than the rest of the network and could rewrite fresh payments, as the part on the 51% attack describes. If the shortcut were published, everybody would use it and the difficulty would go up. Then it would depend on how much the shortcut saved.
Addresses. A preimage alone would not be enough for those. The attacker would find some data for the hash of an address, but to spend coins they do not need data, they need a public key for which they know the private key. And a public key is worked out from a private key in one direction only, so a preimage that did not arise from their own key is of no use to them. They would have to be able to find a preimage among the hashes of keys they make themselves, and that is a much harder task.
History. A second preimage would let them find, for somebody else’s old payment, another one with the same hash. The tree of payments and the header hash with zeros would both fit it, and the attacker could slip it to a node that is only now downloading the history. But it would have to be a valid payment with correct signatures, not random data, which makes the task harder still.
How far away is a break of SHA-256
That hash functions really do fall is shown by MD5 (2004) and SHA-1 (2017), as the article on hash functions describes in detail. In both cases it was collisions, the easiest of the three tasks.
SHA-256 holds. As of December 2026 nobody knows an attack on the full function faster than brute force, not even for collisions. Researchers therefore try shortened versions. SHA-256 mixes the data in 64 repetitions, rounds, and in 2026 a truly computed collision for a version cut down to 35 rounds appeared at conferences, and a theoretical one for 37, that is, an attack faster than brute force that nobody can yet actually compute. A large margin remains up to the full 64 rounds, as the part on Bitcoin’s security shows. For SHA-1, twelve years passed between the first theoretical attack and a real collision. If SHA-256 began to crack, we would probably know long in advance.
Grover’s algorithm
That leaves the quantum computer. For Bitcoin’s signatures, which are built on elliptic curves, a large enough quantum computer would have Shor’s algorithm, a quantum method that breaks them completely, as the part on quantum computers and Bitcoin describes. Against hash functions, though, it lacks a similar weapon. It is left with the more general Grover’s algorithm, which can do one thing only: search a large heap faster than trying one possibility after another.
How much faster? When there are N possibilities, an ordinary computer goes through half of them on average. Grover needs roughly
With real numbers it looks alarming: a SHA-256 preimage would cost, instead of 2256 steps, only
But 2128 is exactly what a collision costs today, those 11 billion years. That is why for hash functions a longer hash is enough, just as a longer key is enough for the AES cipher. For the 160-bit hash of an address Grover would bring the preimage down from 2160 to 280. A quantum attacker would not break an address this way, though: whoever pays from an address has to reveal their public key, and from it Shor’s algorithm would work out the private key far more easily.
But Grover has two snags.
It does not split up well. Its steps follow one another and none can be skipped. Ordinary searching can be divided among a hundred computers and finished a hundred times sooner. Dividing Grover among k quantum computers helps only by the square root of k: a hundred quantum computers are only
Quantum steps are slow. Mining shows this well. For one block the network today needs on average 6.2 · 1023 attempts (the calculation is in the part on mining). Grover would get by with the square root, about 790 billion steps, but those follow one another and must fit into ten minutes. That is over a billion steps per second, and each one means computing a whole double SHA-256 on a quantum chip without errors. According to an analysis from 2017 (published in the journal Ledger in 2018, arXiv), such a step is so slow that a quantum miner would be more than a thousand times slower than one ordinary mining machine of the time. And it would need millions of qubits, which did not exist then and do not exist now. In 2017 the authors estimated that SHA-256 in Bitcoin would stay resistant to quantum computers for at least ten years.
What would be done
If SHA-256 began to give way, Bitcoin would have to replace it, and at each of the three places the replacement would look different. Addresses and payments can be converted to a new function much as to new signatures: a new kind of address is added and people gradually move their coins to it. Such a change can be introduced as a soft fork: the rules are merely tightened and old nodes go on accepting new blocks, as the part on post-quantum Bitcoin describes.
Mining is a tougher nut to crack. If blocks had to have a small hash under a different function, the old program would reject them, because their SHA-256 hash would not be small. Such a change is called a hard fork, and everybody has to update the program. Whoever does not stays in a different network, and one Bitcoin could become two. And all of today’s mining machines would be useless overnight, because they can compute SHA-256 only.
That is why in Bitcoin replacing the mining function is spoken of not as a plan but as an emergency exit. As of December 2026 there is no reason for it.
See also
- Hash function (hash)
- Is Bitcoin secure? What its cryptography rests on
- Bitcoin mining: how proof of work works
- Quantum computers and Bitcoin: what if elliptic curves fell
- Post-quantum Bitcoin: how Bitcoin would defend itself against quantum computers
- AES cipher (Advanced Encryption Standard)
- Shor’s algorithm
Chapters: Bitcoin: what it is and how it works, The Bitcoin halving: why there are only 21 million bitcoins, Bitcoin mining: how proof of work works, Blockchain and the Merkle tree: how it works and why history cannot be rewritten, The Bitcoin address, private key and signature, Seed phrase: why nobody can guess the 12 words of a wallet, Ethereum: smart contracts and proof of stake, Is Bitcoin secure? What its cryptography rests on, The 51% attack: can Bitcoin be spent twice?, Quantum computers and Bitcoin: what if elliptic curves fell, Bitcoin and SHA-256: what if the hash function fell, Post-quantum Bitcoin: how Bitcoin would defend itself against quantum computers