Blockchain — Deep Dive

Merkle trees, Byzantine fault tolerance, gas economics, and the scalability trilemma.

Internal Data Structures

Merkle Trees

Each block doesn’t just list transactions — it organizes them in a Merkle tree (binary hash tree). This allows:

  • Efficient verification: Prove a transaction is in a block by providing ~log₂(n) hashes instead of all transactions
  • Light clients: Mobile wallets don’t download full blocks — they verify Merkle proofs
        Root Hash
       /         \
    Hash(AB)    Hash(CD)
    /    \      /    \
  H(A)  H(B)  H(C)  H(D)
   |      |     |      |
  Tx A   Tx B  Tx C   Tx D

UTXO vs Account Model

  • Bitcoin (UTXO): Unspent Transaction Outputs. Each “coin” is a discrete object. Privacy-friendly but complex.
  • Ethereum (Account): Each address has a balance. Simpler but requires careful nonce management.

Consensus Deep Dive

Byzantine Fault Tolerance (BFT)

The fundamental problem: in a network of n nodes, up to f can be malicious (lie, delay, send conflicting messages). BFT consensus works if f < n/3.

Nakamoto consensus (Bitcoin) is a probabilistic BFT — finality is never absolute but becomes exponentially certain with each confirmation (6 blocks ≈ 99.9999% final).

Proof of Stake Economics

Ethereum’s PoS requires validators to stake 32 ETH. Misbehavior triggers slashing — loss of staked funds. This creates economic incentive alignment:

  • Honest behavior: Earn ~4-5% APY
  • Dishonest behavior: Lose staked ETH (up to 100%)

The Scalability Trilemma

You can optimize for two of three:

    Decentralization
        /        \
       /          \
Security --- Scalability
  • Bitcoin: Decentralized + Secure, but ~7 tx/sec
  • Solana: Scalable + Secure, but fewer validators (less decentralized)
  • Layer 2s (Rollups): Inherit L1 security while scaling to thousands of tx/sec

Rollups

  • Optimistic Rollups: Assume transactions are valid, allow fraud proofs within a challenge period (7 days). Used by Arbitrum, Optimism.
  • ZK-Rollups: Cryptographic validity proofs included with each batch. Faster finality but more complex. Used by zkSync, StarkNet.

Gas and Fee Markets

Ethereum’s EIP-1559 introduced:

  • Base fee: Algorithmically adjusted per block. Burned (deflationary pressure).
  • Priority fee (tip): Paid to validators for inclusion priority.
  • Fee = (base_fee + tip) × gas_used

This creates a more predictable fee market compared to first-price auctions.

Smart Contracts

Self-executing code deployed on-chain. Key considerations:

  • Immutable once deployed — bugs can’t be patched (unless using proxy patterns)
  • Gas costs real money — every computation has a price
  • Composability — contracts can call other contracts (DeFi “money legos”)
  • Reentrancy attacks — the most common vulnerability (The DAO hack, 2016)
techcryptoweb3