A Blockchain Primer › Module 5 › Lesson 5.2
Lesson 5.2: Attack-and-Defense Lab — Try Tampering, Double-Spending, and Attacks Yourself — Why They Rarely Succeed
- #1. The Core Question
- #2. An Everyday Analogy
- #3. Core Concepts Explained
- #4. Diagrams
- #5. Key Takeaways
- #6. Quiz
We've learned that tampering gets caught, double-spending runs into a time lag, signatures resist forgery, and rewriting the chain is expensive. This lesson turns all of that into five hands-on "experiments." You play the attacker, follow each attack path, and see which wall you hit at every step.
1. The Core Question
"Blockchain is tamper-resistant" isn't a slogan. It's the result of mechanisms stacked one on top of another. Really understanding it means you can follow an attack path yourself and explain where it fails and what it would cost.
This lesson answers one question: Which defenses do tampering, double-spending, signature forgery, rewriting the whole chain, and a 51% attack each run into?
The short version: Nobody "forbids" attackers from cheating. Layer after layer of mechanisms just push them to the point where cheating isn't worth it.
2. An Everyday Analogy
About the Five Little Experiments
You don't need any code for the experiments below. All you need is a sheet of paper, a pen, and a little patience. Each experiment starts with the attacker's idea, has you check the result by hand, and then explains where the defense is.
3. Core Concepts Explained
3.1 Experiment One: Alter an Old Transaction
The attacker's idea: The chain has 100 blocks. I find a transaction in block 50, change the recipient address to mine, and quietly put it back.
Verify by hand:
- Write down the original transaction's hash value, H0.
- Change the address, recompute the hash, and you get H1.
- Notice that H1 ≠ H0. The reference pointing to this transaction doesn't match anymore.
- Recompute block 50's transaction root hash. It has changed too.
- That means block 50's header hash changes as well, and the parent reference stored in block 51 doesn't match anymore.
Conclusion: Change one spot, and every reference after it breaks like a row of dominoes, all the way to the head. To avoid getting caught, you'd have to recompute everything from block 50 through block 100.
3.2 Experiment Two: Attempt Double-Spending
The attacker's idea: I have 10 coins. I pay them to A and B at the same time. As long as two nodes haven't compared notes yet, both sides will accept.
Verify by hand:
- Send the first transaction to node P.
- Before P forwards the message to Q, send the second transaction to Q.
- Q's own ledger still shows a balance of 10, so it accepts the second one.
Observation: For a short while, P and Q may really see different histories. But of the two branches, only one will keep getting extended with new blocks.
Conclusion: Double-spending can cause "temporary confusion," but in the end nodes only accept the chain with the most accumulated work. The transactions on the other branch end up in orphan blocks, and the second spend is treated as if it never happened. The attacker's effort goes to waste.
3.3 Experiment Three: Forge Someone Else's Signature
The attacker's idea: I intercept A's transaction to B, change the recipient address to C, and broadcast the transaction.
Verify by hand:
- The transaction carries A's signature.
- The signature was created with A's private key over "the original transaction hash."
- Once the address changes to C, the transaction hash changes.
- Checking the signature with A's public key gives a hash that doesn't match the altered transaction's hash.
Conclusion: The signature is tied to the transaction's contents. Without A's private key, nobody can re-sign the altered transaction. The forgery fails.
3.4 Experiment Four: Rewrite the Entire Chain
The attacker's idea: Fine, I'll just rewrite the whole chain. Nobody's stopping me.
Verify by hand:
- Every altered block header means solving its hash puzzle all over again.
- Say each puzzle takes 10 minutes on average (an assumption just for illustration). Changing the block 21 levels below the head means solving 21 puzzles again.
- That's about 210 minutes, while honest nodes only have to solve one new block in the same stretch of time.
Conclusion: The earlier the block you rewrite, the more blocks you have to recompute. The honest majority keeps extending the chain, and your old chain falls further and further behind. Rewriting the whole chain doesn't pay off economically.
3.5 Experiment Five: The 51% Attack
The attacker's idea: If I have more than half the network's computing power, can I reverse transactions and decide history over again?
Verify by hand (compare two scenarios):
- Small chain: the whole network is just 10 ordinary computers. You buy 11, grab most of the computing power, and the attack works.
- Large chain: the network has hundreds of thousands of devices. Grabbing most of the computing power takes huge amounts of capital and electricity, and you have to keep pouring money in.
Conclusion: The 51% attack exists in theory, but the bigger the system, the higher the cost. Blockchain's security doesn't mean attacks are "absolutely impossible." It means "when honest nodes hold most of the computing power, attacking doesn't pay."
3.6 What the Five Experiments Show Together
| Attack | Defense it hits | Result |
|---|---|---|
| Altering an old transaction | Chained hash references | The change propagates along the chain; recomputation must reach the head |
| Double-spending | Longest chain / heaviest chain selection | The second spend ends up in an orphan block |
| Signature forgery | Private-key signing + public-key verification | Verification fails |
| Rewriting the entire chain | Each block's hash puzzle | Cost accumulates with depth |
| 51% attack | Honest majority and critical mass | Small chains are fragile; large chains are expensive |
These defenses don't work in isolation. They stack in layers: first they make changes visible, then they make rewriting expensive, and finally they let the network settle on one chain the majority accepts.
4. Diagrams
Figure 5-2-1: Five Attack Paths and Their Defenses
5. Key Takeaways
- Altering an old transaction breaks the references along the hash chain all the way to the head.
- Double-spending only causes temporary confusion. In the end nodes pick the longest/heaviest chain, and the second spend ends up in an orphan block.
- Signatures are tied to the transaction's contents. Without the private key, nobody can re-sign an altered transaction.
- Rewriting the whole chain means solving every block's hash puzzle again, and the cost piles up with depth.
- The 51% attack exists in theory, but it takes most of the computing power, which is extremely expensive on a large chain.
- Blockchain's security means "making attacks unprofitable," not "impossible to attack."
6. Quiz
Part 1: Single Choice (1–4)
Question 1
After a transaction in block 50 is altered, what's the first change to show up?
A. The transaction hash changes, and the reference pointing to it becomes invalid
B. The whole chain disappears automatically
C. All private keys update automatically
D. The transaction amount doubles automatically
Show answer
Answer: A
Explanation: Changing a transaction's contents changes its hash. The direct reference breaks first, and then the damage spreads along the chain.
Question 2
After a double-spending attack causes confusion, what do nodes do in the end?
A. Keep both versions forever
B. Accept the chain with the most accumulated work, and the other branch becomes orphan blocks
C. Merge the two transactions automatically
D. Shut down the network
Show answer
Answer: B
Explanation: In the end nodes pick the chain with the most accumulated work, and the transactions on the other branch end up in orphan blocks.
Question 3
What's the root reason signature forgery fails?
A. The signature is tied to the transaction's contents, and only the private key holder can create it
B. The signature is too long
C. The public key sounds an alarm automatically
D. Nodes confirm by phone
Show answer
Answer: A
Explanation: The signature is based on the transaction hash and is only valid for the original contents. Without the private key, there's no way to re-sign.
Question 4
Where does most of the cost of rewriting the whole chain come from?
A. Every altered block's hash puzzle has to be solved again
B. You have to buy a new keyboard
C. You have to re-register domain names
D. You have to write letters to every user
Show answer
Answer: A
Explanation: Every altered block header's hash puzzle has to be solved again, and the cost piles up with depth.
Part 2: Multiple Choice (5–7)
Question 5
Which defenses make tampering unprofitable?
A. Chained hash references
B. Longest chain / heaviest chain selection
C. Private-key signatures
D. Each block's hash puzzle
Show answer
Answer: A, B, C, D
Explanation: Chained references, chain-selection rules, signatures, and hash puzzles work together as the defenses.
Question 6
Which statements about the 51% attack are correct?
A. It takes control of most of the computing power
B. Small chains are easier to attack
C. Attacking a large chain is extremely expensive
D. It's absolutely impossible
Show answer
Answer: A, B, C
Explanation: A 51% attack takes most of the computing power. Small chains are fragile, and large chains are expensive. D is wrong to call it "absolutely impossible."
Question 7
What do the five experiments show together?
A. Blockchain security comes from mechanisms stacked in layers
B. Attackers aren't forbidden, they're pushed to the point where it isn't worth it
C. Each defense deals with a specific kind of attack
D. Any attack succeeds as long as you're online
Show answer
Answer: A, B, C
Explanation: Security rests on layers of stacked mechanisms that push attacks to the point where they don't pay. D goes against the facts.
Part 3: True or False (8–9)
Question 8
True or false: as long as the double-spending transactions go to two nodes at the same time, both transactions will end up accepted.
Show answer
Answer: False
Explanation: In the end nodes only accept one chain, and the second spend ends up in an orphan block.
Question 9
True or false: blockchain's tamper resistance means "too expensive to be worth it," not that changes are mathematically impossible.
Show answer
Answer: True
Explanation: Blockchain makes tampering so expensive that it's usually not worth it, but changing the data isn't mathematically impossible.
Part 4: Scenario Analysis (10)
Question 10
An attacker finds a chain of 500 blocks and wants to change a transaction in block 10. Each block's hash puzzle takes 5 minutes on average (an assumption just for illustration).
Answer the following:
- How many block headers have to be rewritten?
- About how much time would it take?
- What are honest nodes doing during that time? How does that make the attack harder to pull off?
Show answer
Answer:
- From block 10 through block 500, that's 500 - 10 + 1 = 491 block headers.
- 491 × 5 = 2455 minutes, or about 40 hours and 55 minutes (an estimate just for illustration).
- Honest nodes keep solving puzzles for "new blocks," each taking just 5 minutes, so their chain keeps growing. The attacker can't keep up with how fast the honest chain grows. The old chain falls further behind, and most nodes end up abandoning it.