A hash function is a mathematical algorithm that takes an input of any size and produces a fixed-size output (called a hash or digest). Hash functions are one-way โ given the output, it's computationally infeasible to determine the original input.
Properties
Deterministic: The same input always produces the same output.
Fixed Output: Regardless of input size, the output length is always the same (256 bits for SHA-256).
Avalanche Effect: A tiny change in input dramatically changes the output.
One-Way: Cannot reverse the output to find the input.
Collision Resistant: Extremely unlikely for two different inputs to produce the same output.
Hash Functions in Blockchain
SHA-256: Used by Bitcoin for mining and block linking.
Keccak-256: Used by Ethereum for addresses and state management.
Block Linking: Each block contains the hash of the previous block, creating an immutable chain.
Hash functions are the cryptographic glue that holds blockchains together, ensuring data integrity and enabling proof-of-work mining.