Module 10 · Cryptography for Finance

Consensus — agreeing without a boss

The blockchain gave us a tamper-evident, ordered ledger — but left the hardest question unanswered: in a network with no leader, who adds the next block, and how do thousands of mutually distrustful strangers agree on a single history? This is the problem that had never been solved before 2008, and Bitcoin's answer is genuinely ingenious. This module builds it from intuition. You will run a real miner in your browser — grinding through nonces to find a hash with enough leading zeros, watching the work multiply with every added zero — and see how that "proof of work" makes adding a block costly, adding a fraudulent chain hopeless, and honest behavior the most profitable strategy. Then the alternative, proof-of-stake, the energy debate, and what a 51% attack truly threatens.

34 minute read
8 sections
Live miner
The Bitcoin stack · 3 of 4
6-question quiz
Section 01

Who adds the next block?

Module 09 built a beautiful data structure — a tamper-evident, ordered, replicated ledger — but it cannot grow by itself. Someone has to gather pending transactions, form them into the next block, and append it. In a bank, the answer is obvious: the bank does it. In Bitcoin there is no bank, no server, no authority of any kind. So the question is stark: in a leaderless network of strangers, who gets to add the next block, and how does everyone agree on it?

This is far harder than it sounds, because the network is full of parties who do not trust each other and some of whom are actively hostile. Three problems tangle together. First, if anyone can add blocks freely, an attacker can simply create millions of fake identities and flood the network with their own blocks — the so-called Sybil attack, where cheap fake identities overwhelm a vote. Second, when two honest participants form different next blocks at the same instant, the network needs a way to converge on one of them, or it splinters into conflicting histories. Third, all of this must work with no leader to break ties and no way to know who is honest. Agreeing on a single truth among mutually distrustful strangers, some malicious, with no central authority, is a classic problem in computer science — and for digital money it had never been solved.

The reason it is so hard is that voting does not work when identities are free. "One vote per person" is meaningless when anyone can mint a million personas for nothing. You need to tie influence over the ledger to something that cannot be faked or cheaply multiplied — some scarce, real-world resource that a participant must genuinely expend to have a say. Bitcoin's breakthrough was to make that resource computational work: to add a block, you must prove you burned real computing effort, effort that cannot be faked and that no amount of sock-puppet identities can conjure for free. This is proof-of-work, and it is the idea the rest of the module builds.

The leaderless agreement problem

With no central authority, the network must decide who adds each block and converge on one shared history — among distrustful, possibly hostile strangers. Voting fails because fake identities are free (the Sybil attack). The solution is to tie influence to a scarce resource that cannot be faked: real computational work. Proof-of-work makes adding a block cost genuine effort, so no one can cheaply overwhelm the network.

Section 02

Proof-of-work: making blocks costly

Proof-of-work turns the right to add a block into a contest of computational effort, using nothing but the hash function you already know. Here is the mechanism. To add a block, you must find a special number — called a nonce — that, when included in the block and hashed, produces a block hash meeting a difficulty target: specifically, a hash that starts with a certain number of zeros.

Why is that hard? Because of everything you learned about hashing in Module 02. A hash is unpredictable — the avalanche effect means you cannot reason your way to an input that produces a hash starting with many zeros; you can only guess and check. Try a nonce, hash the block, look at the result; if it does not have enough leading zeros, increment the nonce and try again. There is no shortcut, no clever formula — just relentless trial and error, billions of times over. Finding a valid nonce is genuinely hard work, requiring enormous numbers of hash computations. This grinding is what we call mining.

But here is the asymmetry that makes it useful, and it is the same easy-to-verify, hard-to-produce property behind signatures and certificates: while finding a valid nonce takes astronomical effort, checking one is instant. Anyone can take the block, hash it once, and immediately see whether the result has the required leading zeros. So a valid block is proof that its creator did the work — expended real computational effort — and that proof can be verified by everyone in a single hash. Costly to produce, trivial to check. That asymmetry is the entire foundation of how a leaderless network agrees, as the next sections show. First, feel the work for yourself.

Hard to find, easy to verify

