Crypto From First Principles · Lesson 48 · 11 min read

How a Blockchain Works

Security Made of Cost, Not Cleverness
Kanin D. Alldredge
Legal & Quantitative Analyst / Author / Educator, The Currency Classroom
Free

1What a Block Contains

Start with the smallest unit.

A block is a package of data. Three things go inside it.

Inside a BlockWhat It Is
TransactionsA batch of transfers, confirmed together
A timestampWhen the block was assembled
A fingerprint of the previous blockThe link that makes it a chain

A hash is a fingerprint of data. Feed any amount of information into a hash function and it produces a fixed-length string of characters. The same input always gives the same output, and any change to the input, however small, gives a completely different one.

Figure 48.1: Change one letter and the hash shares nothing with the original.
Figure 48.1Change one letter and the hash shares nothing with the original.

Each block carries the hash of the block before it. That is the chain.

Figure 48.2: Each block carries the fingerprint of the one before it, which makes the chain.
Figure 48.2Each block carries the fingerprint of the one before it, which makes the chain.

2Why the Past Cannot Be Edited

Now follow what happens if someone tries to change an old transaction.

StepWhat Happens
1They alter data in a block from last year
2That block's hash changes, because the input changed
3The next block contains the old hash, which no longer matches
4The chain is broken at that point, visibly, for everyone

Altering the past is not hard to do. It is impossible to hide.

Figure 48.3: Altering a past block breaks the chain at that point, for everyone to see.
Figure 48.3Altering a past block breaks the chain at that point, for everyone to see.

Which is a different kind of protection from the usual one. Nothing prevents the edit. The structure makes the edit obvious, permanently, to every participant holding a copy.

3Thousands of Copies

A node is any computer holding a full copy of the ledger and independently checking transactions against the rules.

There are tens of thousands, spread across dozens of countries. No central server exists, and no master copy exists either. Each node holds the whole thing.

Which produces the practical consequence Lesson 47 gestured at. Shutting the network down would require disabling most of those nodes simultaneously, in every country at once. No single government or institution can do that.

It also means every node is checking every other node's work, continuously, by applying identical rules to identical data.

Figure 48.4: Every node holds the whole chain, and there is no master copy.
Figure 48.4Every node holds the whole chain, and there is no master copy.

4The Puzzle

Transactions are broadcast and nodes verify them. Somebody still has to assemble them into a block and add it to the chain.

That is mining, and it is deliberately expensive.

Each candidate block contains the transactions, the previous block's hash, a timestamp, and one more piece of data the miner chooses freely. That last piece is called the nonce.

The task is to find a nonce that makes the whole block's hash begin with a certain number of zeros.

Figure 48.5: Mining is trial and error: try a nonce, check the hash, repeat.
Figure 48.5Mining is trial and error: try a nonce, check the hash, repeat.

5The Asymmetry

Here is the elegant part, and it is the reason the system functions at all.

finding a valid nonce: billions of attempts
checking one: a single calculation

Finding the answer takes enormous work. Verifying somebody else's answer takes almost none.

So when a miner finds a valid nonce and broadcasts the block, every other node confirms it instantly and adds it to their copy. Thousands of independent participants agree in seconds, having spent nothing to check.

Expensive to produce, trivial to verify. That gap is the mechanism.

Figure 48.6: Finding the answer takes billions of attempts. Checking it takes one.
Figure 48.6Finding the answer takes billions of attempts. Checking it takes one.

The successful miner receives two things. Newly created Bitcoin, called the block reward, and the fees attached to the transactions in the block.

That reward is the only way new Bitcoin enters circulation. No central bank, no treasury. Miners solving puzzles, and coins appearing as payment.

Figure 48.7: The difficulty adjusts so that a block arrives about every ten minutes.
Figure 48.7The difficulty adjusts so that a block arrives about every ten minutes.
YearBlock Reward
200950 BTC
201225 BTC
201612.5 BTC
20206.25 BTC
20243.125 BTC
Figure 48.8: The block reward halves every 210,000 blocks.
Figure 48.8The block reward halves every 210,000 blocks.

The reward halves every 210,000 blocks. At roughly ten minutes a block, that works out to just under four years, which is where the four-year rhythm comes from. It is arithmetic written into the protocol at the start rather than a policy anyone reviews.

