ORIGINAL LESSON CONTENT:

Learning Objectives:

  • Understand the structure of blocks and the blockchain

  • Explain Merkle trees, transaction structures, and state models

  • Differentiate between UTXO and account-based models

1.4.1: Block Structure

Components of a Block:

text
Block Structure:
┌─────────────────────────────────────────────────────────────────────┐
│  Block Header                                                     │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │ Version: Block format version                              │   │
│  │ Previous Block Hash: Link to previous block                │   │
│  │ Merkle Root: Root hash of transactions                     │   │
│  │ Timestamp: Block creation time                             │   │
│  │ Difficulty Target: Mining difficulty                       │   │
│  │ Nonce: Proof-of-work counter                               │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                                                                   │
│  Transaction Counter: Number of transactions                     │
│                                                                   │
│  Transaction List:                                                │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  Tx 1: {from, to, amount, signature}                       │   │
│  │  Tx 2: {from, to, amount, signature}                       │   │
│  │  ...                                                       │   │
│  │  Tx N: {from, to, amount, signature}                       │   │
│  └─────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────┘

Block Header Details:

 
 
Field Size Description
Version 4 bytes Block format version
Previous Block Hash 32 bytes Hash of previous block header
Merkle Root 32 bytes Root of Merkle tree of transactions
Timestamp 4 bytes Unix timestamp (seconds since 1970)
Difficulty Target 4 bytes Mining difficulty
Nonce 4 bytes Counter for proof-of-work
Transaction Count Variable Number of transactions

1.4.2: Chain Structure

How Blocks Link Together:

text
Blockchain Linkage:

Block 0 (Genesis) ────────┐
  Hash: 0x...            │
  Prev: None             │
                          │
                          ▼
Block 1 ──────────────────┐
  Hash: 0x...            │
  Prev: 0x(Block0 Hash)  │
                          │
                          ▼
Block 2 ──────────────────┐
  Hash: 0x...            │
  Prev: 0x(Block1 Hash)  │
                          │
                          ▼
Block 3 ──────────────────┐
  Hash: 0x...            │
  Prev: 0x(Block2 Hash)  │
                          │
                          ▼
         ... (Chain continues)

Immutability Property:

Changing any data in a block changes its hash, breaking the chain and invalidating all subsequent blocks.

text
If Block 2 data changes:
Block 2 Hash changes
  ↓
Block 3's "Previous Hash" no longer matches
  ↓
All subsequent blocks become invalid
  ↓
Chain is broken

1.4.3: Merkle Trees in Blockchain

Purpose:
Merkle trees allow efficient verification of transactions without downloading the entire blockchain.

Structure:

text
Merkle Tree with 4 Transactions:

Level 2:                    Merkle Root (H₁₂₃₄)
                           /              \
Level 1:              H₁₂                H₃₄
                    /     \            /     \
Level 0:          H₁      H₂         H₃      H₄
                 /        /          /        /
Tx List:       Tx₁      Tx₂        Tx₃      Tx₄

Where:
H₁ = Hash(Tx₁)
H₂ = Hash(Tx₂)
H₃ = Hash(Tx₃)
H₄ = Hash(Tx₄)
H₁₂ = Hash(H₁ + H₂)
H₃₄ = Hash(H₃ + H₄)
Merkle Root = Hash(H₁₂ + H₃₄)

Merkle Proof Verification:

To verify Tx₃ is in the tree:

text
Merklization proof for Tx₃ (4 transactions):
1. Present Tx₃ and H₄, H₁₂
2. Verifier computes:
   H₃ = Hash(Tx₃)
   H₃₄ = Hash(H₃ + H₄)
   Merkle Root' = Hash(H₁₂ + H₃₄)
3. Compare Merkle Root' with published Merkle Root
4. If equal, Tx₃ is verified

1.4.4: Transaction Structures

Bitcoin Transaction (UTXO Model):

text
Bitcoin Transaction:

Inputs (Sources):
┌────────────────────────────────────────────────────────────┐
│  Input 1:                                                 │
│    Previous Transaction: 0x7f3a...                        │
│    Index: 0                                              │
│    Script: <sig> <pubkey>                                │
│                                                          │
│  Input 2:                                                 │
│    Previous Transaction: 0x9b2c...                        │
│    Index: 2                                              │
│    Script: <sig> <pubkey>                                │
└────────────────────────────────────────────────────────────┘

Outputs (Destinations):
┌────────────────────────────────────────────────────────────┐
│  Output 1:                                                │
│    Amount: 5.0 BTC                                       │
│    Script: OP_DUP OP_HASH160 <pubkey_hash> OP_EQUALVERIFY │
│            OP_CHECKSIG                                    │
│                                                          │
│  Output 2:                                                │
│    Amount: 3.5 BTC                                       │
│    Script: OP_DUP OP_HASH160 <pubkey_hash> OP_EQUALVERIFY │
│            OP_CHECKSIG                                    │
│                                                          │
│  Change Output:                                           │
│    Amount: 1.5 BTC                                       │
│    Script: ...                                           │
└────────────────────────────────────────────────────────────┘

Ethereum Transaction (Account Model):

text
Ethereum Transaction:

┌────────────────────────────────────────────────────────────┐
│  From: 0x1a2b... (Sender Address)                        │
│  To: 0x3c4d... (Recipient Address)                       │
│  Value: 10.0 ETH                                         │
│  Nonce: 5                                                │
│  Gas Limit: 21,000                                       │
│  Gas Price: 20 Gwei                                      │
│  Data: [Optional contract data/calldata]                 │
│  Signature: (v, r, s)                                    │
└────────────────────────────────────────────────────────────┘