To add a block you must find a nonce that makes the block's hash start with a required number of zeros — findable only by guess-and-check, because hashing is unpredictable. This grinding (mining) takes enormous effort, but anyone can verify a valid nonce with a single hash. A valid block is unforgeable proof that real computational work was spent — costly to produce, trivial to check.

Section 03

Mine a block — yourself

This is real mining, running in your browser with genuine SHA-256. Pick a difficulty — the number of leading zeros the block hash must have — and press Mine. The miner will grind through nonces (0, 1, 2, …), hashing the block each time, until it finds one whose hash starts with that many zeros. Watch the attempt counter climb. Then raise the difficulty by one and notice the work roughly multiplies by sixteen each time, because each additional leading zero (in hexadecimal) is sixteen times rarer.

Live demo · proof-of-work miner

Find a nonce whose hash starts with N zeros

Real SHA-256. The block data is fixed; only the nonce changes. Higher difficulty = exponentially more guessing. Each added zero ≈ 16× the work.

difficulty (leading zeros):
hash will appear here…
nonce: attempts: 0 hashes/sec: target: 00…

Feeling it makes the idea concrete in a way no description can. At difficulty 2 the miner finds a nonce almost instantly; at 4 or 5 you watch it churn through tens or hundreds of thousands of guesses, and the attempt counter tells the story — there was no clever path, only brute search. Now scale that up in your imagination: the real Bitcoin network targets a difficulty so high that the entire planet's mining hardware, hashing in unison, takes about ten minutes to find one valid block — that is trillions upon trillions of guesses. The work is staggering and real, and it is precisely that staggering, real cost that makes the next idea — how the network agrees — actually secure.

Section 04

How work becomes agreement

Now the payoff: how grinding nonces produces consensus among strangers. Miners across the world compete to find the next valid block; whoever finds one first broadcasts it, and everyone else, after verifying it in a single hash, accepts it and starts mining the next block on top. The winning miner is rewarded with new coins (the "block reward") plus transaction fees — the incentive that makes anyone bother spending the electricity. Roughly every ten minutes, a new block is found and the chain grows by one link.

But what if two miners find valid blocks at nearly the same moment, and the network temporarily splits, some building on one, some on the other? This is a fork, and the rule that resolves it is beautifully simple: the longest chain wins — more precisely, the chain with the most cumulative proof-of-work. Miners always extend the chain with the most work behind it. So as soon as one branch gets the next block, it becomes longer, everyone switches to it, and the other branch is abandoned. The network reconverges on a single history within a block or two. No vote, no authority — just the simple rule "build on the chain with the most work," and the math does the rest.

A B C C' D E C' abandoned longest chain wins ✓ Miners always build on the chain with the most work → the network reconverges on one history

This quietly answers the double-spending tie left open in Module 09. If someone broadcasts two conflicting transactions, each may land in a competing branch — but only one branch survives as the longest chain, so only one transaction becomes part of the permanent history; the other simply vanishes when its branch is abandoned. The deeper a transaction is buried (the more blocks built on top of it), the more work would be needed to reverse it, which is why merchants wait for a few "confirmations" before treating a payment as final. Consensus is not a single instant but a hardening over time: each new block makes the past exponentially more expensive to rewrite.

The longest chain wins

Miners compete to find the next block; the winner is rewarded, and everyone builds on the chain with the most cumulative work. When two blocks appear at once (a fork), whichever branch gets extended first becomes longest, and the network abandons the other — reconverging on one history with no vote or authority. Each added block makes reversing the past exponentially costlier, which is why deeper transactions are more final.

Section 05

The 51% attack — and why honesty pays

We can now state precisely what would break Bitcoin's consensus, and why it usually does not happen. Since the rule is "the chain with the most work wins," an attacker who controlled a majority of the network's total mining power could, in principle, out-mine everyone else — building an alternative chain faster than the honest network builds the real one, eventually overtaking it and making their version the longest. This is the famous 51% attack, and understanding exactly what it can and cannot do is essential to an honest picture.

