Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part III · The house: building a chain This chapter contains no cryptography from beginning to end. It is the heart of the book, and it is Satoshi’s actual invention.

Last chapter left a hole: the ledger lives on one machine. Alice goes to another machine, spends the same coin against another ledger, and both ledgers insist they are correct.

Which do you believe?


7.0 First, dismantle a common belief

Before the answer, one misconception has to go — nearly everybody has it:

WRONG. “Bitcoin makes every computer in the world see the same ledger, always.”

It does not. Networks have latency. Right now, two nodes on opposite sides of the planet very likely see different transactions, different blocks, different local ledgers. That is normal, not a malfunction.

The accurate statement is:

RIGHT. Everyone runs the same rules, starts from possibly different local views, and eventually converges on one history.

This is not pedantry. It determines how you understand everything downstream — why forks happen, why you wait for confirmations, why a chain reorganization is part of the design rather than an accident.

A shared ledger is not the starting point. It is the result of convergence.


7.1 A block you can mine

Fuse chapter 4 and chapter 5:

A block = a batch of transactions + the previous block’s hash (chapter 4’s chain)

  • a mined nonce (chapter 5’s work)

genesis mined. nonce = 3661  hash = 0008f013f7ef ...
genesis fields: {'txs': ['genesis'], 'prev_hash': '0000000000000000000000000000000000000000000000000000000000000000', 'difficulty': 3, 'nonce': 3661}
genesis content: ['genesis']|0000000000000000000000000000000000000000000000000000000000000000|3661

Again, do not let chain become an abstract noun. It is a Python list:

[block0, block1, block2]

Every block carries a prev_hash pointing at the one before it, which is what strings the objects together.

Those last two print lines are worth reading when it runs: genesis.__dict__ shows the block is four fields, and genesis.content() shows you exactly which string is hashed.

Nothing here is new — chapter 4’s chain plus chapter 5’s mining, and not one novel concept.


7.2 A chain, and its “work”

honest chain: length 3  work 9  valid? True
block0: txs=['genesis'], prev=0000000000..., nonce=3661, hash=0008f013f7...
block1: txs=['Alice pays Bob 10'], prev=0008f013f7..., nonce=6795, hash=0007c2b94c...
block2: txs=['Bob pays Carol 10'], prev=0007c2b94c..., nonce=6430, hash=000650c2ef...

Two things to look for in that output:

  • honest is a list holding three Block objects in order

  • block 1’s prev_hash equals block 0’s hash; block 2’s prev_hash equals block 1’s hash

So “chain” is not a magic word. It means: each block writes the previous block’s hash into its own body.

Of the three functions, work is the new one, and it is suspiciously simple — it adds up the difficulties.

The question it answers is: “how much electricity did building this chain consume?”

(Real Bitcoin computes accumulated work more precisely, but it means exactly this: a chain’s weight is the total hashpower required to produce it.)


7.3 Alice double-spends, this time across machines

Now open up last chapter’s hole.

On another machine, Alice forks from the same genesis block and spends the coin — already given to Bob — again, to Dave.

honest  : length 3  work 9  valid? True
attacker: length 2  work 6  valid? True

Both chains are valid, and they disagree about who got the coin.

Both chains pass valid.

Signatures fine, proof-of-work fine, links fine. You cannot write a checking function that rules either one out — because neither one is invalid.

Cryptography is no help at all here. It can prove Alice signed both transactions. It cannot say which chain is the real history.

Seeing something first locally does not mean it happened first. Final order is decided by whichever chain wins.


7.4 The rule

Satoshi’s rule is this:

Among all valid chains, take the one with the most accumulated work.

No voting, no identities, no adjudication of who is right — only who spent more effort.

honest work: 9   attacker work: 6
winner: honest

Alice->Bob stands. Alice->Dave (the double-spend) is discarded.

That is the whole thing.

max((c for c in chains if valid(c)), key=work)

This is Bitcoin’s heart. Thirty years of an unsolved problem, and the answer is a max.

Notice carefully what it does not do:

  • It does not ask who the good guy is

  • It does not ask which transaction happened first (it has no way to know)

  • It has no authority, no roster, no weighted votes

  • It does not even care which chain is “correct”

It does one thing: among valid chains, pick the one that burned the most electricity.

And that is sufficient. Because everyone runs the same max, everyone picks the same chain. Disagreement does not need to be prevented; the same rule dissolves it automatically.

The mempool is “I heard about this.” The blockchain is “the network finally accepted this.”


7.5 So can Alice still win?

Yes. If her hashpower exceeds every honest miner combined.

honest work: 9   attacker after catching up: 12
who wins now?: attacker -- 51% attack succeeded!

The attacker wins.

That is the 51% attack, and you just performed one successfully. It genuinely works.

Which exposes the truth about Bitcoin’s security, and it deserves saying bluntly:

Bitcoin is not “impossible to attack.” It is “not worth attacking.”

You would need more than half the hashpower on Earth. The hardware and electricity cost more than you could steal.

Bitcoin’s security is not absolute. It is computational and economic.

That should make you slightly uncomfortable. Chapter 1’s hash and chapter 3’s signature gave you the feeling of a mathematical guarantee. This gives you we ran the numbers and it doesn’t pay.

But that discomfort is exactly what this book wants you to see. Mathematics can guarantee that a signature cannot be forged without the key. Mathematics can never guarantee that a crowd of strangers will agree on an ordering — that is a social problem, a game-theoretic problem. Satoshi’s contribution was converting that social problem into a cost problem.

One more thing works in the honest chain’s favour: honest miners do not stop and wait. They keep extending, and the gap the attacker must close keeps widening. Time is on the honest chain’s side.

YOUR TURN

confirmations for Alice pays Bob: 1

Question 2 exposes the most misleading thing in this chapter. “Longest chain” is a bad name.

If block count were the measure, an attacker could set difficulty to 1 and stack a hundred blocks in seconds. What actually gets compared is work — accumulated work. The honest name would be “heaviest chain.”

(In Bitcoin the rule is formally most-cumulative-work. “Longest chain” is a historical nickname, because when difficulty is equal, longest and heaviest coincide.)


7.6 The ledger

This chapter’s ledger is the most important table in the book:

What you wroteField
class Block — transactions + previous hash + nonceSystems design
work(chain) — accumulated workSystems design
valid(chain) — does it link, was it minedSystems design
choose(*chains) — the longest-chain ruleA game rule
The 51% attackEconomics
confirmations()Probability

Now count: how many lines of cryptography are in this chapter?

Zero.

H() appears, but its jobs are “did this meet the mining target” and “does this block link to that one” — those are integrity checks, not cryptography in the sense of secrecy or authentication. There is not one private key, not one signature, not one verification in the entire chapter.

And what this chapter solved is precisely the thing thirty years of cryptographers could not.

This is the prologue’s claim, fully cashed:

Signatures and hashes are bricks, and they were somebody else’s (chapters 1–5). “Use accumulated work to make mutually distrustful strangers converge on one history” — that house is Satoshi’s, and it lies entirely outside cryptography.

Chapter 1 promised you: “by chapter 7 you will write an entire chapter of code and find not one line of cryptography in it.”

Delivered.


Next

Incentives and issuance.

You have a machine that resists forgery, resists double-spending, and reaches consensus. One question remains, and it is fatal:

Why would any miner burn electricity?

If nobody mines, this entire chapter is waste paper — with no work, choose has nothing to compare.

The next chapter is the whitepaper’s cleverest move, and the first time in this book that economics takes the lead role.