Problem & Constraints
Design a cross-institution settlement ledger (many banks, multiple regulators, nobody willing to be the central party): replicate, across mutually distrusting hundreds of nodes, one transaction history that everyone agrees on and no one can unilaterally alter. This is a different threat model from classic distributed systems — Day 5's replication assumes nodes only crash (crash fault), whereas here nodes may actively lie, forge, and collude (Byzantine fault), with no trusted coordinator. Consensus shifts from "make the live replicas agree" to "make a crowd of potential liars agree."
- Trust model: no trusted third party; nodes can act Byzantine; tolerate at most 1/3 (BFT) or <50% of hash power/stake (Nakamoto consensus) being malicious.
- Throughput vs security: Bitcoin ~7 TPS, Ethereum ~15-30 TPS, versus Visa's peak of tens of thousands TPS — three orders of magnitude slower is the tax paid for security.
- Finality: how long until a transaction is "irreversible"? PoW gives probabilistic finality (wait ~6 blocks ≈ 1 hour); BFT gives deterministic finality (one block settles it).
- Data size: full nodes store all history (Bitcoin > 600GB, Ethereum archive node > 15TB); on-chain storage is brutally expensive (dollars per KB).
- Tamper-evident + auditable: any third party can independently verify the whole chain without trusting the publisher.
High-Level Architecture
graph TD
C["Client / Wallet
signs tx with private key"]
MP["Mempool
pending tx pool"]
subgraph P2P["P2P node network (gossip broadcast)"]
V1["Validator node
execute+consensus"]
V2["Validator node"]
V3["Validator node"]
end
EVM["State machine / VM
EVM · deterministic exec"]
LDG[("Blockchain ledger
hash chain + Merkle tree")]
OFF[("Off-chain storage
IPFS / Arweave")]
C -->|1 signed tx| MP --> P2P
P2P -->|2 consensus picks leader| EVM
EVM -->|3 state transition| LDG
EVM -.large blobs store only hash.-> OFF
V1 <-.gossip.-> V2 <-.gossip.-> V3
classDef client fill:#1a2530,stroke:#64c8ff,color:#e8eef5
classDef net fill:#0e2030,stroke:#5eead4,color:#e8eef5
classDef exec fill:#1a1a30,stroke:#ffb450,color:#e8eef5
classDef store fill:#2a1530,stroke:#ff7ab6,color:#e8eef5
class C client
class V1,V2,V3,MP net
class EVM exec
class LDG,OFF store
Transactions enter the mempool → P2P network → consensus picks a block producer → the VM deterministically executes to a new state → the hash chain appends. Every full node replays all transactions to verify independently, trusting no producer.
Key Technical Points
1. Consensus: PoW vs PoS vs BFT — trading security and decentralization for throughput
Principle: reaching agreement under Byzantine conditions requires scarce voting power, otherwise an attacker spins up endless fake identities (Sybil attack) to swing votes. PoW uses hash power as the scarce resource (solve a hash puzzle; whoever solves first produces the block). PoS uses staked capital (a stake-weighted random pick of the producer; misbehave and your stake is slashed). BFT-style (PBFT / Tendermint) runs two voting rounds (pre-vote / pre-commit) within a known validator set and commits deterministically once 2/3+ agree.
| PoW (Bitcoin) | PoS (Ethereum) | BFT (Tendermint) |
| Scarce resource | hash power | staked capital | known identity + stake |
| Finality | probabilistic (~6 blocks) | ~2 epochs | 1 block |
| Node scale | permissionless, tens of thousands | permissionless, 100k+ validators | usually <200 (O(n²) voting) |
| Energy | very high | very low | very low |
| Cost | slow, power-hungry, 51% attack | nothing-at-stake, rich-get-richer | scale-limited, needs gated identity |
Trade-off:
- PoW: ✅ most battle-tested; Sybil resistance is pure physical hash power; ❌ slow, staggering energy use, mining-pool centralization, only probabilistic finality (reorgs are theoretically possible).
- PoS: ✅ ~99.95% less energy, slashing punishes misbehavior, more stake = higher attack cost; ❌ "nothing-at-stake" (low marginal cost to cheat, needs slashing to fix), long-range attacks, capital concentration.
- BFT: ✅ instant finality, low latency, high throughput; ❌ O(n²) vote communication caps node count — fundamentally a permissioned stance, trading open decentralization.
# PoW block production: brute-force a nonce meeting the difficulty (pseudo-code)
def mine(block, difficulty):
target = 2 ** (256 - difficulty)
nonce = 0
while True:
h = sha256(sha256(block.header + nonce)) # Bitcoin double SHA-256
if int(h, 16) < target: # enough leading zeros
return nonce # found -> broadcast block
nonce += 1
# Verification is a single hash (O(1)); production needs ~2^difficulty tries.
# Difficulty auto-adjusts every 2016 blocks, locking ~10-min block interval.
Real cases:
- Bitcoin: PoW Nakamoto consensus, ~10-min blocks, ~7 TPS; security rides on total network hash power, never 51%-attacked to date (smaller coins are, repeatedly). See the Nakamoto 2008 whitepaper.
- Ethereum: "The Merge" on 2022-09-15 switched PoW → PoS, cutting energy by ~99.95%; validators stake 32 ETH and get slashed for misbehavior.
- Cosmos / Tendermint: BFT instant finality, the consensus base for the IBC cross-chain ecosystem; bounded validator set but ~1s blocks.
- Solana: Proof of History (a cryptographic clock that pre-orders transactions) + PoS chasing high TPS — but suffered repeated network-wide halts in 2022 from congestion/bugs (see Scalability below).
2. Smart contracts: deterministic state machine + gas metering — making the halting problem pay per opcode
Principle: a smart contract is code deployed on-chain and re-executed by every node. Each full node must compute the exact same result, or the state forks — demanding strict determinism: no true randomness, no reading wall-clock/network, avoid floating point. The EVM is a 256-bit stack machine. Because code may loop forever (the halting problem is undecidable), gas prices every opcode; the caller prepays gas, and running out reverts — both a DoS guard and a price on computation.
Trade-off: the mutability dilemma
- Immutable: ✅ truly trustless, users are certain the rules won't change; ❌ bugs can't be fixed (The DAO is the textbook case), only abandoned and migrated.
- Upgradeable proxy: ✅ can patch bugs; ❌ reintroduces an "admin can swap the logic" centralization — itself an attack surface.
- Off-chain compute + on-chain verify: ✅ saves gas, runs heavy compute; ❌ needs a trusted oracle or ZK proof, high complexity.
// reentrancy bug: transfer before zeroing balance -> recursive re-entry (The DAO 2016)
function withdraw() public {
uint bal = balances[msg.sender];
(bool ok,) = msg.sender.call{value: bal}(""); // ⚠️ callback re-enters withdraw()
balances[msg.sender] = 0; // too late! re-entered before zeroing
}
// Fix — Checks-Effects-Interactions: change state first, then call out
function withdraw() public {
uint bal = balances[msg.sender];
balances[msg.sender] = 0; // ✅ zero first (Effect)
(bool ok,) = msg.sender.call{value: bal}(""); // then transfer (Interaction)
require(ok);
}
Real cases:
- The DAO (2016): a reentrancy bug drained ~3.6M ETH (~$60M at the time); Ethereum hard-forked to reverse it, splitting off Ethereum Classic (the no-fork camp).
- Ethereum EVM: stack-based 256-bit VM + gas metering — the de facto standard that Polygon, BNB Chain, Avalanche and many others stay compatible with.
- Solana: uses BPF/SBF (not EVM) and an account model rather than EVM's contract-storage model, optimized for parallel execution.
- Hyperledger Fabric: a permissioned chain; chaincode runs in Docker containers, and its execute-order-validate flow tolerates non-determinism by filtering after.
3. Data integrity: hash chain + Merkle tree + off-chain storage — compressing "trust" into a 32-byte root
Principle: tamper-evidence comes from two hashing layers. A hash chain: each block header contains the previous block's hash, so altering any historical block invalidates every hash after it — the cost to tamper equals redoing all subsequent PoW/consensus. A Merkle tree: the thousands of transactions in a block are pairwise-hashed into a tree whose root goes into the header — so a light node (SPV) needs only an O(log n) Merkle proof to verify "this transaction is in this block" without downloading the full block. That lets a phone wallet skip storing 600GB.
Trade-off: where does data live?
- Fully on-chain: ✅ strongest tamper-evidence + availability; ❌ every node stores a copy — absurdly expensive (hundreds of dollars per MB), never store images/video.
- Off-chain + hash on-chain: ✅ cheap, scalable; ❌ availability falls back to the off-chain system (IPFS content nobody pins disappears) — tamper-evident but able to vanish.
- Permanent storage (Arweave): ✅ pay once, stored forever; ❌ the economic model rests on long-term endowment-yield assumptions.
# Merkle proof verification: recompute the root from O(log n) sibling hashes (pseudo-code)
def verify(leaf, proof, root):
h = sha256(leaf)
for sibling, is_left in proof: # bottom-up
h = sha256(sibling + h) if is_left else sha256(h + sibling)
return h == root # root matches -> leaf is in the tree and untampered
# For one tx in a million-tx block, the proof is only ~20 hashes ≈ 640 bytes.
Real cases:
- Bitcoin SPV: light wallets verify transactions via Merkle proofs without storing the full chain — exactly the design in Section 8 of the Nakamoto whitepaper.
- IPFS / Filecoin: content addressing (CID = content hash); NFT metadata/large files often live on IPFS with only the CID on-chain; Filecoin adds economic incentives so someone keeps storing it.
- Arweave: a "permanent storage" play — pay once, blockweave structure — used by many NFT projects as a durable image layer.
- Certificate Transparency: Google's CT logs use Merkle trees for an auditable certificate ledger — a non-cryptocurrency application of blockchain ideas.
4. The scalability trilemma: Layer 2 Rollups — don't compute on the main chain, just throw the proof back at it
Principle: the "blockchain trilemma" (per Vitalik) says decentralization, security, scalability are hard to have all at once — raising throughput tends to either shrink the node set (lose decentralization) or relax verification (lose security). The mainstream scaling path is the Layer 2 Rollup: execute hundreds-to-thousands of transactions off-chain in a batch, and submit only compressed data + a validity guarantee back to L1, which acts as the settlement and data-availability layer. Two schools: Optimistic Rollup trusts by default but keeps a challenge window (~7 days) for fraud proofs; ZK Rollup uses zero-knowledge proofs (SNARK/STARK) to mathematically prove correct execution, so the main chain finalizes on one verification.
Trade-off: Optimistic vs ZK Rollup
- Optimistic: ✅ great EVM compatibility, simple to build; ❌ withdrawals wait the ~7-day challenge window; security rests on "at least one honest verifier will challenge."
- ZK Rollup: ✅ cryptographic instant finality, fast withdrawals, no need to trust challengers; ❌ proof generation is compute-heavy, and EVM compatibility (zkEVM) is brutally hard engineering.
- Sharding / DA layer: ✅ scales data-availability bandwidth horizontally (Ethereum's danksharding direction); ❌ cross-shard transactions are complex, cross-shard atomicity is hard.
Real cases:
- Arbitrum / Optimism: the mainstream Ethereum Optimistic Rollups, cutting gas costs by one-to-two orders of magnitude and absorbing heavy DeFi traffic.
- zkSync / StarkNet / Polygon zkEVM: the ZK Rollup route, compressing via STARK/SNARK proofs, with withdrawals that skip the challenge window.
- Ethereum: the official roadmap is explicitly "rollup-centric" — L1 retreats to settlement + data availability, scaling delegated to L2.
- Bitcoin Lightning Network: a different approach (payment channels, not rollups), moving high-frequency micropayments into bidirectional off-chain channels, touching the chain only to open/close.
Scalability & Optimization (what happens as it grows)
- Throughput wall: don't just enlarge main-chain blocks (bigger blocks = higher full-node hardware bar = decentralization decay — the core of Bitcoin's "block size war"); push TPS onto L2 rollups.
- State bloat: full-node state grows without bound (Ethereum state > hundreds of GB); introduce state expiry / statelessness (stateless clients verify via witness data) to lower the new-node bar.
- Data availability: a rollup's bottleneck shifts from execution to "posting data back to L1"; danksharding / blobs (EIP-4844) reserve cheap data bandwidth for L2.
- Cross-chain interop: multi-chain ecosystems need bridges, but bridges are the #1 hacking hotspot (huge locked value, fragile trust assumptions); prefer light-client verification over multisig custody.
Common Pitfalls + Interview Questions
1. "Immutable" ≠ "correct". The chain only guarantees that what's written can't be changed (tamper-evident); it does not guarantee that what was written is true (garbage in, garbage forever). Oracles feed off-chain truth on-chain and are the weakest, most-manipulated link in the trust chain (DeFi oracle price-manipulation attacks are common).
2. What does a 51% attack actually attack? Not "stealing others' coins" (signatures can't be forged) but double-spending: with majority hash power the attacker can reorg the chain and reverse their own confirmed transactions. Low-cap PoW coins, with cheap hash power, get hit repeatedly.
3. The private key is everything. There is no "reset password": lose the key = assets locked forever, leak the key = assets gone instantly. This is the fundamental UX-vs-security tension; account abstraction (AA) / social recovery are filling the gap.
4. Finality isn't "confirmed = safe". PoW is probabilistic finality — more blocks lower the reorg probability but never to zero; only BFT is deterministic finality. Exchanges requiring many confirmations for large deposits do so for exactly this reason.
5. Frequent interview follow-ups: (1) Why is PoS's attack cost higher than PoW's? (2) Where does the withdrawal-latency gap between Optimistic and ZK rollups come from? (3) Why not store a user avatar on-chain? (4) Why is BFT node count limited, and where does the O(n²) come from? (5) Soft fork vs hard fork compatibility difference?
Crossovers
- Evolutionary biology · The handicap principle (Amotz Zahavi, 1975): A peacock's tail is believable precisely because it is costly and cannot be faked; PoW likewise turns "I cast a vote" into real cost burned, so cheating does not pay. The difference: the tail is expensive in order to advertise the bird's quality, while burned hash power says nothing about a miner's merit and only keeps voting power scarce.
- Animal behavior · Quorum decisions in honeybee swarms (Thomas Seeley): Scout bees inspect candidate nest sites on their own, and once enough scouts gather at one site to reach a quorum, the whole swarm commits, with no queen deciding. It resembles BFT committing only at a 2/3 vote; unlike BFT, the swarm shares one interest and has no lying traitors.
- Economics · The stone money of Yap (Milton Friedman, 1991): Yap's giant stone coins often never move; ownership lives in the island's shared memory of who owes whom, so the ledger is the consensus itself. The difference: it runs on the identity and reputation of a small community, closer to a permissioned chain, and fails among strangers.
- Psychology · Reconstructive memory (Elizabeth Loftus, 1974): Asking whether cars "smashed" or "hit" each other shifts witnesses' speed estimates; human memory is rewritten each time it is recalled. A blockchain is the opposite: nothing written can be changed, but if the first entry is wrong, the error is preserved forever too.
Ten takeaways
- Blockchains differ from ordinary replication in the threat model: nodes do not just crash, they actively lie, forge, and collude.
- Permissionless consensus must make voting power scarce, or an attacker can swing votes with masses of fake identities in a Sybil attack.
- PoW uses hash power, PoS uses staked capital, and BFT uses known identities plus two voting rounds, each paying in speed, capital concentration, or node count.
- PoW offers only probabilistic finality, where more blocks lower reorg risk but never to zero; BFT commits deterministically in one block.
- Smart contracts must produce identical results on every node, which rules out true randomness, system clocks, floating point, and network calls.
- Gas prices every opcode and is prepaid by the caller, and running out reverts the call, turning the halting problem into a fee and blocking DoS.
- In 2016 The DAO lost about 3.6 million ETH to a reentrancy bug that paid out before zeroing the balance; the fix is to update state before external calls.
- Hash chaining means altering any past block requires redoing all later consensus, and a Merkle proof lets a light client verify a transaction with O(log n) hashes.
- Storing only an IPFS content hash on-chain prevents tampering but not disappearance: content no node pins can never be retrieved.
- Immutable does not mean correct: the chain locks in what was written but cannot tell whether it was true, and oracles are the weakest link.
Deeper Resources
- Bitcoin Whitepaper (Nakamoto, 2008): the origin of PoW, Merkle, and SPV — Nakamoto consensus explained in 9 pages.
- "Designing Data-Intensive Applications" (Kleppmann) Ch. 8-9: Byzantine faults, consensus, and consistency from a systems view, placing blockchain back in the distributed-systems lineage.
- ethereum.org — The Merge: the official account of the PoS switch, energy, and slashing.
- Vitalik Buterin's blog (vitalik.eth.limo): first-hand writing on the trilemma, the rollup-centric roadmap, and PoS design.
Going Deeper (click to expand)
1. What exactly is PoS's "nothing-at-stake" problem? Why does PoW not have it naturally, and why does PoS need slashing to fix it?
The essence: during a fork, a PoW miner's hash power is physically exclusive — the same rig mining chain A can't simultaneously mine chain B, so betting on a fork splits hash power and carries a real opportunity cost. A PoS validator, however, can sign votes on every fork at near-zero cost (signing barely consumes resources), so the rational strategy is "vote on all of them" to collect rewards no matter which chain wins. The result: nothing converges to a single chain and consensus collapses.
The fix, slashing: the protocol declares "signing two conflicting blocks" a cryptographically provable offense; once reported, the validator's stake is confiscated and they are ejected, turning "vote-on-all is free" into "vote-on-all gets you bankrupted" and restoring the opportunity cost. Second-order effect: validators now risk "fat-fingered double-signing" (misconfig, bugs), which spawned Distributed Validator Technology (DVT) to reduce single-point mis-slashing.
2. Why did Bitcoin choose ~10-minute blocks while Solana chases 400ms? Is faster always better? What does speed cost in a distributed system?
The core constraint is network propagation latency. Broadcasting a block across a global P2P network takes time (seconds). If the block interval approaches propagation latency, two miners produce blocks "before receiving each other's" → frequent forks (orphan/stale blocks). Nakamoto deliberately set the interval to 10 minutes, far above propagation latency, so forks are rare and the chain converges cleanly — at the cost of being slow.
How Solana hits 400ms: Proof of History pre-orders transactions (a cryptographic clock), cutting the "whose turn is it now" coordination overhead, while requiring validators to run high-spec hardware. The cost: a high hardware bar → fewer nodes → decentralization decay; thin fault-tolerance margin, with repeated network-wide halts for hours in 2022 from traffic surges/bugs. This is the trilemma in the flesh: throughput bought with decentralization and stability — fast blocks are spent safety margin.
3. Smart contracts require "every node computes the exact same result." Which everyday programming habits does this determinism constraint forbid, and what happens if you break it?
- True randomness:
random() differs per node → state fork. On-chain "randomness" can only use reproducible pseudo-randomness (e.g. block hash), which miners can manipulate (MEV).
- Reading system time: wall clocks differ per node; you can only use the block timestamp (an approximate value the producer fills), accurate to seconds and slightly manipulable.
- Floating point: IEEE 754 can differ subtly across architectures/compilers → the EVM has integers only, with amounts in the smallest integer unit (wei).
- External I/O / network: a contract can't directly HTTP-fetch data (not reproducible). External data must come via an oracle writing the value into a transaction, so all nodes replay the same fixed value.
- Unbounded gas loops: a loop length driven by external input can exhaust gas and revert, becoming a denial-of-service surface.
Breaking determinism doesn't throw an error — it makes different nodes reach different state roots, so consensus can't align → the chain splits. That's why the EVM cuts these sources out at the instruction-set level.
4. Storing data on IPFS with only the hash on-chain claims "decentralized + immutable." Where's the availability trap, and how is it fundamentally different from "store on S3, keep the URL"?
The trap: immutable ≠ won't disappear. The on-chain hash permanently guarantees "if the content for this CID exists, it is the original content" (tamper-evident), but nobody guarantees that content stays stored. IPFS is content-addressed; content is online only while some node actively pins it — if every pinning node goes offline, the content is unretrievable: the hash is still on-chain, pointing into the void. Many early NFT "images disappearing" was exactly the project stopping its pinning service.
vs S3+URL: an S3 URL is location addressing — content can be silently swapped while the URL stays the same — not tamper-evident. An IPFS CID is content addressing — change the content and the CID changes — so tamper-evident but equally without availability guarantees. Both need a "someone keeps storing it" incentive; the only difference is "can tampering be detected." True durability requires Filecoin (storage proofs + incentives) or Arweave (pay once, stored forever), which fold storage availability into the incentive.
5. A banking consortium wants a cross-bank settlement ledger and an engineer suggests "put it on Ethereum mainnet." As the architect, would you object? When do you truly need a permissionless public chain?
Most likely yes, object to mainnet. The consortium wants "members share one tamper-evident, auditable ledger and skip reconciliation," but members are known and regulated — which is precisely where you don't need a permissionless chain's most expensive property: Sybil- and censorship-resistant open consensus. On a public chain you'd also hit: privacy (all transactions public, breaking financial confidentiality), throughput (~15 TPS nowhere near enough), fee volatility, and uncontrollable compliance (assets on an uncontrolled public network).
What to use instead: a permissioned / consortium chain (Hyperledger Fabric, R3 Corda, Quorum) — BFT consensus among known validators for deterministic finality, with orders-of-magnitude higher throughput, private channels, and controllable governance. In essence it gives up "trust no one" for "decentralize within a gated, small trust circle."
When you genuinely need a public chain: when participants can't be determined in advance, distrust each other, and need censorship-/single-shutdown-resistance — e.g. public asset issuance to any global user, trustless cross-border value transfer. A litmus test: if you can write a whitelist of "who may write," you probably don't need a permissionless public chain.