What a 51% attacker could do: reverse their own recent transactions (spend coins, get the goods, then publish a longer chain where the spend never happened — a double-spend), and prevent specific transactions from being confirmed (censorship). What they emphatically could not do, even with all that power: steal coins from other people's addresses (that still requires private keys, which mining power cannot produce), create coins out of thin air beyond the rules, or change the protocol's rules — because every other node validates blocks against the rules and rejects invalid ones, no matter how much work backs them. And crucially, rewriting deep history is effectively hopeless: to reverse a transaction buried under many blocks, the attacker must redo all that work and then out-run the entire honest network going forward, which grows more impossible with every confirmation. A 51% attack threatens recent, shallow transactions, not the whole ledger.

But the deepest defense is economic, not technical, and it is elegant. Amassing a majority of the network's mining power would cost an enormous fortune in hardware and electricity. And here is the key: anyone who has that much mining power earns far more by using it honestly — collecting block rewards and fees, transaction after transaction, indefinitely — than by attacking the very system whose coins they would be stealing, an attack that would likely crash the coin's value (destroying their own holdings and hardware investment) the moment it was detected. Proof-of-work aligns incentives so that the rational move for anyone powerful enough to attack is to play by the rules and profit. Security comes not just from the difficulty of the attack but from the fact that honesty is more profitable. The system is held together less by making cheating impossible than by making it pointless.

⚠️ What 51% can and cannot do
A majority of mining power could reverse the attacker's own recent transactions (double-spend) and censor transactions — a real threat to shallow, unconfirmed payments. It could not steal others' coins (that needs private keys), mint coins against the rules, or change the protocol (nodes reject invalid blocks regardless of work), and rewriting deep history is effectively impossible. The strongest defense is economic: anyone powerful enough to attack earns more mining honestly than by an attack that would crash the coin they hold. Cheating is made not impossible but unprofitable.
Section 06

The energy debate, honestly

There is no avoiding the most common criticism of proof-of-work, and the course's commitment to evenhandedness means meeting it squarely: Bitcoin mining consumes an enormous amount of electricity — comparable, by some estimates, to that of a mid-sized country. This is not an accident or an inefficiency to be optimized away; it is intrinsic to the design. The security comes precisely from the fact that real, expensive work must be burned to add blocks. The energy expenditure is the cost that makes attacking the chain prohibitively expensive. You cannot have proof-of-work security without proof-of-work cost.

The two sides of the debate both have real points, and an honest account gives each its due. Critics argue that consuming a country's worth of electricity to run a payment network is environmentally indefensible, especially amid climate concerns, and that the energy delivers no benefit beyond securing the ledger — pure expenditure for its own sake. Defenders respond that the energy buys something real and unprecedented — a globally secure, decentralized monetary system owned by no one — and that the comparison should be against the (also enormous) energy and resource footprint of the traditional financial system it partly competes with; they add that mining increasingly uses stranded, surplus, or renewable energy that would otherwise be wasted, and can even fund renewable build-out by monetizing power in remote locations. Both positions contain truth: the energy use is genuinely large and genuinely intentional, and reasonable people weigh its worth differently depending on how much they value what it secures.

The honest summary is that proof-of-work makes a real and deliberate trade: it spends energy to buy a particular kind of security and decentralization that, so far, nothing else has achieved at the same scale and robustness. Whether that trade is worth it is partly a technical question and partly a values question, and it is precisely the discomfort with the energy cost that drove the development of an entirely different approach to consensus — one that tries to achieve agreement without burning energy at all. That alternative is proof-of-stake.

The energy is the security, by design

Proof-of-work's large energy use is intrinsic: the expensive, real work burned to add blocks is exactly what makes attacking the chain prohibitively costly. Critics call running a country's worth of electricity for a payment network indefensible; defenders argue it buys an unprecedented decentralized monetary system and increasingly uses surplus or renewable power. Both have real points — it is a deliberate trade of energy for security, weighed differently depending on what one values.

Section 07

Proof-of-stake: agreement without the burn

If the problem is tying influence to a scarce resource so identities cannot be faked, computational work is one answer — but not the only one. Proof-of-stake ties influence to a different scarce resource: the cryptocurrency itself. Instead of miners burning electricity to compete for the right to add a block, validators lock up (stake) a quantity of the coin as collateral, and the protocol selects who proposes the next block in proportion to how much they have staked. The scarce resource being expended is not energy but capital put at risk.

