Hash Functions — Fingerprints for Data
In section 1, Ravi's edit to an old block was caught because the block's fingerprint changed. That fingerprint is a hash, and almost every part of a blockchain leans on it: block links, transaction IDs, mining and addresses. This lesson makes the idea precise.
The rule
Same input, same hash; change one bit, change everything; never run it backwards.
A cryptographic hash function takes input of any size and returns an output of fixed size. Bitcoin uses SHA-256, whose output is 256 bits, usually written as 64 hexadecimal characters. Ethereum uses a different function, Keccak-256, which is also 256 bits long.
SHA-256("Asha pays Ravi 5") = ef4f6f0fea431f4b4dd3b1e9f0c88c5dc028a807ede25da5ab3efb7e9e80245e
SHA-256("Asha pays Ravi 6") = 245847cc211a5555290467fb275551853ae46e26dd13b260c35c80acd5b899e6One digit changed in the input, and the two outputs share no visible pattern. Five properties make hashes useful:
- Deterministic. The same input always gives the same hash, on any computer, at any time.
- Fixed size. A 16-character message and an 18,000-character file both produce 64 hex characters.
- Avalanche effect. A tiny change to the input scrambles the whole output.
- One-way. Given a hash, there is no practical way to find an input that produces it, other than guessing inputs one at a time.
- Collision resistant. Nobody can practically find two different inputs with the same hash.
Collisions must exist in principle, because there are endlessly many possible inputs and only 2²⁵⁶ possible outputs. But finding one for SHA-256 is far beyond any computer that exists.
A hash is not encryption. Encryption is built to be reversed by whoever holds the key. A hash has no key and is built never to be reversed.