1.4.5: UTXO vs. Account Models

UTXO Model (Bitcoin-style):

text
UTXO Model:

┌────────────────────────────────────────────────────────────┐
│  UTXO Set (Unspent Transaction Outputs):                  │
│                                                          │
│  UTXO₁: 5.0 BTC (Owner: Alice)                          │
│  UTXO₂: 3.0 BTC (Owner: Bob)                            │
│  UTXO₃: 2.0 BTC (Owner: Alice)                          │
│                                                          │
│  Transaction:                                             │
│  Inputs: UTXO₁ (5.0 BTC) + UTXO₃ (2.0 BTC) = 7.0 BTC  │
│  Outputs:                                                 │
│    Output₁: 4.0 BTC (to Charlie)                         │
│    Output₂: 3.0 BTC (change to Alice)                    │
│                                                          │
│  New UTXO Set:                                            │
│  UTXO₂: 3.0 BTC (Owner: Bob)                            │
│  UTXO₄: 4.0 BTC (Owner: Charlie)                        │
│  UTXO₅: 3.0 BTC (Owner: Alice)                          │
└────────────────────────────────────────────────────────────┘

Account Model (Ethereum-style):

text
Account Model:

┌────────────────────────────────────────────────────────────┐
│  Account State:                                           │
│                                                          │
│  Alice: Balance = 5.0 ETH, Nonce = 2                    │
│  Bob: Balance = 3.0 ETH, Nonce = 1                     │
│  Charlie: Balance = 2.0 ETH, Nonce = 0                  │
│                                                          │
│  Transaction: Alice → Charlie: 1.0 ETH                 │
│                                                          │
│  Updated Account State:                                   │
│                                                          │
│  Alice: Balance = 4.0 ETH, Nonce = 3                    │
│  Bob: Balance = 3.0 ETH, Nonce = 1                     │
│  Charlie: Balance = 3.0 ETH, Nonce = 0                  │
└────────────────────────────────────────────────────────────┘

Comparison:

 
 
Feature UTXO Model Account Model
State Storage Transactions only Full account state
Privacy Higher (new addresses) Lower (known addresses)
Scalability Higher Lower (state growth)
Smart Contracts Limited Full support
Complexity Higher (inputs/outputs) Lower (simple transfers)
Parallel Processing Easier Harder
Examples Bitcoin, Cardano Ethereum, Solana

ADDITIONAL DEEP TECHNICAL NOTES:

1. Block Validation Process

Block Validation Steps:

text
1. Validate Block Header:
   - Version is supported
   - Previous block hash exists
   - Merkle root is valid
   - Timestamp is reasonable
   - Difficulty target is correct
   - Nonce satisfies proof-of-work

2. Validate Transactions:
   - Each transaction is valid
   - No double-spending
   - Total input value >= total output value
   - Transaction fees are acceptable

3. Validate Merkle Tree:
   - Compute Merkle root
   - Compare with header Merkle root

4. Check Block Size:
   - Block size within limits

5. Verify Chain:
   - Block extends valid chain
   - No fork detected

2. Merkle Tree Applications

Applications in Blockchain:

 
 
Application Purpose Benefit
SPV Verification Verify transaction without full node Light clients
Merkle Proofs Prove transaction inclusion Efficient verification
Merkle Patricia Trie State storage (Ethereum) Efficient state proofs
Merkle Mountain Ranges History storage Efficient pruning

3. Transaction Lifecycle

text
Transaction Lifecycle:

1. User Creates Transaction
   - Fill in inputs (UTXO or balance)
   - Specify outputs
   - Sign with private key

2. Transaction Broadcast
   - Sent to network nodes
   - Added to mempool

3. Transaction Validation
   - Nodes validate transaction
   - Check signatures and balance
   - Remove from mempool

4. Block Creation
   - Miner selects transactions
   - Creates block with transactions
   - Solves proof-of-work

5. Block Broadcast
   - Block sent to network
   - Nodes validate block

6. Confirmation
   - Block added to blockchain
   - Transaction confirmed
   - Additional confirmations (blocks)

4. State Trie (Ethereum)

text
Ethereum State Trie:

┌─────────────────────────────────────────────────────────────────────┐
│                     State Trie (Merkle Patricia Trie)              │
│                                                                   │
│                   State Root (Keccak-256 hash)                    │
│                              │                                    │
│                 ┌────────────┴────────────┐                      │
│                 │                         │                      │
│           Account 1                Account 2                     │
│           (Alice)                  (Bob)                         │
│              │                        │                          │
│     ┌────────┴────────┐        ──────┴──────                    │
│     │                 │        │          │                     │
│  Balance  Nonce    Storage   Balance  Nonce   Storage           │
│  5.0 ETH   2      Contract   3.0 ETH   1     Contract          │
│                   (0x...)              (0x...)                  │
│                                                                   │
│  Storage Trie (for contract):                                     │
│  ┌─────────────────────────────────────────────────────────────┐  │
│  │  Key 1 → Value 1                                          │  │
│  │  Key 2 → Value 2                                          │  │
│  │  ...                                                      │  │
│  └─────────────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────────┘

5. Data Storage Comparison

 
 
Data Type Bitcoin (UTXO) Ethereum (Account)
State Storage UTXO Set Account State Trie
Transaction Storage Transaction Chain Transaction Chain
Contract Storage Limited (Script) Storage Trie
State Proof Merkle Block Hash State Root
Storage Growth Linear Linear + State Growth