Day 235Part 7: How Bitcoin Works

What Is Hashing

A hash function takes any input — a word, a sentence, an entire book, a Bitcoin transaction — and produces a fixed-length output called a hash. Always the same length, regardless of input size. Always unique to that specific input.

Bitcoin uses a hash function called SHA-256. Feed it the word “hello” and it produces a specific 64-character string. Feed it “hello.” with a period and it produces a completely different 64-character string. The relationship between input and output looks random — but it’s entirely deterministic. The same input always produces the same output.

Two properties make hashing fundamental to Bitcoin.

First: it’s one-way. Given a hash output, it’s computationally impossible to reconstruct the input that produced it. The fingerprint tells you nothing about what was fingerprinted.

Second: it’s uniquely sensitive. Change a single character in the input and the output changes completely and unpredictably. There’s no way to make a small adjustment to the input to nudge the output in a desired direction.

This is why hashing secures the blockchain. Every block contains the hash of the previous block. If anyone tried to alter a historical transaction — change an amount, reassign a payment — the hash of that block would change. Which would invalidate the hash stored in the next block. Which would cascade through every subsequent block.

Tampering with the blockchain doesn’t just change one entry. It breaks every block that came after it. And repairing that break would require redoing more computational work than the entire rest of the network has performed.

Hashing is the mathematical glue that makes the chain immutable.

Tomorrow: what is the blockchain — now with the full context to understand it properly.

— The Daily Bit

Part of The Daily Bit — 365 days to understanding Bitcoin.