TeachMeBitcoin

Security: HASH160 vs. SHA256

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Security: HASH160 vs. SHA256

One of the hidden upgrades in the transition to SegWit Multisig was the move from 160-bit hashes to 256-bit hashes. This was a proactive move by the Bitcoin developers to defend against future mathematical attacks.

1. The Collision Problem

A "Collision" is when two different scripts produce the same hash. If an attacker can find two scripts:

2. Birthday Attack Math

The difficulty of finding a collision is related to the length of the hash.

3. SegWit's Upgrade

When SegWit was designed, the developers decided that P2WSH (Witness Scripts) should always use the stronger 32-byte (256-bit) SHA256.

4. Why Legacy P2SH is still safe

Legacy P2SH (the 3-series addresses) still uses 20-byte HASH160. While theoretically less secure than 256-bit, no one has ever successfully performed a collision attack on a 160-bit Bitcoin script. However, by moving multisig to 256-bit, Bitcoin has ensured its security for decades to come.

Feature Legacy P2SH SegWit Multisig (WSH)
Hash Length 160 Bits 256 Bits
Security Level ~80 Bits ~128 Bits
Attack Type Birthday Attack Mathematically Impossible

In the final section, we will build a Python P2SH-P2WSH Auditor.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!