Common Web3 Attacks and Exploits eBook
A Coursebook on Common Web3 Attacks and Exploits
A Coursebook on Common Web3 Attacks and Exploits
Formats
Free sample
Chapter 1: Trust’s Broken Promise...--The first thing you need to understand about Web3 security is that the slogan printed on a million laptops and tweeted by a billion crypto accounts is a lie. Not a malicious lie, but a comforting one. “Don’t trust, verify.” It sounds empowering. It sounds like the end of banks, the end of middlemen, the end of asking permission. But here is the uncomfortable truth that every exploited protocol, every drained wallet, and every rekt developer learns too late: you cannot verify everything.
And even when you do, the code you are verifying might be perfectly correct while still being catastrophically wrong.This chapter is not a technical tutorial. It is a reorientation. Before you write a single line of Solidity, before you fork mainnet, before you even open a terminal, you need to internalize a different worldview. Web3 failures are almost never about breaking cryptography. Nobody is out there factoring RSA keys or reversing SHA-256.
The attacks you will learn about in this book succeed because they exploit the gap between what a developer intended and what the code actually does. They exploit the gap between the state machine you think you are running and the state machine that exists in the EVM. And most importantly, they exploit the gap between “don’t trust” and the reality that every single Web3 application is built on a foundation of implicit, unstated, and often dangerous trust assumptions.Let us start with a thought experiment. Imagine you are building a lending protocol. You write a flawless smart contract.
It has no reentrancy bugs. It has no integer overflows. It passes every audit. You deploy it, and users deposit a hundred million dollars. Then, suddenly, your protocol is drained in a single transaction.
Did the attacker break your code? No. They manipulated the price feed your contract trusted. Your contract assumed the oracle was honest. That was a trust assumption you never even wrote down.
The code was perfect. The system failed.This is the central paradox of Web3 security. The more we celebrate “trustlessness,” the more we blind ourselves to the trust we still rely on. This chapter will tear down that blindfold. We will explore what trust actually means in a blockchain context, why “code is law” is a dangerous half-truth, and how the 2016 DAO hack—the original sin of smart contract security—was not a bug in the code but a failure of governance and implicit rules.
By the end, you will see the attack surface not as a single contract but as five distinct layers, each with its own trust assumptions and each waiting to be exploited.Trust Assumptions: The Invisible Attack Surface Every blockchain application is built on assumptions. Some are explicit: “This function can only be called by the owner.” Others are implicit: “The owner will not be malicious.” “The oracle price will be accurate within 1%.” “The blockchain will not reorg more than six blocks deep.” “The RPC node I am connected to is returning real data.” Attackers do not break code; they violate assumptions.Let us define a trust assumption formally. A trust assumption is any condition that must hold for the system to behave correctly but that is not enforced by the protocol’s cryptography or consensus rules. In other words, if you have to hope something is true, you are trusting it. And hope is not a security strategy.Here are some common trust assumptions that have led to millions of dollars in losses:First, the oracle assumption.
“The price returned by this Chainlink feed is the true market price.” Chainlink is robust, but it can stall during extreme volatility. In May 2022, the Luna-UST collapse saw oracle feeds lag by minutes. Protocols that trusted the stale price continued liquidating positions at incorrect values, compounding the crash.Second, the admin key assumption. “The multi-sig signers will not collude to steal funds.” This is not a technical guarantee; it is a social one. And social guarantees fail.
In 2022, the Harmony Horizon bridge was exploited not through a smart contract bug but through a compromised private key of a multi-sig signer. The code was fine. The trust assumption broke.Third, the mempool assumption. “My transaction will execute after I submit it.” In reality, miners and MEV bots reorder transactions at will. If your transaction reveals a profitable opportunity (like a large swap or a liquidation), someone else can copy it, pay higher gas, and land ahead of you.
Your assumption of fair ordering was never guaranteed.Trust minimization is the goal, not trust elimination. You cannot eliminate trust entirely—because you trust the laws of physics that keep the blockchain’s cryptographic primitives secure, and you trust that the developers of the Ethereum client did not accidentally introduce a consensus bug. What you can do is move trust. A bank moves trust from the teller to the software. A smart contract moves trust from the bank to the code and the oracle and the multi-sig.
But trust never disappears. It only changes address.The implication for attackers is profound. If you can find a trust assumption that is not enforced, you have found an exploit. You do not need to break ECDSA. You just need to find the moment when the system stops verifying and starts hoping.Why “Code is Law” Fails The phrase “code is law” is recited with religious fervor in crypto communities.
It means that the rules of a protocol are exactly what the code says, not what a judge or a contract or a community might interpret. On its face, this is liberating. No ambiguity. No human discretion. Just deterministic execution.But here is the problem: code is not law.
Code is a map, and the law is the territory. The map can be accurate in every line and still lead you off a cliff if the cartographer misunderstood the terrain.A smart contract does what it says, not what you meant. This distinction is everything. The DAO’s code in 2016 said that a withdrawal could call back into the DAO’s functions before the balance was updated. The code executed perfectly.
The developer intended that no single entity could drain the DAO. The code did not care about intentions. The attacker exploited the gap between the written code and the unwritten specification. The code was law. The law was wrong.This gap exists in every non-trivial smart contract.
Specifications are written in English (or whatever human language the developers speak). Implementations are written in Solidity. English is ambiguous. Solidity is precise. The translation from one to the other is where bugs are born.Consider a simple specification: “Users can withdraw only up to their balance.” In Solidity, you write:function withdraw(uint amount) external {require(balances[msg.sender] >= amount);(bool success,) = msg.sender.call{value: amount}("");balances[msg.sender] -= amount;}The code says: check balance, send ether, then update balance.
The specification says: user cannot withdraw more than balance. The code violates the specification if the external call re-enters withdraw before the balance is updated. The code is law—it executes exactly as written. But the law is wrong relative to the specification. That is the…
This is the end of the free sample. Get the eBook to keep going. Buy now
About this book
Details
- Author
- Cornelius Zana
- Publisher
- SamEnrico
- Language
- English
- Genre
- Non-Fiction, Informative, Educational
- Released
- 2026-05-04
- Pages (approx.)
- 128
- Available as
- eBook, Audiobook
Read better in the ZLOADR app
Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.
More by Cornelius Zana
Reddit Idea Validation GuideCornelius Zana$11.99
TM for Small Business OwnersCornelius Zana$11.99
The Anxious Teen WorkbookCornelius Zana$11.99
Competitive Program Stress GuideCornelius Zana$11.99
HGH And ResveratrolCornelius Zana$11.99
Fasting for LongevityCornelius Zana$11.99
Talking to Kids About DeathCornelius Zana$11.99
Strom Thurmond DixiecratCornelius Zana$11.99
Cold Weather Football GritCornelius Zana$11.99
The Serpent and the Storm: Vritra’s Last StandCornelius Zana$11.99
The Last Voyage of the Great Lakes Freighter: A Storm That Changed EverythingCornelius Zana$11.99
The Codebreakers' War: Bletchley Park vs. the Enigma of LoveCornelius Zana$11.99