RoadToChain Logo
RoadToChain
T0/M0.2/What is a block — data structure deep dive
beginner 14m read

What is a block — data structure deep dive

Previous hash, merkle root, timestamp, nonce, transactions. Why the previous hash chains blocks together.

#blocks #hashing #interactive

When I first learned about blockchain, I had a very fuzzy mental image of it. I imagined some sort of digital glowing chains physically holding data together.

The reality is much simpler, and much more beautiful: A blockchain is just a singly-linked list of records, where each record contains a cryptographic reference to the one before it.

T0.4 — Where Is Blockchain Stored?
✗ Common Misconception
Laptop
your device
Server
one company
Database
single source
“How I thought blockchain worked”
✓ Reality — Distributed Storage
Node A
Block 1
Block 2
Block 3
Node B
Block 1
Block 2
Block 3
Node C
Block 1
Block 2
Block 3
Node D
Block 1
Block 2
Block 3
Every full node stores a complete copy. "The blockchain" is not a single place — it's thousands of identical copies.

Let's look inside a single block to see exactly how it is structured.


1. Anatomy of a Block: The Block Header vs. Block Body

A block is divided into two parts: the Header (the metadata that identifies the block) and the Body (the actual list of transactions).

SmartAccount.sol
 ┌─────────────────────────────────────────────────────────┐
 │                      BLOCK HEADER                       │
 ├─────────────────┬───────────────────┬───────────────────┤
 │  Previous Hash  │    Merkle Root    │     Timestamp     │
 ├─────────────────┼───────────────────┼───────────────────┤
 │    Difficulty   │       Nonce       │    Block Number   │
 └─────────────────┴───────────────────┴───────────────────┘
 ┌─────────────────────────────────────────────────────────┐
 │                       BLOCK BODY                        │
 ├─────────────────────────────────────────────────────────┤
 │  [Tx 0: Alice -> Bob 5 ETH]                             │
 │  [Tx 1: Charlie -> Dave 2 ETH]                          │
 │  ...                                                    │
 └─────────────────────────────────────────────────────────┘

The header contains the key fields that secure the chain:

  1. Previous Block Hash: The 32-byte SHA-256 hash of the header of the previous block. This is the link that chains them.
  2. Merkle Root Hash: A single cryptographic hash that represents every transaction in the block body.
  3. Timestamp: The Unix epoch time when the block was mined.
  4. Nonce (Number used Once): The random value miners adjust to solve the Proof of Work math puzzle.
  5. Difficulty Target: The threshold target the block hash must meet.
Anatomy of a Block — Header fields and Body transaction list
A block contains a Header (previous hash, merkle root, timestamp, nonce, difficulty) and a Body (ordered list of transactions). The previous hash is what chains blocks together.

2. Layman Explanation: The Sealed Box Files

Imagine a company keeps its accounting records in a stack of cardboard boxes.

Every time a box is full, the manager takes a polaroid photo of the entire contents of the previous box, along with the box's lid, and sticks that photo onto the inside lid of the new box. Then, they close the box, wrap it in security tape, and seal it with a wax stamp.

If a thief sneaks in and tries to change a transaction sheet in Box 3:

  • The contents of Box 3 will change.
  • When you take a photo of Box 3, it won't match the polaroid photo stuck inside Box 4.
  • The seal is broken! You instantly know history has been tampered with.

Because each box contains a photo of the previous one, changing a single letter in Box 3 requires you to redo the photos, seals, and tape for Box 4, Box 5, Box 6, and every box up to the present.


3. Technical Explanation: Merkle Trees & Tamper Resistance

The Chained Dependency

If we express this chain in code, a block hash is computed as:

SmartAccount.sol
BlockHash = SHA256(PreviousHash + MerkleRoot + Timestamp + Nonce)

Because the PreviousHash is an input parameter for the current block's hash calculation, changing Block 1 will alter BlockHash_1. Since Block 2 contains PreviousHash_1 inside its header, Block 2's hash will change. This cascades all the way to the latest block (the "tip" of the chain).

The Merkle Root (Efficient Verification)

Instead of hashing the entire block body (which could be megabytes of transactions), blockchain headers use a Merkle Tree:

  1. All transactions in the block are hashed: H(T0), H(T1), H(T2), H(T3).
  2. Hashes are paired and hashed recursively: H(01) = H(H(T0) + H(T1)) and H(23) = H(H(T2) + H(T3)).
  3. This process continues until a single root remains: MerkleRoot = H(H(01) + H(23)).
MERKLE TREE DATA STRUCT (TRANSACTION HASHING)Merkle RootHash(H01 + H23)Hash 01Hash(H0 + H1)Hash 23Hash(H2 + H3)Hash 0Hash(Tx 0)Tx 0Hash 1Hash(Tx 1)Tx 1Hash 2Hash(Tx 2)Tx 2Hash 3Hash(Tx 3)Tx 3

// A Merkle Tree recursively hashes transaction pairs. The resulting Merkle Root represents all transactions using a single 32-byte hash inside the Block Header.

This enables a client to prove a transaction T2 is in the block without downloading all other transactions. They only need the Merkle Path (the sibling hashes H(T3) and H(01)), which scales at $O(\log N)$ complexity rather than $O(N)$!


Interactive Sandbox: Visual Blockchain Simulator

Below is the interactive Visual Blockchain Simulator. You can broadcast transactions, mine blocks into the ledger, view the P2P gossip propagation animation, and tamper with transaction data to see how it breaks the cryptographic hash links between blocks:

BLOCKCHAIN_NODE_SIMULATOR // CORED_v1.0.4
CHAIN_SECURE
Ledger Chain State

Transaction Injector

Mempool Ledger Queue

0 TX_PENDING
Mempool empty. Node idling...
System CLI Output Log
guest@blockchain-node:~$

System Design Challenge
Think Active

If a block contains 8 transactions, how many levels will the Merkle Tree have, and how many hashing operations are required to compute the Merkle Root?

[ Think Before Continuing ]

Was this lesson helpful?

Let us know what you think of this specification. (submitting anonymously)