Block Chain - Hash Function in Blockchain:
1. Definition
A Hash Function is a cryptographic algorithm that takes an input (any size: text, file, transaction data) and produces a fixed-size output (called a hash or digest).
-
In blockchain, hash functions are used to secure data, link blocks, and ensure integrity.
-
Example: Bitcoin uses SHA-256 (Secure Hash Algorithm – 256 bit).
2. Properties of Hash Functions
-
Deterministic – Same input → always the same output.
-
Fixed Output Size – Output (hash) length is always the same, regardless of input size.
-
Example: SHA-256 always outputs 256 bits (64 hex characters).
-
-
Pre-image Resistance – You can’t reverse a hash to find the original input.
-
Collision Resistance – No two different inputs should produce the same hash.
-
Avalanche Effect – Small input change → huge change in output hash.
3. How It Ensures Integrity and Immutability
-
Integrity: If even 1 character in a transaction changes, the hash completely changes → tampering is obvious.
-
Immutability: Since each block contains the previous block’s hash, changing one block requires recalculating all subsequent hashes → nearly impossible on large networks.
4. Example
Input: "Blockchain"
SHA-256 Output:
6250...7e47f3c (64-character hash)
Input: "blockchain"
(lowercase "b")
SHA-256 Output:
ef78...93a2df1 (completely different hash)
This shows the avalanche effect.
5. Role of Hash in Blockchain
-
Block Linking: Each block stores the previous block’s hash → forms the “chain.”
-
Mining (Proof of Work): Miners find a hash with certain properties (like starting with a number of zeros).
-
Digital Signatures: Transactions are hashed and signed to ensure authenticity.
In short:
A Hash Function is the backbone of blockchain security. It guarantees that data is tamper-proof, verifiable, and immutable by turning information into unique digital fingerprints that cannot be reversed or duplicated.