Blockchain & Smart Contract Security
Blockchain and smart contract security focuses on vulnerabilities in decentralized applications (dApps), DeFi protocols, and cryptocurrency systems. Unlike traditional applications, smart contract bugs are immutable once deployed—a single vulnerability can result in millions of dollars stolen. This guide covers Solidity security, common attack patterns, and audit methodology.
Authorised Targets Only
Immutability = Permanent Bugs
Smart Contract Attack Surface
Smart Contract
- Reentrancy vulnerabilities
- Integer overflow/underflow
- Access control bugs
- Front-running attacks
- Delegatecall injection
DeFi Protocol
- Flash loan attacks
- Oracle manipulation
- Liquidity pool exploits
- Price manipulation
- Governance attacks
Wallet/User
- Phishing attacks
- Private key theft
- Malicious transaction signing
- Rug pulls / exit scams
- Social engineering
Common Smart Contract Vulnerabilities
1. Reentrancy (The DAO Hack)
External contract calls before state updates allow attacker to recursively drain funds. Famous $60M DAO hack in 2016.
(bool ok, ) = victim.call{value: amount}(""); // BAD: sends ETH before updating balance
2. Integer Overflow/Underflow
Arithmetic operations exceeding uint256 max (2^256-1) wrap around to zero. Fixed in Solidity 0.8.0+ with automatic checks.
uint256 balance = 0; balance -= 1; // underflows to MAX_UINT
3. Access Control Bugs
Missing or incorrect onlyOwner modifiers allow unauthorized users to call privileged functions.
function withdrawAll() public {} // BAD: anyone can withdraw
4. Unchecked External Calls
Failing to check return value of send() or call() can result in silent failures.
addr.send(amount); // BAD: doesn't revert on failure
Landmark Crypto Hacks
| Date | Project | Loss | Vulnerability |
|---|---|---|---|
| 2016-06 | The DAO | $60M | Reentrancy attack |
| 2021-08 | Poly Network | $610M | Cross-chain bridge exploit |
| 2022-03 | Ronin Network | $625M | Validator key compromise |
| 2022-10 | Mango Markets | $114M | Oracle price manipulation |
| 2023-03 | Euler Finance | $197M | Flash-loan donation attack on solvency checks |
| 2023-07 | Curve pools (Vyper) | ~$70M | Compiler bug: reentrancy lock failed in Vyper 0.2.15 |
| 2025-02 | Bybit | $1.46B | Compromised Safe signing interface; cold-wallet keys |
| 2025-05 | Cetus Protocol (Sui) | ~$223M | Missing overflow check in a shared liquidity-math helper (Move) |
Smart Contract Testing Tools
Static Analysis
- Slither (Trail of Bits)
- Aderyn (Cyfrin)
- Semgrep (Solidity rules)
- Halmos (symbolic)
Fuzzing
- Echidna
- Medusa
- Foundry (forge fuzz, invariants)
- Diligence Fuzzing
Testing Frameworks
- Foundry (forge, anvil, cast)
- Hardhat
- Ape (Python)
- Tenderly (fork simulation)
Billions Lost, Same Bug Classes
Audit Checklist
- ✓ Reentrancy: Checks-Effects-Interactions pattern enforced?
- ✓ Access Control: All privileged functions have proper modifiers?
- ✓ Integer Arithmetic: Solidity 0.8.0+ checked arithmetic, and every
uncheckedblock justified? - ✓ External Calls: Return values checked? Gas limits considered?
- ✓ Oracle Security: Using decentralized oracles (Chainlink)? Time-weighted average price (TWAP)?
- ✓ Flash Loan Resistance: Critical operations protected against single-block attacks?
- ✓ Upgradeability: If using proxies, is upgrade mechanism secure?
- ✓ Front-Running: Critical functions protected against MEV attacks?
Guide Contents
Blockchain Fundamentals
Ledger, consensus and EVM basics, plus a local Foundry or Hardhat chain to test on.
Solidity Security
tx.origin authentication, unchecked transfers, and delegatecall to a caller-supplied target.
Reentrancy Attacks
The vulnerable bank, the attacker contract, and both ways to close the hole.
Integer Bugs
Overflow, underflow, unchecked blocks, and why SafeMath is now history.
Access Control
Missing modifiers and the tx.origin phishing path, vulnerable and fixed.
Account Abstraction
ERC-4337 user operations and EIP-7702 delegation, and what running a delegate as an EOA exposes.
DeFi Attacks
Flash loans, spot-price oracles, and the protocol logic they break.
Wallet Security
Approvals, blind signing, address poisoning, and inspecting an extension safely.
NFT Security
Predictable token IDs, mutable metadata, mint reentrancy, and signature replay.
Auditing
Scoping, automated and manual review, tooling that still works, and severity calls.
Related Topics
Cryptography Attacks
The cryptographic primitives underneath — hashing, signatures, key exchange — and how they fail.
Source Code Review
The manual review method this section applies to Solidity: sink-first, taint-aware, evidence-driven.
Web Penetration Testing
The web-layer classes a dApp front end still inherits: XSS, CSRF, SSRF, file upload and authentication bypass.
API Pentesting
Exchange and indexer APIs behind most protocols, and the authentication they get wrong.