Establish the Threat Model First
Before writing a single line of Solidity, define assets, actors, and trust boundaries. Assume that every external call is malicious, flash loans can access arbitrary liquidity, and miners can manipulate block timestamps.
Defensive Architecture That Prevents 95% of Exploits
- Checks-Effects-Interactions (CEI): Update internal state before calling external addresses, and reinforce state transitions with OpenZeppelin ReentrancyGuard.
- Least-Privilege Role Isolation: Use
AccessControlDefaultAdminRuleswith mandatory 48-hour timelocks for contract upgrades and fee modifications. - Bounded Loop Operations: Enforce strict limits on array iterations to prevent block gas limit exhaustion attacks.
- Pull Over Push Payments: Require users to withdraw funds individually rather than batching transfers that can revert if a single recipient fails.
- Foundry Invariant & Fuzz Testing: Write stateful fuzz tests that execute thousands of randomized call sequences to discover edge-case invariant violations.
Mainnet Deployment Runbook
Testnet rehearsal on Sepolia, multisig vault ownership via Safe, pause circuit breakers, automated Tenderly monitoring, and a published incident disclosure runbook.
