BLOCKCHAIN

What is a Blockchain?

A distributed ledger where each block contains data, a hash, and the previous block's hash — making the chain tamper-evident by design.

1The Distributed Ledger Problem

In a traditional database, one entity controls the records. If that entity is compromised, corrupted, or simply dishonest, the data changes without anyone knowing. Blockchain solves this with distributed consensus: the same ledger is held by thousands of participants, and no single party can alter history without rewriting every subsequent entry and outpacing the entire network.

A blockchain is a linked list of blocks where each block cryptographically commits to its predecessor. Changing any past block invalidates every block that follows, because the hashes no longer match. An attacker would have to redo the cryptographic work for every subsequent block — a task that becomes computationally infeasible on large networks.

✓ What blockchain adds

  • ✓ Immutable audit trail — no record can be silently erased
  • ✓ Decentralisation — no single point of failure or control
  • ✓ Transparency — anyone can audit the entire history
  • ✓ Censorship resistance — transactions cannot be blocked

✗ What it costs

  • ✗ Low throughput — Bitcoin does ~7 TPS vs Visa's ~24,000
  • ✗ Energy cost (PoW) — Bitcoin uses ~150 TWh/year
  • ✗ Irreversibility — a mistake cannot be undone
  • ✗ Storage growth — every node keeps the full history

2Anatomy of a Block

Every block in the chain contains four essential fields: an index, a timestamp, the data (e.g. a list of transactions), and a hash that uniquely fingerprints all of this content plus the previous block's hash. That last dependency is what chains the blocks together.

Block #0 (Genesis)index: 0time: 2024-01-01data: "Genesis"prev: "0000"hash: a3f2...Block #1index: 1time: 2024-01-01data: "Alice→Bob 1BTC"prev: a3f2...hash: 9c1d...Block #2index: 2time: 2024-01-02data: "Bob→Carol 0.5BTC"prev: 9c1d...hash: 7e8a...
Index & Timestamp
Position in the chain plus creation time. These anchor the block in the timeline.
Data
Payload — usually a Merkle tree of transactions. The hash commits to every byte of this field.
Previous Hash
The fingerprint of the last block. This field creates the chain: change one block, break all successors.

3Immutability via Cryptographic Hashing

SHA-256 maps any input to a 256-bit fingerprint. Two properties make it perfect for blockchains: determinism (same input → same hash, always) and avalanche effect (change one bit of input → ~50% of output bits flip). This means you cannot quietly edit a block's data — the hash changes, which cascades through every subsequent block.

To tamper with block #1, an attacker must: (1) recompute block #1's hash with new data, (2) update block #2's prev_hash and recompute block #2's hash, (3) continue through every subsequent block, and (4) do all of this faster than the honest network adds new blocks — an impossibility once the chain is long.

2²⁵⁶ outputs
SHA-256's output space. Finding two different inputs that hash to the same value is computationally infeasible.
6 confirmations
After 6 blocks are built on top of yours, reverting it requires controlling 51% of network hash rate — prohibitively expensive.
51% attack
An attacker with majority hash power could rewrite recent history — the fundamental security assumption blockchain relies on.

4Nodes, Peers, and Consensus

A blockchain is run by a peer-to-peer network of nodes. Each node stores a full copy of the chain. When a new block is proposed, nodes verify it independently and add it only if it satisfies the consensus rules. No central coordinator exists — agreement emerges from the protocol itself.

✓ Full nodes do

  • ✓ Store the complete chain from genesis
  • ✓ Validate every transaction independently
  • ✓ Relay valid blocks and transactions to peers
  • ✓ Enforce consensus rules — reject invalid blocks

✗ Common misconceptions

  • ✗ "Blockchain = Bitcoin" — blockchain is the data structure; Bitcoin is one application
  • ✗ "Decentralised = anonymous" — Bitcoin is pseudonymous, not anonymous
  • ✗ "Immutable = perfect" — bugs in smart contracts are permanent too
  • ✗ "All blockchains are permissionless" — enterprise blockchains (Hyperledger) are permissioned
Merkle Tree
Transactions in a block are hashed in pairs up to a single Merkle root — efficient verification without downloading all transactions.
Genesis Block
Block #0. Hard-coded into every Bitcoin client. Its prev_hash is all zeros — there is no predecessor.
Fork
When two valid blocks compete for the same position. Resolved by the longest-chain rule: nodes adopt whichever branch accumulates more work.
Build a mini blockchain in Python

Recall check

0 of …

Say the answer out loud before revealing — recalling is what makes it stick.

  1. What makes a blockchain tamper-evident?

  2. What are the four fields in a block?

  3. What is the avalanche effect in SHA-256?

  4. What is a 51% attack?