The security logic is different but rhymes with proof-of-work. A validator who tries to cheat — approving fraudulent blocks or attacking the chain — can have their staked coins destroyed by the protocol, a penalty called slashing. So misbehavior costs you real money directly, just as a failed proof-of-work attack costs you electricity and hardware. The incentive structure is again arranged so that honest participation is profitable (you earn rewards on your stake) and attacking is self-destructive (you lose your stake). The largest example is Ethereum, the second-biggest cryptocurrency, which famously switched from proof-of-work to proof-of-stake in 2022, cutting its energy consumption by over 99% essentially overnight.

In the evenhanded spirit, proof-of-stake is not a free lunch — it trades one set of properties for another, and the debate is genuine. Its great advantage is obvious: it achieves consensus with a tiny fraction of the energy, removing the environmental objection. Its critics raise different concerns: that staking may concentrate power in the hands of those who already hold the most coins ("the rich get richer," and influence pools among large holders), that its security model is newer and less battle-tested than proof-of-work's decade-plus track record, and that it can be subtly more complex and have different, less-understood failure modes. Defenders counter that it is more accessible (no expensive specialized hardware), more environmentally responsible, and that slashing provides strong, direct disincentives. There is no consensus on which is ultimately better — the two represent different bets on how to buy decentralized agreement, energy versus capital, and the ecosystem now runs both.

Stake capital instead of burning energy

Proof-of-stake ties block-creation influence to staked coins rather than computational work; validators who cheat are "slashed," losing their stake. It achieves consensus with a tiny fraction of the energy (Ethereum cut ~99%+ by switching in 2022). The trade-offs are debated: lower energy and no specialized hardware, versus concerns about wealth concentration and a less battle-tested security model. Energy or capital — two different bets on buying decentralized agreement.

Section 08

A complete system — and what comes next

Step back and see what has been assembled. Keys give ownership (Module 08); the blockchain gives a tamper-evident, ordered, replicated ledger (Module 09); and consensus — proof-of-work or proof-of-stake — lets a leaderless network of strangers agree on how that ledger grows, securely, with no one in charge (this module). Together they are a complete system for digital money without a central authority: you can own, receive, and spend value, and the whole network agrees on the state of the ledger, all without a bank, a government, or any trusted institution. The thing that seemed impossible for decades — digital cash that no one controls — actually works, built entirely from the primitives in the first half of this track plus the consensus idea in this one.

This is the achievement the banking innovation track pointed to when it spoke of money as "a claim on no one." You now understand, technically, how that claim is enforced: by cryptographic keys you alone control, recorded on a ledger no one can quietly rewrite, maintained by a network that agrees through costly, unfakeable work rather than through trust in any institution. The mechanics that the Bitcoin module deferred are now fully in your hands.

But the story does not end with simple payments. Once you have a decentralized network that can agree on the state of a ledger, a tantalizing question arises: what if the ledger could hold not just balances, but programs — code that runs on the blockchain and moves money automatically according to rules no one can alter or stop? What if value itself could be made programmable? That is the idea of smart contracts, and it extends everything you have learned from a system that records who owns what into a system that can enforce arbitrary financial agreements without intermediaries. The next module takes it up: what smart contracts are, what they make possible, how they fail, and why "code is law" is both their great promise and their great danger.

Next module

Module 11 · Smart Contracts and Programmable Value

From a ledger of balances to a ledger that runs code. What a smart contract is, how a decentralized network executes programs that move money automatically with no intermediary, what this makes possible (and what "decentralized finance" really means), and how it breaks — the immutability double-edge, famous exploits, and why "code is law" is both the promise and the peril. With live demos, as always.

Self-examination

Test your understanding

Six questions on consensus — the leaderless agreement problem, proof-of-work and mining, the longest-chain rule, the 51% attack, the energy debate, and proof-of-stake. The questions test the concepts you just saw in action.

Module 10 · Self-examination