The bug classes that drain the most value — reentrancy, access control — and the symbolic-execution and theorem-proving tools that catch them before an audit.
Almost every large loss in DeFi comes from a small set of mistakes that were known before the code was written. That is the uncomfortable part of smart contract security: the bug classes are public, documented, and still exploited every year, because the conditions that produce them — an external call before a state update, a spot price read from a thin pool, an initialiser anyone can call — keep reappearing in new shapes.
The bug classes that actually drain money
Reentrancy. A contract makes an external call before updating its own state, so the callee can re-enter and act on the stale state. The 2016 DAO drain, roughly $60 million in ETH, was the original. The modern variants are subtler: read-only reentrancy through a view function that other protocols trust, cross-function reentrancy where the second entry point is a different function, and ERC-777 or callback hooks that turn an otherwise safe-looking transfer into a re-entrant one. The fix is ordering (checks, effects, interactions) plus a reentrancy guard, and neither is optional.
The difference between the vulnerable and the fixed version is four lines of ordering, which is why this class never dies:
// Vulnerable: external call happens BEFORE the state update
function withdraw() external {
uint256 amount = balances[msg.sender];
(bool ok,) = msg.sender.call{value: amount}("");
require(ok);
balances[msg.sender] = 0; // too late — msg.sender just re-entered
}
// Fixed: effects before interactions
function withdraw() external {
uint256 amount = balances[msg.sender];
balances[msg.sender] = 0; // effect first
(bool ok,) = msg.sender.call{value: amount}(""); // interaction last
require(ok);
}
Copy link
Read the vulnerable version once and it looks fine — the balance is read, the transfer is required to succeed, the bookkeeping happens. The exploit lives entirely in the sequence: during the call, the callee's fallback runs with balances still showing money that is logically already gone. Every reentrancy review starts by drawing exactly this sequence.
Access control. Missing modifiers, role checks that validate the wrong address, an onlyOwner that resolves to the deployer's hot wallet, or an initialiser that was never called and therefore can be called by anyone. The last one is worth dwelling on: an un-initialised proxy is a fully open contract, and it is a mistake that ships constantly because tests run against an initialised instance.
The mechanism, in six lines per side:
// The proxy delegates everything to the implementation...
function initialize() external initializer {
owner = msg.sender; // if nobody called this, nobody is owner
}
// ...and an un-initialised proxy lets anyone become it:
attacker.initialize(); // attacker is now owner
attacker.upgrade(newImpl); // and owns every proxied balance
Copy link
Tests pass because the test fixture calls initialize() in setup — the deployment script must call it too, and the race between deployment and initialisation is its own attack window. The mature pattern removes the race: initialise in the same transaction as deployment, or transfer ownership to a timelocked multisig immediately.
Oracle manipulation. Reading a price from a spot pool that an attacker can move inside a single transaction, or from a feed whose update cadence is longer than the attack. This class is responsible for a large share of the largest exploits, and it is frequently a design failure rather than a coding one: the code does exactly what it says, against a price that was never trustworthy.
Proxy and upgrade flaws. Storage-collision between implementation versions, an upgrade path guarded by a single key, a delegatecall into an address that can be changed. Upgradability trades immutability risk for governance risk, and the second is usually easier to exploit because it does not require a novel bug.
Economic and logic errors. Correct code used incorrectly: a rounding direction that leaks value on every call, an accounting invariant that quietly breaks at a boundary, a reward calculation that can be gamed by splitting a position.
An audit is a review by humans who have seen this class of bug many times. It is good at finding logic errors, access-control gaps, and deviations from established patterns. It is not a proof, and the report usually says so. Scoped time means the reviewers sample rather than exhaust the code, and a clean audit is a statement about the code that was reviewed at the time — not about a subsequent upgrade, a new integration, or an economic assumption nobody questioned.
Tools that extend the audit
Static analysis (Slither and similar) walks the code and flags known-dangerous patterns. Fast, cheap, noise-heavy, and best run on every commit rather than once.
Fuzzing and invariant testing run the contract against random and adversarial inputs, asserting properties that must always hold — total supply equals the sum of balances, the protocol's assets always exceed its liabilities. Foundry has made this the highest-value-per-hour activity available, because invariants encode the things you actually care about and the fuzzer finds the path you did not.
An invariant worth writing is a sentence with "always" in it, translated to code: "no user can withdraw more than they deposited," "a paused protocol cannot lose funds," "the sum of user obligations never exceeds the vault's balance." The craft is choosing invariants that are strong enough to catch real bugs and simple enough to stay true — an invariant that itself encodes a buggy formula just proves the bug. Start with the accounting identities, because they are both the easiest to state and the ones every major exploit ultimately violates.
Symbolic execution (Halmos, and Manticore before it) replaces concrete values with symbolic ones and asks a constraint solver whether a violating path is feasible. It finds real bugs and produces a counterexample, at the cost of state-space explosion on complex code.
Formal verification (Certora Prover, KEVM) derives a proof that the implementation satisfies a specification. It is powerful, and its real output is often the specification itself: writing down what the contract is supposed to do finds bugs before the prover runs.
What verification cannot prove
Four limits are worth stating plainly, because teams routinely overread a green result.
Verification says nothing about economic correctness. Accounting can be internally airtight while the price input is manipulable — the proof covers the arithmetic, not the assumption.
It says nothing about composability. Every contract you call is unverified in this proof, so the system as a whole is not what was proven.
It can be invalidated by governance. If an upgrade is possible, every proven property holds only until the next upgrade, which means the upgrade path is part of the security surface and not an operational footnote.
And it assumes oracle correctness. If the feed is wrong, a proven contract is faithfully wrong.
The pipeline that catches them
The tools are not alternatives; they are stations in an order, and the order is set by cost per finding. Static analysis runs on every commit — seconds of compute, noisy output, and the noise is cheapest to read at this stage. Invariant fuzzing runs nightly and on every PR that touches state logic — hours, far fewer false positives, and it catches the interactions static analysis cannot see. Symbolic execution runs on the functions where a proof is feasible — targeted, expensive, decisive. The audit happens once the pipeline is quiet, because paying auditors to find what Slither finds is the most expensive way to buy a finding. Monitoring runs after deployment, forever, because everything before this point was a statement about a snapshot.
Teams that invert the order — audit first, tooling later, monitoring never — buy their findings at the worst possible price: discovered in production, paid for by users.
What actually reduces risk
Layer the cheap controls that stop a bug from becoming a catastrophe: rate limits and caps on what any single transaction or signer can move, a timelock on parameter changes so a compromised key is not instantly fatal, a pause mechanism that actually works and that someone is watching, and monitoring that alerts before the loss is unrecoverable. Then add the bug bounty, so the person who finds the bug has a reason to report it rather than use it. None of that is a substitute for careful code.
Reading a protocol's security posture without reading code
Most people interacting with contracts are not the people who wrote them, and the good news is that the decision-relevant signals do not require reading Solidity. What to check, in the order it filters: is the code verified and the repository public — unverified contracts are not a risk, they are a statement; who is named on the audit, whether more than one firm reviewed it, and whether the audit predates the last material change (an audit of last year's code is context, not assurance); what the timelock on upgrades is, and whether that delay is long enough for users to leave; and whether there is a public bug bounty, because a bounty is a price tag on the team's confidence in its own code.
None of these signals is strong alone. Together they separate protocols that treat security as a practice from protocols that treat it as a launch checklist item — and the difference is where deposits belong.
The first hour of an incident
When something breaks, the first hour decides whether the loss is the exploit or everything after it. The sequence that works: pause what is pausable — this is why the pause authority and the rehearsal exist; freeze frontends so users stop depositing into a broken contract; and communicate with one honest sentence — what happened, what is safe, what is not, what you do not know yet. Silence during an exploit is read as either negligence or complicity, and both cost more than the truth.
What not to do matters as much: do not fix silently and pretend nothing happened — on-chain forensics make that a lie with a timestamp; do not post speculation about the attacker's identity or motives; and do not negotiate panic responses in public threads. Incidents end up judged less by the bug than by the first hour, and the teams that rehearsed this sequence — who pauses, who speaks, who freezes — recover deposits and reputations that the ones improvising do not.
The operational layer audits never see
Every control above has a human behind it, and the humans are where audits go blind — they review code, not rosters. Four questions decide whether the controls exist in practice rather than in the docs:
Who can actually pause? The pause function that the docs describe is only as real as the signer set that can call it at 3 a.m. on a Sunday. If pausing requires a four-of-seven multisig whose signers are in three time zones, the effective pause authority is whoever happens to be awake — and the rehearsal (see below) is how you find out it is nobody.
Where do the keys live? The deployer hot wallet that survives after launch is the most common leftover key in this industry. A key inventory with a disposal date — what exists, who holds it, when it gets swept and burned — costs an afternoon and closes the gap that most post-mortems name as "unknown signature."
What does the timelock actually delay? A 48-hour timelock on parameter changes is a strong control against a compromised key and a weak one against a captured governance vote, because a majority attacker simply schedules the theft. Knowing which attacker your timelock stops is the difference between a control and a decoration.
When was the incident plan last rehearsed? The response plan that exists as a Notion page fails its first real use. A one-hour tabletop — a fake alert, the real people, the real pausing procedure, the real comms channel — twice a year is the entire cost of making the plan real. Every serious post-mortem contains a line about what the team meant to have rehearsed.
These are unglamorous controls, and that is the point: by the time an incident starts, the code is what it is, and the outcome is decided by the operational layer that was either built or skipped.