6Why Attacking It Fails

Suppose somebody wanted to rewrite history and reverse a past transaction.

Section 2 showed the chain would break at that point. To repair it they would need to redo the work for that block and every block after it. And they would have to do all of that faster than the honest network is adding new blocks, because the network keeps going while they work.

That requires controlling more than half the total computing power on the network. The hardware and energy cost is astronomical.

But cost is not the interesting part.

Figure 48.9: A rewrite falls behind the honest chain, and nodes reject it.
Figure 48.9A rewrite falls behind the honest chain, and nodes reject it.

7The Other Approach

Bitcoin is not the only blockchain and this is not the only way to reach agreement.

Proof of stake replaces computational work with money at risk. Instead of miners burning energy, validators lock up a quantity of the network's own currency as collateral. They are chosen to add blocks in proportion to how much they have locked up.

The enforcement is direct. A validator who tries to approve a fraudulent block has their collateral destroyed automatically. The deterrent is not wasted electricity but confiscated capital.

Proof of WorkProof of Stake
What is committedEnergy and hardwareCurrency locked as collateral
Who gets to add blocksWhoever solves the puzzle firstChosen in proportion to the amount staked
Penalty for cheatingWasted cost, rejected blockCollateral destroyed
Used byBitcoinEthereum, since September 2022
Figure 48.10: Proof of work and proof of stake compared.
Figure 48.10Proof of work and proof of stake compared.

Ethereum's switch, in September 2022, cut its energy consumption by an estimated ninety-nine percent. That changed how it is received by regulators and institutions in places where environmental considerations matter.

Figure 48.11: Ethereum's switch to proof of stake cut its energy use by an estimated 99 percent.
Figure 48.11Ethereum's switch to proof of stake cut its energy use by an estimated 99 percent.

8An Argument Still Running

It would be easy to present proof of stake as the obvious successor. That would misrepresent a serious disagreement.

The Case For Proof of WorkThe Case For Proof of Stake
A track record. Bitcoin has operated without a successful attack for over fifteen years.Efficiency. Removing the energy requirement makes the system far cheaper to run.
The cost is external and objective. It cannot be gamed by whoever already holds the most.Scalability. Less overhead makes the network easier to grow.
But critics argue it concentrates influence among the largest existing holders, and that objection has not been settled.

Both systems are running at enormous scale right now, and the evidence continues to accumulate. Anyone telling you the question is closed is telling you about themselves rather than about the technology.

Figure 48.12: The strongest case on each side, with the objection still unsettled.
Figure 48.12The strongest case on each side, with the objection still unsettled.

One further point belongs here because it is a fact rather than an opinion. Bitcoin mining consumes a great deal of electricity. That has real consequences for regulation and for institutional adoption. Some countries have restricted mining on energy grounds, others have attracted it with cheap renewable power, and both responses are part of the landscape this technology operates in.

Which completes the mechanics. Lesson 47 said Bitcoin moves trust from an institution into a mechanism, and you have now seen the mechanism.

The next lesson leaves Bitcoin behind. Ethereum took the same underlying idea and asked what else a distributed ledger could do besides move money.

Three Things to Remember

Try This

Fifteen minutes. One step uses a free tool and takes about ten seconds.

Words From This Lesson

TermWhat It Means
BlockA package of transactions, a timestamp, and the hash of the previous block.
HashA fingerprint of data. Any change to the input produces a completely different output.
NodeA computer holding a full copy of the ledger and independently verifying transactions.
MiningCompeting to find a nonce that produces a valid block hash, at real energy cost.
NonceThe freely chosen number a miner varies until the block's hash meets the requirement.
Block rewardNewly created currency paid to the successful miner. The only way new Bitcoin enters circulation.
HalvingThe scheduled reduction of the block reward every 210,000 blocks, roughly every four years.
Proof of stakeAgreement secured by locked collateral rather than energy. Dishonesty destroys the collateral.

Test Your Knowledge

Eight questions. Answer them all before checking the key on the following pages. If a question gives you trouble, the answer key tells you which section to revisit.

1. What links one block to the next?
  1. A. A sequential number
  2. B. A digital signature from a central authority
  3. C. A shared timestamp
  4. D. A hash of the previous block
