SHA-256SW: Demonstrating Flaws in Hash Functions & PoW Bypass
SHA-256SW
is a deliberately weakened version of SHA-256. This demonstration explores how its flaw can be exploited for various attacks, including bypassing Proof-of-Work, a core security mechanism for cryptocurrencies.
IMPORTANT DISCLAIMER: This page demonstrates vulnerabilities in SHA-256SW, a deliberately flawed hash function for educational purposes. The actual, cryptographically secure SHA-256 algorithm used in Bitcoin and other applications remains robust and is NOT broken by these methods.
The Critical Flaw: Invertibility & Reduced Diffusion
The attack is possible due to a deliberate flaw in this hash function's message schedule expansion (the process by which initial message blocks are expanded into 64 words). In standard SHA-256, future message words are complex combinations of past words, ensuring strong bit diffusion.
In this SHA-256SW
implementation, a simple internal array `hs_b` is used, and the flaw manifests with a rule like hs_b[i+20] = hs_b[i+4]
. This creates a direct, predictable relationship between certain internal state values and original message words.
The Flaw in Detail:
- Direct Copy, Not Complex Mixing: Instead of robustly mixing previous values with non-linear functions (like bitwise rotations, shifts, and XORs), this rule directly copies an earlier "word" from the message schedule (`hs_b[i+4]`) to a later position (`hs_b[i+20]`). For example, the 20th expanded word (`hs_b[20]`) is simply a copy of the 0th original message word (`hs_b[4]`).
- Loss of Unpredictability: In a secure hash, you cannot deduce earlier inputs from later internal states. This direct copy creates a "leak" where information from the original input remains trivially recoverable at later stages.
Why This Breaks Cryptographic Security:
- Inversion Attack (One-Way Property Failure): Because information is directly copied and not thoroughly scrambled, the function becomes invertible. Given the final internal state (which still contains these "leaked" original message components), the original input block can be instantly recovered, bypassing the massive computational effort required for Proof-of-Work.
- Reduced Diffusion (Avalanche Effect Failure): A single bit change in the input should ideally flip roughly half the bits in the output. This direct copy rule severely limits how well input bits spread throughout the hash state, making the output less chaotic and more predictable. This allows algorithms like Simulated Annealing to "find" patterns.
Why Standard SHA-256 Remains Secure
The standard SHA-256 algorithm (and other secure cryptographic hashes like SHA-3, BLAKE2) prevents these attacks through fundamental design principles:
- Complex Message Schedule: Each expanded message word is a complex combination of multiple previous words, involving integer additions, and non-linear bitwise operations (rotations, shifts, and XORs). This process is designed to be highly non-reversible.
(Example: Real SHA-256's word expansion formula for `W[t]` where t >= 16:
W[t] = U32(W[t - 16] + Σ0(W[t - 15]) + W[t - 7] + Σ1(W[t - 2]));
where Σ0 and Σ1 involve bitwise rotations and shifts.)
- Strong Diffusion (Avalanche Effect): Every bit of the input quickly influences every bit of the internal state and the final hash, ensuring that a tiny change in input results in a drastically different output. This makes brute-force the only practical attack for specific hash properties.
- One-Way Property (Preimage Resistance): It is computationally infeasible to reverse a secure hash function to find the original input from its output. This is fundamental to Proof-of-Work security.
These properties are meticulously designed and rigorously tested to ensure SHA-256's continued cryptographic strength against practical attacks.