MASTERING-BITCOIN · Interactive Practice | Unit 4 · Video 4
| Concept | Formula / Value | Description |
|---|---|---|
| HASH160 | Produces a 20-byte (160-bit) digest used in P2SH | |
| P2SH output template | The exact script pattern nodes recognize as P2SH | |
| Preimage / 2nd-preimage work | Work to invert or match a fixed -bit hash | |
| Birthday bound (collision) | Work to find any two inputs colliding on an -bit hash | |
| HASH160 collision security | Matches Bitcoin's hourly hashrate | |
| SHA-256 collision security | ~ years at today's hashrate |
The security of a hash commitment depends on the type of attack and the bit length . Preimage and second-preimage attacks take work. Collision attacks — where the attacker controls the input — take only work thanks to the birthday bound.
Move the slider to change the hash output size and see how the three attack costs compare. Then see how long each would take on hardware running at hashes per hour (roughly today's Bitcoin mining network).
⚙ interactive visualization — coming to this page format soon
Notice: At (HASH160, the P2SH standard), collision work is only — roughly one hour of global Bitcoin mining. At (SegWit's P2WSH / Taproot), collision work is — well beyond the age of the universe. Doubling the hash length doesn't double security; it squares the collision-breaking time.
Why is collision the scary attack? Because the attacker can shape the input. In the P2SH collision attack, a malicious multisig participant grinds two scripts in parallel:
They tweak a nonce in each, hash both, and collect digests into two piles of size . By the birthday bound, once they are very likely to find a match. Then they publish the honest script, let victims fund the address, and later reveal the evil script — which hashes to the same 20 bytes.
Adjust the hash size and the attacker's grinding budget to see the collision probability.
⚙ interactive visualization — coming to this page format soon
Reflect: The curve jumps from "impossible" to "near certain" right around . This is why we say the birthday bound is the real security level against a collision attack. For real HASH160 we can't simulate directly, but the shape of the probability curve is identical — just shifted to .
How does the collision threat scale as Bitcoin's mining hashrate grows (or shrinks)? The network's aggregate work per hour is currently around HASH160-equivalent operations. If dedicated hashing hardware eventually reaches that same scale, HASH160 collisions become practically grindable.
Pick an attacker hashrate and compare how long it takes to collide a 160-bit hash vs a 256-bit hash.
⚙ interactive visualization — coming to this page format soon
Notice: At roughly hashes per second (far beyond today's total Bitcoin network, which does per hour), a 160-bit hash collides in seconds, while a 256-bit hash still needs more time than the age of the universe. This is the structural reason Bitcoin migrated to 32-byte script hashes in SegWit (P2WSH) and Taproot (P2TR).
Question 1 · Collision Work for HASH160
P2SH commits to a 20-byte (160-bit) HASH160 digest of the redeem script. Assuming the hash function behaves ideally, how much work is required to find any pair of inputs that collide on the same 20-byte output?
✅ Correct! The birthday bound gives for a 160-bit hash.
❌ Not quite. is the cost of a preimage or second-preimage attack, not a collision. Collisions benefit from the birthday bound.
❌ Not quite. Apply the birthday bound: with .
Solution:
By the birthday bound, finding any collision on an -bit hash takes roughly work, not .
For HASH160 with :
This matches the entire Bitcoin mining network's output per hour, which is exactly why the margin is considered dangerously thin.
Question 2 · Why Collision, Not Preimage?
A group sets up a P2SH multisig address. Mallory is the last participant to contribute a public key. Before submitting, she secretly grinds two script variants in parallel: an honest one using everyone's keys, and an evil one that pays only her. She hashes both until their 20-byte digests match, then publishes the honest version.
Why does this attack cost only work instead of ?
✅ Correct! Collision attacks are cheap precisely because the attacker shapes both inputs.
❌ Not quite. The figure comes from the birthday bound, which only applies when the attacker controls both inputs to the hash.
Solution:
The difference between preimage and collision work comes down to who controls the input.
The weakness isn't that HASH160 is broken — it's that the P2SH protocol lets the attacker shape the committed input before publishing. The 20-byte hash size and the mining hashrate are both relevant facts, but the structural reason the attack is cheap is that Mallory picks both inputs.
Question 3 · Why SegWit and Taproot Switched to 32-Byte Hashes
SegWit's P2WSH and Taproot's P2TR use a 32-byte SHA-256 script hash instead of a 20-byte HASH160. Roughly how much work does a collision attack now require, and by what factor has the collision cost increased relative to P2SH?
✅ Correct! Jumping from 160 to 256 bits multiplies collision cost by .
❌ Not quite. Apply the birthday bound to each: vs , then divide.
Solution:
The collision security of an -bit hash is .
The ratio is:
Concretely, if HASH160 collisions take the entire Bitcoin network about one hour, then SHA-256 collisions at that same rate would take roughly hours ≈ 32 billion years — more than twice the age of the universe.
Question 4 · True or False — Mining ASICs Threaten P2SH Today
Claim: "Bitcoin mining ASICs perform roughly hashes per hour, so they can be pointed directly at a P2SH collision attack."
Is this claim true or false?
✅ Correct! ASICs do SHA-256², not HASH160 (SHA-256 + RIPEMD-160), so they can't be directly repurposed for this attack.
❌ Not quite. The hash functions don't match — mining hardware can't directly attack HASH160 even though the work scale is similar.
❌ Not quite. Try again — the hints above can help.
Solution:
False.
Mining ASICs compute double SHA-256 (), which is what Bitcoin's proof-of-work requires. P2SH commitments use HASH160, which is — a different hash chain. Mining ASICs have no RIPEMD-160 circuit and therefore cannot directly grind HASH160 collisions.
The real threat is not today's miners. It's that operations is now a demonstrably feasible scale for purpose-built custom hardware. The "economically impossible" argument that justified 20-byte hashes in 2012 has eroded, which is precisely why SegWit and Taproot migrated to 32-byte SHA-256 script hashes.
Solved: 0 / 4