2. What happens if someone alters data in an old block?
  1. A. Nothing, since old blocks are not rechecked
  2. B. Only the miner who created it would notice
  3. C. The network automatically restores it
  4. D. That block's hash changes and the chain visibly breaks
3. What is a node?
  1. A. A specialized mining machine
  2. B. A central server that coordinates the network
  3. C. A computer holding a full copy of the ledger and verifying transactions
  4. D. An account holding cryptocurrency
4. What are miners actually competing to do?
  1. A. Find a nonce that makes the block's hash meet a requirement
  2. B. Verify transactions faster than each other
  3. C. Purchase the right to add a block
  4. D. Vote on which transactions are valid
5. Why is there no shortcut to finding a valid nonce?
  1. A. The software prevents it
  2. B. A hash function cannot be run backwards from the desired output
  3. C. Miners are limited by regulation
  4. D. The nonce is chosen by the network
6. What makes verification so different from mining?
  1. A. Verification also takes billions of attempts
  2. B. Verification takes a single calculation, so nodes agree in seconds
  3. C. Only certain nodes may verify
  4. D. Verification happens once a day
7. Why is a majority attack described as self-defeating?
  1. A. The attacker would be prosecuted
  2. B. The network would shut down entirely
  3. C. The resulting ledger would be rejected, since the honest chain has more work behind it
  4. D. Mining hardware cannot be bought at that scale
8. What does proof of stake use in place of energy?
  1. A. Currency locked as collateral, destroyed if the validator cheats
  2. B. Faster computers
  3. C. A central authority
  4. D. Random selection with no stake required

Answer Key

Each answer explains why the correct choice is correct, why the others are not, and where to reread.

Question 1 · correct answer D

Every block contains a hash of the block before it. That link is what makes a series of blocks into a chain rather than a list.

A would provide ordering without any tamper detection. C records when a block was made but does not connect it to the previous one. B describes the central authority the design exists to remove.

Review: Section 1, What a Block Contains

Question 2 · correct answer D

Any change to the input produces a different hash, so the following block's stored reference no longer matches and the break is visible to everyone holding a copy.

A is wrong because nodes verify continuously. C describes an automatic repair that does not exist. B understates it, since every node can see the mismatch.

Review: Section 2, Why the Past Cannot Be Edited

Question 3 · correct answer C

Tens of thousands of computers each hold the whole ledger and independently check transactions against the rules. There is no master copy.

B describes the central server the design deliberately avoids. A describes mining hardware, which is a different role. D describes a wallet rather than a node.

Review: Section 3, Thousands of Copies

Question 4 · correct answer A

The nonce is the one piece of block data a miner chooses freely, and the competition is to find a value that makes the whole block's hash start with the required number of zeros.

B describes what nodes do, and verification is not competitive. C is wrong because the right cannot be bought. D describes a voting process that does not occur.

Review: Section 4, The Puzzle

Question 5 · correct answer B

You cannot start from the output you want and calculate which input produces it. The only method is trying values until one works by chance.

A attributes to software restriction what follows from the mathematics. C invents a regulatory limit. D is wrong because the miner chooses the nonce, not the network.

Review: Section 4, The Puzzle

Question 6 · correct answer B

Finding a valid nonce takes billions of attempts. Checking one takes a single calculation, which lets thousands of independent nodes confirm a block almost instantly.

A removes the asymmetry that makes the system function. C is wrong because any node can verify. D invents a schedule that does not exist.

Review: Section 5, The Asymmetry

Question 7 · correct answer C

Nodes follow the chain with the most work behind it. An attacker would spend an enormous sum to produce a version the network does not accept.

A describes a legal consequence rather than the structural one. B overstates it, since the honest network continues. D is wrong because the barrier is cost and futility rather than availability.

Review: Section 6, Why Attacking It Fails

Question 8 · correct answer A

Validators lock up currency as collateral and are chosen in proportion to the amount. Approving a fraudulent block destroys that collateral automatically.

B describes an advantage in proof of work rather than a different mechanism. C reintroduces the authority both designs avoid. D removes the economic commitment that provides the deterrent.

Review: Section 7, The Other Approach

Keep going

Crypto From First Principles is written by Kanin D. Alldredge for The Currency Classroom, and it is free to read. There is more free from CNS: start here.

Start free with CNS →

Or see CNS Pro →