Maps to: CMU 15-440/640 Spring 2026, learning outcome “consensus: distributed lotteries (proof-of-work, proof-of-stake, aka blockchain)”; the course’s reference text, E. Shi, Foundations of Distributed Consensus and Blockchains (2020 manuscript, chapters 14, 15 and 18). Problem set: PS4 asks when a blockchain is the right framework and weighs it against alternatives. This lecture gives the concepts (§8) and answers nothing there; its exercises are quantitative and different. Sources:
- S. Nakamoto, Bitcoin: A Peer-to-Peer Electronic Cash System (2008);
- J. Douceur, The Sybil Attack (IPTPS 2002);
- C. Dwork and M. Naor, Pricing via Processing or Combatting Junk Mail (CRYPTO 1992);
- J. Garay, A. Kiayias and N. Leonardos, The Bitcoin Backbone Protocol (EUROCRYPT 2015);
- R. Pass, L. Seeman and A. Shelat, Analysis of the Blockchain Protocol in Asynchronous Networks (EUROCRYPT 2017);
- I. Eyal and E. G. Sirer, Majority Is Not Enough: Bitcoin Mining Is Vulnerable (FC 2014);
- M. Rosenfeld, Analysis of Hashrate-Based Double Spending (2014);
- C. Grunspan and R. Pérez-Marco, Double Spend Races (2018);
- C. Decker and R. Wattenhofer, Information Propagation in the Bitcoin Network (P2P 2013);
- A. Kiayias et al., Ouroboros (CRYPTO 2017);
- V. Buterin and V. Griffith, Casper the Friendly Finality Gadget (2017).
The slides are not public; this is not a transcript. Every number not attributed to a source comes from
code/lecture23/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Everything is simulated and seeded except the labelled SHA-256 timings. Code:code/lecture23/. Reading time: ~90 minutes, plus ~1 to run the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Explain why voting by identity fails when anyone may join (the Sybil attack), and what proof of work and proof of stake count instead.
- Describe a proof-of-work puzzle: why it is hard to solve, easy to check, and a lottery.
- State Nakamoto’s protocol (mine on the longest chain; a block K deep is final), and its formal guarantees: chain growth, chain quality, consistency, and the role of network delay.
- Compute the probability of a double spend after z confirmations, and explain why “6 confirmations” depends on assumptions.
- Explain selfish mining and why an honest majority does not make honesty rational.
- Explain difficulty adjustment as a feedback loop, and its failure modes.
- Describe proof of stake: stake lotteries, randomness and grinding, nothing at stake and slashing, and finality with accountable safety.
- Compare blockchains with Paxos and BFT, and say when a blockchain is the wrong tool.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 14: Byzantine agreement, n ≥ 3f + 1, signatures;
- Lectures 19–21: quorums, Paxos, replicated logs;
- Lecture 12: feedback control;
- Lecture S1: happened-before (helpful).
- Scope: the consensus layer of blockchains, i.e. agreement on an ordered log by an open, changing set of participants. Not covered: cryptocurrency economics, smart-contract languages, transaction formats, Merkle trees beyond one sentence, privacy, or wallets.
0.3 Section → code map
| Section | Idea | Demo in code/lecture23/ |
|---|---|---|
| §1–2 | Sybil attacks; proof of work | 01_sybil_and_work.py, pow.py |
| §3 | the longest chain; forks; difficulty | 02_forks.py, 05_difficulty.py, chainsim.py |
| §4 | double spending | 03_double_spend.py, nakamoto.py |
| §5 | incentives; selfish mining | 04_selfish_mining.py |
| §6 | proof of stake | 06_proof_of_stake.py, stake.py |
| §7–8 | comparison; when not to use one | (notes) |
0.4 Notation
- Hash power shares: an attacker or pool holds a fraction q (also written α or ρ) of the total hash power; honest miners hold p = 1 − q.
- T is the mean block interval: 10 minutes in Bitcoin. Δ is the network’s propagation delay.
- z (or K) is the number of confirmations: a transaction is buried z blocks deep when the merchant accepts it.
- d bits of difficulty: a hash must be below 2^(256 − d), so a block takes 2^d tries on average.
1. Consensus without a membership list (demo 01 Part A)
1.1 Permissioned and permissionless
Every consensus protocol so far assumed a known set of participants:
- two-phase commit’s participants;
- Paxos’s acceptors, whose majorities we count;
- Byzantine agreement’s n generals, of whom at most f misbehave.
Shi calls such settings permissioned: a few to a few dozen machines, configured in advance, usually run by one organization.
Bitcoin, launched in 2009, solved a problem the classical literature considered impossible. Consensus in a permissionless setting: anyone may join or leave at any time, under any name, communicating over unauthenticated channels.
1.2 The Sybil attack
Douceur’s Sybil attack is the reason it seemed impossible. If participants cannot be tied to real-world entities, one attacker can appear as many participants. Majority voting then measures the attacker’s willingness to create names, not the community’s opinion.
In demo 01 Part A, 101 made-up identities outvote 100 honest participants. Creating them costs the attacker nothing. Douceur showed that without a trusted authority that certifies identities, Sybil attacks cannot be prevented except under unrealistic assumptions. Pass and Shi formalized the intuition: absent other assumptions, consensus is impossible in a permissionless environment.
The way out is to count something that cannot be multiplied for free:
- computation, in proof of work: one vote per hash evaluated;
- coins, in proof of stake: one vote per unit of currency locked up.
Both turn voting into a lottery. Each round, one participant wins the right to extend the log, with probability proportional to its share of the scarce resource.
2. Proof of work (demo 01 Parts B–D)
2.1 The puzzle
A block’s header binds three things: the previous block’s hash, a digest of the block’s transactions, and a nonce. The block is valid if
i.e. its hash begins with d zero bits. The idea goes back to Dwork and Naor’s 1992 proposal of making e-mail senders solve puzzles to price out spam.
For a good hash function nobody knows a better method than trying nonces. Each try succeeds independently with probability 2^−d, so the number of tries is geometric with mean 2^d. Real SHA-256 on this machine (demo 01 Part B; the timings are real measurements):
| difficulty | expected tries 2^d | mean tries (20 blocks) | std. dev. | time per block | time to verify |
|---|---|---|---|---|---|
| 8 bits | 256 | 382 | 391 | < 1 ms | 0.5 µs |
| 16 bits | 65,536 | 86,140 | 73,653 | 0.04 s | 0.5 µs |
| 20 bits | 1,048,576 | 737,140 | 789,274 | 0.31 s | 0.5 µs |
Two properties make this useful:
- Asymmetry: solving took 0.3 s, checking one hash 0.5 µs. Anyone can verify a block, and a chain of them, cheaply.
- Randomness: the number of tries varies as much as its mean. Mining is a lottery; a miner with twice the hash power holds twice as many tickets.
Python computes about 2.4 million SHA-256 per second here. Bitcoin’s network in the mid-2020s computes several times 10^20 hashes per second, with chips built for nothing else; at 600 s per block its puzzles need around 2^78 tries.
2.2 Chaining makes history expensive to rewrite
Each header contains its predecessor’s hash. Changing a transaction in block k changes block k’s hash, which breaks the link from block k + 1, and so on to the end. In demo 01 Part C, changing block 1 of a 12-block chain invalidated every block, and redoing them would cost all 866,871 hashes the chain had cost.
The deeper a block, the more work must be redone, while the honest network keeps extending the real chain. That race is the security argument of §4.
2.3 A fair lottery
Block discovery is a Poisson process: the time to the next block anywhere in the network is exponential, and each block is miner i’s with probability equal to its share of the power. In demo 01 Part D, chainsim.py (simulated races, 3,000 blocks) gave miners with 40/30/20/10% of the power shares of the main chain within 0.8 percentage points of that. §3.3 shows when this fairness breaks.
3. Nakamoto’s protocol (demos 02 and 05)
3.1 The rule
Shi describes the “barebone” protocol:
- every node keeps the longest valid chain it has seen (in Bitcoin, the one with the most cumulative work);
- every node mines on the end of that chain, and broadcasts any block it finds;
- on receiving a longer valid chain, a node switches to it;
- a node’s finalized log is its chain minus the last K blocks.
Nobody votes, nobody counts a quorum, nobody needs to know who else participates. A block’s position in the chain is its “vote”, weighted by the work behind it.
3.2 Why it works, and what it needs
Garay, Kiayias and Leonardos (2015) and Pass, Seeman and Shelat (2017) proved the guarantees. Shi’s chapter 14 states them for a synchronous network with delay at most Δ:
- chain growth: honest nodes’ chains grow at a steady rate, at least (1 − ε)(1 − 2pnΔ)α per round, where α is the honest mining rate;
- chain quality: in any K consecutive blocks, a guaranteed fraction was mined by honest nodes;
- consistency (common prefix): any honest node’s chain minus its last K blocks is a prefix of every honest node’s later chain.
They hold with overwhelming probability if K is large enough and
That is, the honest mining power, discounted by the network delay, must exceed the corrupt power. The discount is the heart of the matter. While an honest block is in flight, other honest miners still work on the old tip, so their work may be wasted. An attacker mining a private fork on a fast private network suffers no such loss. The faster the blocks relative to the delay (pnΔ is about Δ/T), the larger the honest majority must be.
3.3 Forks in practice (demo 02)
chainsim.py runs 20 equal miners with one-way delays of 1–3 s (mean 2 s):
| block interval T | stale blocks | estimate 1 − e^(−2 s/T) | reorganizations of depth ≥ 2 | deepest | main-chain blocks per T |
|---|---|---|---|---|---|
| 600 s | 0.36% | 0.33% | 0 | 1 | 1.01 |
| 60 s | 3.08% | 3.28% | 0 | 1 | 0.98 |
| 12 s | 14.2% | 15.4% | 70 | 2 | 0.87 |
| 4 s | 31.6% | 39.4% | 590 | 3 | 0.70 |
| 2 s | 46.3% | 63.2% | 1,559 | 4 | 0.55 |
- A block goes stale when another is found while it is still propagating, so the stale rate is about 1 − e^(−Δ/T) while T ≫ Δ. Decker and Wattenhofer measured Bitcoin’s real network in 2013 and found a fork rate of about 1.7%, driven by propagation times of seconds.
- Stale blocks are wasted honest work. With 2-second blocks the main chain grew only 0.55 blocks per interval: the “discounted honest power” of the theorem, visible.
- Deep reorganizations appear only when the interval nears the delay. That is why confirmations are counted in blocks, and why fast chains need more of them.
- Fast blocks favour big miners. A miner with 30% of the hash power got 29.7% of the main chain with 10-minute blocks, but 41.4% with 2-second blocks. It never races its own blocks, while the small miners waste work racing each other. Latency is a pressure towards centralization, one reason Bitcoin’s interval is long.
3.4 Keeping the pace: difficulty adjustment (demo 05)
Nobody knows the total hash power of an open system, and it changes as miners come and go. Bitcoin therefore retargets: every 2,016 blocks (two weeks at 10 minutes) the difficulty is multiplied by (2016 × 10 min) / (time the last 2,016 blocks took), clamped to a factor of 4. This is a feedback controller (Lecture 12) with a long measurement window and discrete action.
| event (at a retarget) | window | mean interval until the next retarget | time until it |
|---|---|---|---|
| hash rate doubles | 2,016 | 309 s | 7.2 days |
| hash rate halves | 2,016 | 1,237 s | 28.9 days |
| hash rate halves | 144 | 1,654 s | 2.8 days |
- The controller is slow. When half the hash power left, the chain ran at half speed for almost a month, and the slower it runs, the later the next correction comes.
- The long-run mean holds at about 600 s, but single intervals are a lottery: 67 of 30,000 blocks took more than an hour.
- Short windows trade speed for noise. A 144-block window recovers in days but measures noisily: the average interval wandered by 78 s from one window to the next, against 19 s for 2,016 blocks. Each window’s error is carried into the next difficulty, and miners have more opportunity to game the timestamps it relies on.
4. How final is final? Double spending (demo 03)
4.1 The attack
Alice pays a merchant; the payment enters a block. Meanwhile Alice secretly mines a competing chain from the block before, in which the coins go back to herself. When the merchant has seen z confirmations, it ships. If Alice’s secret chain then becomes longer than the public one, she publishes it, nodes switch to it, and the payment vanishes from history.
4.2 Nakamoto’s estimate, and the exact answer
Nakamoto (§11 of the whitepaper) models the race as follows:
- the attacker’s progress while the honest chain adds z blocks is a Poisson variable with mean z q/p;
- from a deficit of k blocks, he catches up with probability (q/p)^k, the gambler’s-ruin result.
nakamoto.py implements his formula line for line and reproduces his table: for q = 0.1, z = 5 gives 0.0009137.
The number of attacker blocks found while the honest miners find z is not Poisson but negative binomial: it also depends on how long the honest blocks happened to take. Rosenfeld (2014) and Grunspan and Pérez-Marco (2018) pointed out that this makes Nakamoto’s formula optimistic. Demo 03 computes three versions and checks the last against 200,000 simulated races per cell:
| q | z | Nakamoto | exact, same convention (catching up suffices) | exact, payment block counted, strictly longer needed | simulated (the latter) |
|---|---|---|---|---|---|
| 0.1 | 1 | 0.2046 | 0.2000 | 0.0311 | 0.0320 |
| 0.1 | 6 | 0.000243 | 0.000591 | 0.000110 | 0.000055 |
| 0.2 | 6 | 0.0143 | 0.0233 | 0.0088 | 0.0086 |
| 0.3 | 6 | 0.1321 | 0.1565 | 0.0891 | 0.0888 |
| 0.4 | 10 | 0.3600 | 0.3722 | 0.2906 | 0.2912 |
- Nakamoto’s convention, done exactly, gives 2.4 times his estimate at q = 0.1 and 6 confirmations.
- The convention matters almost as much as the approximation. Does the payment’s block count as the first confirmation? Must the attacker be strictly ahead, or is a tie enough? “Six confirmations” means nothing until the race is defined.
- Simulation and the exact formula agreed to within 0.0017 absolute in every cell. Events near 1 in 10,000 are too rare for 200,000 races to pin down, which is exactly where the formula is needed.
4.3 How long to wait
Confirmations needed for a risk below 0.1%:
| attacker’s share q | Nakamoto | exact, catch up | exact, strictly longer | wait at 10-min blocks |
|---|---|---|---|---|
| 0.10 | 5 | 6 | 4 | 0.7 h |
| 0.20 | 11 | 13 | 11 | 1.8 h |
| 0.30 | 24 | 32 | 29 | 4.8 h |
| 0.40 | 89 | 133 | 128 | 21.3 h |
| 0.45 | 340 | 539 | 530 | 88.3 h |
Three lessons:
- Finality is a probability that shrinks with waiting, never a certainty. The common rule of thumb, K = 6 or about an hour (Shi), assumes a modest attacker.
- Waiting buys little against a large attacker: against 40% of the hash power, 0.1% risk needs about a day.
- At q ≥ 1/2, waiting does not help at all. A random walk with no drift, or a drift towards the attacker, catches up eventually. In demo 03 Part C, a 50% attacker overtook in 98% of races, even giving up 100 blocks behind, and a 55% attacker in all of them.
Majority attacks are not hypothetical for small proof-of-work chains. Hash power can be rented, and smaller chains such as Ethereum Classic and Bitcoin Gold have suffered double-spend attacks by miners who briefly controlled most of their hash power.
5. Incentives: is honesty rational? (demo 04)
5.1 Rewards
Mining costs hardware and electricity, so Bitcoin pays miners. Each block grants a block reward and the transaction fees of the transactions it includes. Shi recounts the schedule: 50 bitcoins at first, halving every 210,000 blocks (about four years), and reaching zero around 2140, after which fees alone remain.
The security argument assumes an honest majority. In a permissionless system “honest” must mean “rational”: following the protocol must be in each miner’s interest.
5.2 Selfish mining
Eyal and Sirer (2014) showed it is not. A pool with hash share α can follow this strategy:
- keep the blocks it finds secret;
- when the honest network finds a block, publish just enough to orphan it:
- with a lead of 1, publish and race (a fraction γ of honest miners build on the pool’s block);
- with a lead of 2, publish both and orphan the honest block;
- with a larger lead, publish one block at a time and stay ahead.
The pool loses some of its own blocks but destroys more honest ones, so its share of the chain grows.
| pool’s hash power α | γ = 0 | γ = 0.5 | γ = 1 |
|---|---|---|---|
| 0.10 | 0.035 | 0.073 | 0.109 |
| 0.25 | 0.194 | 0.250 | 0.304 |
| 0.30 | 0.273 | 0.324 | 0.381 |
| 1/3 | 0.334 | 0.385 | 0.436 |
| 0.40 | 0.484 | 0.526 | 0.570 |
Bold entries are larger than α, i.e. selfish mining pays. The simulation matched Eyal and Sirer’s closed form within 0.003 in every cell.
- The profitability threshold is α > (1 − γ)/(3 − 2γ): 1/3 if the pool never wins a tie, 1/4 if it wins half of them, and 0 if it controls the network. “Majority is not enough”: a coalition of a quarter to a third of the miners can gain by deviating, and once it gains, others have reason to join it, and the honest majority the security proofs assume erodes.
- The cost falls on everyone: at α = 0.4 and γ = 0.5, 29.5% of all blocks were orphaned, honest work thrown away.
- Shi’s back-of-the-envelope analysis lets every selfish block erase one honest block and bounds the pool’s share by ρ/(1 − ρ): about 1/2 with a third of the power, 96% with 49%. Eyal and Sirer’s strategy stays below this even when it wins every tie (0.570 against 0.667 at α = 0.4), because with a lead of 2 it spends two blocks to orphan one.
Shi points out that nobody knows whether selfish mining has happened on Bitcoin; it would be hard to detect. Designs such as Fruitchain (Pass and Shi 2017) pay rewards for small “fruits” that cannot be erased, which makes honest mining an approximate equilibrium.
5.3 Pools
Because rewards are a lottery, small miners join pools that share rewards in proportion to work. The variance falls, but a few pool operators then decide what most of the hash power mines on. Demo 02 showed latency favouring big miners; pools are the economic version of the same centralizing pull.
6. Proof of stake (demo 06)
6.1 Coins instead of hashes
Proof of work’s cost is its point: security is bought with energy. Shi quotes the Digiconomist estimate of 66.7 TWh per year for Bitcoin in June 2019, comparable to the Czech Republic. Proof of stake replaces computation by stake. A validator locks up coins, and its chance of producing a block, or its voting weight, is proportional to them. Ethereum moved from proof of work to proof of stake in September 2022.
Shi’s observation is that, at any moment, proof of stake is permissioned consensus. The validator set and its public keys are known from the chain itself, and it is reconfigured periodically as stake changes hands, much like Lecture 21’s membership changes.
6.2 A lottery over coins (demo 06 Parts A, B)
Each slot’s leader is the validator whose stake interval contains a pseudo-random point derived from a public seed and the slot number. Anyone can recompute it, and there is no hashing race. Over 20,000 slots, validators with 40/30/20/10% of the stake led within 0.4 percentage points of their shares.
The weak point is the seed. If the next epoch’s seed is derived from the chain’s last blocks, a validator that leads some of the last slots can grind: publish or skip its blocks, compute the resulting seeds, and pick the one that gives it more slots next time.
| attacker’s stake | last slots it may skip | slots it led | gain over its share |
|---|---|---|---|
| 11% | 1 | 10.71% | +0.7% |
| 11% | 8 | 13.75% | +29.3% |
| 30% | 1 | 31.33% | +4.4% |
| 30% | 8 | 42.80% | +42.7% |
The more stake, the more often a validator controls the end of an epoch and the more seeds it can choose from. Real protocols reduce this choice with verifiable random functions, where each validator’s lottery ticket is a function of its secret key that others can verify but not predict, and with commit-reveal randomness and delays.
6.3 Nothing at stake (demo 06 Part C)
In proof of work, mining on two forks splits one’s hash power, so a miner picks one. In proof of stake, signing a block on two forks costs nothing. A rational validator signs both, so that its block survives whichever fork wins.
| validators signing both forks | forks resolved (of 200) | double signers’ blocks rewarded | single signers’ blocks rewarded |
|---|---|---|---|
| 0% | 200 | — | 75% |
| 50% | 200 | 100% | 75% |
| 90% | 197 | 98% | 79% |
| 100% | 0 | — | — |
Validators who follow the rules sometimes cannot tell which fork others are extending; they back the loser a quarter of the time. Double signers never lose. If everyone acts on that incentive, forks never resolve.
The cure is slashing. Two signatures by the same validator on conflicting blocks are a self-contained proof of misbehaviour, which anyone can submit to have that validator’s locked stake destroyed. A penalty larger than the gain from double signing (25% of a block’s reward in this model) removes the incentive.
A related problem is the long-range attack. Validators who have since withdrawn their stake can no longer be slashed, but they still hold the old keys and could sign an alternative history from long ago. Proof-of-stake systems therefore have new nodes start from a recent trusted checkpoint, which is called “weak subjectivity”.
6.4 Finality with accountable safety (demo 06 Part D)
Many proof-of-stake systems add a BFT-style finality layer on top of a block-producing lottery. In Casper FFG, a checkpoint is finalized when validators holding 2/3 of the stake have voted for it. Suppose two conflicting checkpoints are both finalized. Then two sets of voters, each with at least 2/3 of the stake, must overlap in at least 1/3 of the stake, and every validator in the overlap signed both. The signatures convict them. Buterin and Griffith call this accountable safety.
Demo 06 checked it exhaustively over 200 random stake distributions on 7 validators:
| finality threshold | least stake that voted for both | guaranteed 2t − 1 |
|---|---|---|
| 2/3 | 0.333 | 0.333 |
| 51% | 0.020 | 0.020 |
With a bare majority, a violation might implicate only 2% of the stake: too few culprits to deter an attack or to repair it. This is Lecture 14’s n ≥ 3f + 1, and Lecture 19’s quorum intersection, read as accountability. Finality is deterministic: a finalized block is never reverted unless a third of the stake is provably destroyed. Compare that with the probabilistic finality of §4.
7. Blockchains next to Paxos and BFT
| Multi-Paxos / Raft (Lectures 20–21) | PBFT-style BFT (Lecture 14) | Nakamoto proof of work | proof of stake with a finality layer | |
|---|---|---|---|---|
| participants | known, fixed (reconfigurable) | known, fixed | anyone, unknown, changing | anyone with stake; known committee per epoch |
| failures tolerated | f crashes of 2f + 1 | f Byzantine of 3f + 1 | attacker hash power below the delay-discounted honest power | under 1/3 of stake for finality |
| Sybil resistance | not needed (membership) | not needed | work | stake |
| finality | deterministic, once a majority accepts | deterministic, after 2f + 1 votes | probabilistic, improves with depth (§4) | deterministic and accountable once finalized |
| timing assumption | none for safety; partial synchrony for progress | as Paxos | synchrony with a known Δ for safety | partial synchrony for finality; synchrony assumptions in the block layer |
| decision latency | about one round trip (8 ms in Lecture 21’s simulated data centre) | a few round trips | many block intervals (about an hour for 6 confirmations at 10 minutes) | a few epochs’ worth of slots, typically minutes |
| cost per decision | a few messages and forced writes | O(n²) messages | 2^d hash evaluations per block | signatures and messages |
The comparison shows what blockchains buy and at what price:
- What they buy: agreement among participants who do not know or trust each other, may come and go, and are not admitted by anyone. No other design in this course offers that.
- What they pay:
- latency (probabilistic finality in proof of work);
- throughput, since every node processes every transaction and blocks are small and spaced to keep forks rare;
- energy, in proof of work;
- incentive engineering against strategies like selfish mining and nothing at stake;
- a synchrony assumption in the security proof of the longest-chain rule. Paxos needs none for safety.
8. When a blockchain is the wrong tool
The general questions come from Wüst and Gervais (2018), “Do you need a blockchain?”. They are a checklist, not a verdict.
- Is there shared state written by several parties? If not, a database suffices.
- Can the writers agree on a trusted party, an operator, a consortium-run service or an auditor? If so, a conventional replicated database (Lectures 19–21) with that party’s authentication is faster, cheaper and simpler.
- Are the writers known? If they are, permissionless consensus pays for Sybil resistance it does not need. A permissioned BFT protocol among the known writers gives deterministic finality at a fraction of the cost.
- Is public verifiability needed? Can anyone, not only the writers, check the history without trusting them? This is the property where a public ledger is distinctive.
- Can the application live with the costs? These are minutes to hours of probabilistic finality (proof of work), modest throughput, permanent public storage of everything (a problem for privacy and for any “right to be forgotten”), and the energy cost of proof of work.
Blockchains solve a specific problem, consensus without an admission authority, and solve it at a real cost. Many proposed uses have known participants, a natural trusted party, or both. For those, the protocols of Lectures 18–21 are the better tool. Exercise 8 asks you to apply these questions to a situation of your own.
9. Design rules
- Count a scarce resource, not identities, when membership is open.
- Make verification cheap and production costly, and chain the records so that rewriting history costs all the work since.
- Keep the block interval long relative to propagation delay, or forks waste honest power and favour large miners.
- State the race before quoting confirmations: attacker share, convention, and acceptable risk.
- Treat “honest majority” as an incentive question: check that following the protocol is rational (selfish mining, nothing at stake).
- Make misbehaviour provable and costly (slashing, accountable safety with 2/3 quorums).
- Protect the randomness that drives any lottery.
- Use a blockchain only when the participants are unknown and no party can be trusted; otherwise use the permissioned protocols.
Summary
- Open membership defeats voting: 101 free identities outvote 100 honest participants. Proof of work counts hashes; proof of stake counts coins.
- Proof of work is a lottery with costly tickets and cheap verification: about 0.3 s to solve a 20-bit puzzle against 0.5 µs to check one (real). Chaining makes rewriting history cost all subsequent work.
- Nakamoto’s protocol: mine on the longest chain; blocks K deep are final. It is secure if the honest power, discounted by network delay, exceeds the attacker’s.
- Forks grow with delay over interval: 0.36% stale at 10-minute blocks, 46% at 2-second blocks.
- Short intervals favour big miners: 30% of the power earned 41% of the chain at 2-second blocks.
- Double spending:
- Nakamoto’s estimate is optimistic: 2.4× too low at q = 0.1, z = 6;
- the conventions of the race matter;
- 0.1% risk against a 30% attacker takes about 5 hours of 10-minute blocks;
- against 50%, no wait suffices.
- Selfish mining pays above a quarter to a third of the hash power. Honest majority is not an equilibrium.
- Difficulty adjustment is a slow feedback loop: half the hash power leaving stretched two weeks of blocks to 29 days.
- Proof of stake:
- a fair coin lottery, as long as the seed resists grinding (+43% for a 30% validator controlling 8 slots);
- nothing at stake requires slashing (double signing paid 100% against 75%);
- 2/3-stake finality makes safety violations provable against at least 1/3 of the stake.
- Against Paxos and BFT, blockchains trade latency, throughput, energy and incentive engineering for consensus without a membership list.
Common pitfalls
- “Six confirmations is safe”, without saying against what share of the hash power, under which race model, at what risk.
- “An attacker needs 51%”: double spends succeed with any share given enough luck, and are certain at 50%; selfish mining pays well below 50%.
- Shortening the block interval to cut latency, ignoring forks, wasted work and centralization.
- Assuming honest majority in a system where honesty is not the rational strategy.
- Treating proof of stake as proof of work without the energy: it changes the attack surface (grinding, nothing at stake, long-range attacks) and needs penalties.
- Using a bare-majority finality vote: violations cannot be attributed to enough culprits.
- Reaching for a blockchain when the participants are known or a trusted party exists.
Exercises
-
Puzzle arithmetic. A network computes 4 × 10^18 hashes per second and wants one block per 10 minutes. (a) What difficulty (in bits) does that require? (b) A miner with 0.1% of the hash power: what is its expected time between blocks, and the probability of finding none in a whole day? (c) Why do such miners join pools, and what does that do to the decentralization argument?
Answer
(a) The network must make about 4 × 10^18 × 600 = 2.4 × 10^21 tries per block, so 2^d ≈ 2.4 × 10^21 and d ≈ log2(2.4 × 10^21) ≈ 71.0 bits. (b) Its rate is 0.001 blocks per 10 minutes, so it expects one block per 10,000 minutes, about 6.9 days. Blocks in a day are Poisson with mean 0.144, so P(none) = e^−0.144 ≈ 0.87. (c) Income from a lottery that pays out once a week on average, with high variance, is hard to plan around. Pools pay steadily in proportion to work. But a pool operator chooses the blocks its members mine on, so a handful of operators come to control most of the hash power; the lottery's participants are many, its decision makers few. -
Forks. Blocks take on average 8 s to reach all miners. (a) Estimate the stale rate at 10-minute and 15-second intervals. (b) At 15 s, a miner with 25% of the hash power: why does it end up with more than 25% of the main chain? (c) What does a high stale rate do to the share of hash power an attacker needs?
Answer
(a) 1 − e^(−8/600) ≈ 1.3%; 1 − e^(−8/15) ≈ 41%, an overestimate at such ratios (demo 02 shows the estimate exaggerates when T is close to the delay), but large either way. (b) Its blocks reach its own mining immediately, so it never wastes work on a stale tip of its own, while every small miner loses races against everyone else. Its effective power is less discounted than theirs. (c) Stale honest blocks are wasted honest work; an attacker working on a private fork wastes none. So the attacker competes against the discounted honest power (Shi's condition (1 − ρ)(1 − 2pnΔ) ≥ (1 + φ)ρ), and needs less than half of the raw hash power to outpace it. -
Double spending by hand. q = 0.2. (a) Compute Nakamoto’s estimate for z = 1. (b) In the strictly-longer race (the payment’s block is the one confirmation; the attacker must get strictly ahead), compute the attacker’s chance. (c) Why are the two so different?
Answer
(a) p = 0.8 and λ = zq/p = 0.25. The k = 0 term subtracts e^−0.25 × (1 − (q/p)^1) = 0.7788 × 0.75 = 0.584. The k = 1 term subtracts nothing, since (q/p)^0 = 1. So P ≈ 1 − 0.584 = 0.416. (b) When the honest chain has its 1 block, the attacker has m blocks with probability p q^m. With m = 0 he must gain 2 net blocks: (q/p)^2 = 1/16. With m = 1 he must gain 1: 1/4. With m ≥ 2 (probability q^2 = 0.04) he is already ahead. P = 0.8 × 1/16 + 0.16 × 1/4 + 0.04 = 0.05 + 0.04 + 0.04 = 0.13, which is what `nakamoto.exact(0.2, 1)` returns and 200,000 simulated races confirm (0.130). (c) Nakamoto's model lets the attacker start level with the payment block and counts catching up as success; the second race makes him overtake a chain that already contains the payment. With a single confirmation the convention dominates (the exact catch-up race gives 0.400, close to his 0.416). That is why a number of confirmations means nothing without its model. -
Selfish mining. (a) Using α > (1 − γ)/(3 − 2γ), what share does a pool need if its blocks win 25% of ties? (b) Explain in a few sentences why withholding a block can raise a pool’s share even though the pool sometimes loses its own blocks. (c) Why do the security proofs’ “honest majority” and selfish mining not contradict each other?
Answer
(a) (1 − 0.25)/(3 − 0.5) = 0.75/2.5 = 0.30. (b) Revenue is the pool's share of the blocks in the final chain. A withheld block can orphan an honest block that would otherwise have counted. Even if the pool loses some of its own blocks in races, the denominator (all main-chain blocks) shrinks faster than its numerator, so its fraction rises. In absolute terms everyone produces fewer main-chain blocks per unit time, until difficulty adjusts down. (c) The proofs show consistency and liveness if a majority follows the protocol; they say nothing about whether following it is in a miner's interest. Selfish mining shows it is not, for a large enough pool. That threatens the assumption itself, as rational miners join the deviating pool, rather than the theorem. -
Difficulty. A chain retargets every 1,000 blocks with a 5-minute target and a clamp of 4. Right after a retarget, 75% of the hash power leaves. (a) How long do the next 1,000 blocks take? (b) What does the retarget then do? (c) What if 85% leaves?
Answer
(a) The interval quadruples to 20 minutes, so 1,000 blocks take about 20,000 minutes, nearly 14 days instead of 3.5. (b) The measured time is 4 times the target, so the difficulty is divided by 4 (the clamp allows exactly that) and the pace returns to about 5 minutes. (c) The interval becomes 5/0.15 ≈ 33 minutes, and the window takes about 23 days. The retarget can only divide by 4, leaving blocks at about 8.3 minutes, and a second window is needed. A collapsing hash rate can stretch recovery over months: one reason chains have used faster or smoother difficulty algorithms. -
Stake lottery. Validators hold 50%, 30% and 20% of the stake. (a) Over 100 slots, what are the expected numbers of slots each leads, and the standard deviation for the 20% validator? (b) The 20% validator leads the last slot of an epoch with probability 0.2 and can then choose between two seeds. Each seed gives it a number of slots in the next 100-slot epoch distributed as Binomial(100, 0.2), independently. Estimate its expected gain per epoch from choosing the better seed. (c) Name two mechanisms that remove this choice.
Answer
(a) 50, 30 and 20 slots; standard deviation sqrt(100 × 0.2 × 0.8) = 4. (b) The maximum of two independent draws of mean 20 and standard deviation 4 has mean about 20 + 4 × 0.564 ≈ 22.3. It can choose only when it leads the last slot (probability 0.2), so the expected gain is 0.2 × 2.3 ≈ 0.45 slots per epoch, about 2% over its share. More controlled slots compound this (demo 06 Part B). (c) Seeds that combine contributions committed before they are revealed (commit-reveal, as in RANDAO, plus a delay so the last revealer cannot compute the outcome in time). Or verifiable random functions, so that each validator's eligibility depends on its secret key and the previous seed and cannot be steered by publishing or withholding blocks. -
Accountable safety. A finality layer finalizes with votes from validators holding at least t of the stake. (a) Prove that two conflicting finalized checkpoints imply that validators with at least 2t − 1 of the stake voted for both. (b) For t = 2/3, how much stake can the protocol lose to crashes and still finalize? (c) Why does Nakamoto’s chain offer no comparable accountability?
Answer
(a) Let A and B be the two voting sets, each with stake ≥ t. Then stake(A ∩ B) = stake(A) + stake(B) − stake(A ∪ B) ≥ t + t − 1 = 2t − 1, since the union cannot exceed all the stake. (b) Finalizing needs 2/3 of the stake to vote, so it stalls if more than 1/3 is offline: safety and liveness both rest on the 1/3 bound, as in Lecture 14. (c) Mining a block on a fork is legitimate behaviour: miners are supposed to extend the longest chain they see, and a fork is not a provable offence. A reorganization proves nothing about who misbehaved, and miners have no locked deposit to destroy. -
Choose your own case. Describe a situation where several parties keep a shared record (not one from the problem set). Answer §8’s questions for it, and say which protocol from Lectures 18–23 you would use and what you would give up.
Answer
Answers vary; a good one names the writers, says whether a party exists that all would trust to operate a service, says whether outsiders must verify the record, and quantifies the costs. Example: five hospitals sharing an index of which patient records exist where. The writers are known and few, and a consortium-run service with signed entries and audit logs is acceptable. Public verifiability is not wanted, since privacy forbids it. A permissioned BFT log among the five, or a replicated database run by one with signed updates, fits. A public blockchain would publish sensitive metadata forever and add minutes of latency, for a Sybil resistance nobody needs.
Related project and problem set (concepts only)
- Problem Set 4 asks when a blockchain is the right framework and to weigh a blockchain against conventional services. §7–8 give the concepts and the questions to ask; the PS’s scenarios are not discussed and no answers are given.
- Project 4 builds two-phase commit among known nodes with a coordinator: the permissioned world this lecture contrasts with.
Further reading
- E. Shi, Foundations of Distributed Consensus and Blockchains (2020 manuscript), chapters 14 (Nakamoto’s blockchain), 15 (selfish mining, Fruitchain), 17 (analysis) and 18 (proof of stake) — the course’s reference.
- S. Nakamoto, “Bitcoin: A Peer-to-Peer Electronic Cash System”, 2008.
- J. Douceur, “The Sybil Attack”, IPTPS 2002.
- J. Garay, A. Kiayias and N. Leonardos, “The Bitcoin Backbone Protocol: Analysis and Applications”, EUROCRYPT 2015.
- R. Pass, L. Seeman and A. Shelat, “Analysis of the Blockchain Protocol in Asynchronous Networks”, EUROCRYPT 2017.
- I. Eyal and E. G. Sirer, “Majority Is Not Enough: Bitcoin Mining Is Vulnerable”, Financial Cryptography 2014.
- A. Sapirshtein, Y. Sompolinsky and A. Zohar, “Optimal Selfish Mining Strategies in Bitcoin”, Financial Cryptography 2016.
- M. Rosenfeld, “Analysis of Hashrate-Based Double Spending”, 2014; C. Grunspan and R. Pérez-Marco, “Double Spend Races”, 2018.
- C. Decker and R. Wattenhofer, “Information Propagation in the Bitcoin Network”, IEEE P2P 2013.
- A. Kiayias, A. Russell, B. David and R. Oliynykov, “Ouroboros: A Provably Secure Proof-of-Stake Blockchain Protocol”, CRYPTO 2017.
- V. Buterin and V. Griffith, “Casper the Friendly Finality Gadget”, 2017.
- K. Wüst and A. Gervais, “Do You Need a Blockchain?”, CVCBT 2018.
Preview of Lecture 24 — Programming paradigms: MapReduce, MPI and GraphLab
From agreeing on a log we turn to computing at scale. Lecture 24 compares three ways of programming many machines:
- MapReduce: data-parallel batch jobs, with fault tolerance by re-execution, which requires deterministic tasks and atomic commits of their outputs;
- MPI: explicit messages and collectives such as allreduce, with bulk-synchronous steps and checkpointing;
- GraphLab and Pregel: vertex programs that gather, apply and scatter along a graph’s edges.
Each is checked against a sequential answer, and the lecture asks what each makes easy, what it makes hard, and how it survives failures.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| permissioned / permissionless | 许可型 / 无许可型 |
| Sybil attack | 女巫攻击 |
| proof of work (PoW) / proof of stake (PoS) | 工作量证明 / 权益证明 |
| hash puzzle / nonce / difficulty | 哈希难题 / 随机数(nonce) / 难度 |
| block / block header / genesis block | 区块 / 区块头 / 创世区块 |
| hash chain (tamper evidence) | 哈希链(防篡改) |
| miner / mining / mining pool | 矿工 / 挖矿 / 矿池 |
| longest-chain rule (most cumulative work) | 最长链规则(累计工作量最大) |
| fork / stale (orphaned) block / reorganization | 分叉 / 孤块(陈旧区块) / 链重组 |
| confirmation / finality (probabilistic, deterministic) | 确认 / 最终性(概率性、确定性) |
| chain growth / chain quality / consistency (common prefix) | 链增长 / 链质量 / 一致性(公共前缀) |
| propagation delay | 传播延迟 |
| double spend / 51% attack | 双花 / 51% 攻击 |
| gambler’s ruin / negative binomial | 赌徒破产 / 负二项分布 |
| selfish mining | 自私挖矿 |
| incentive compatibility / equilibrium | 激励相容 / 均衡 |
| block reward / transaction fee / halving | 区块奖励 / 交易费 / 减半 |
| difficulty adjustment (retargeting) | 难度调整(重定目标) |
| validator / stake / slot / epoch | 验证者 / 权益(质押) / 时隙 / 纪元 |
| leader election (lottery) / seed / grinding | 领导者选举(抽签) / 随机种子 / 研磨攻击 |
| verifiable random function (VRF) | 可验证随机函数 |
| nothing at stake / slashing | 无利害关系问题 / 罚没 |
| long-range attack / weak subjectivity | 长程攻击 / 弱主观性 |
| finality gadget / checkpoint | 最终性组件 / 检查点 |
| accountable safety | 可追责安全性 |
| centralization pressure | 中心化压力 |