iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Audit Checklist

Smart contract auditing (defensively framed): what auditors check, common bug classes, the patterns that prevent them, and how to prepare your contract for review.

Web3 — audit (defensively)

EXAMPLE
# RoE: defensive review. Audit your own contracts; commission audits for production deploys.

# ===== What an audit covers =====
# 1. Manual code review against known bug classes
# 2. Test coverage review
# 3. Formal verification (some audits)
# 4. Fuzzing + property tests
# 5. Static analysis (Slither, Mythril)
# 6. Deployment configuration review
# 7. Documentation + threat model

# ===== Common bug classes =====
# 1. Reentrancy
#    Calling external untrusted contract then mutating state.
#    Defense: checks-effects-interactions pattern; ReentrancyGuard modifier.
#
# 2. Integer arithmetic
#    Pre-0.8.x: overflow/underflow caused silent wraps.
#    Modern Solidity (0.8+): math is checked by default.
#    Watch unchecked { } blocks.
#
# 3. Access control
#    Functions missing onlyOwner / onlyRole.
#    Initialise functions callable by anyone after deploy.
#    Defense: AccessControl roles + initializer modifier.
#
# 4. Front-running / MEV
#    Public mempool exposes transactions before mining.
#    Defense: commit-reveal; permit / signature-based actions; private mempools.
#
# 5. Price oracle manipulation
#    Spot price from a thin DEX -> flash loan attack.
#    Defense: TWAPs over multiple blocks; multiple oracle sources; circuit breakers.
#
# 6. Delegatecall to untrusted code
#    Library or arbitrary call -> attacker controls storage.
#    Defense: only delegatecall to vetted contracts; immutable target.
#
# 7. Approve / allowance race
#    Front-run between approve(amount) and approve(0).
#    Defense: increaseAllowance / decreaseAllowance; permit (EIP-2612).
#
# 8. Incorrect Selfdestruct or upgrade controls
#    Anyone can call destruct -> proxy bricked.
#    Defense: onlyOwner + timelock + multisig.

# ===== Defensive patterns =====
# - Checks-Effects-Interactions: validate -> mutate -> call external
# - OpenZeppelin Contracts (audited base for everything)
# - ReentrancyGuard on functions that call external untrusted contracts
# - AccessControl + roles + multisig
# - Timelock between proposal + execution for upgrades
# - Pull payments over push (users withdraw rather than contracts paying)
# - SafeERC20 for token interactions (defensive against non-conforming tokens)

# ===== Pre-audit checklist =====
# - 100% test coverage on critical paths
# - Slither + Mythril runs clean
# - Hardhat / Foundry tests cover happy path + edge cases + reverts
# - Fuzz tests with echidna / foundry's invariant testing
# - Static analysis with crytic-compile + 4naly3er
# - Documentation: architecture, invariants, threat model
# - Known-issue list (anything you DELIBERATELY left)

# ===== During audit =====
# - Be responsive; clarify intent
# - Provide test cases for findings to help validate
# - Don't fix in production branch during audit; queue fixes
# - Track findings + your responses in a doc

# ===== After audit =====
# - Address ALL findings (or document risk acceptance)
# - Re-run audit on fixes (usually included)
# - Public report (helps the ecosystem)
# - Don't change the audited code post-deploy

# ===== Audit firms (2026) =====
# - Trail of Bits, OpenZeppelin, Consensys Diligence
# - Spearbit, Cantina (boutique)
# - Code4rena, Sherlock (contest-based)
# - Picking: budget + timeline + complexity match

# ===== Patterns to internalise =====
# - Default to OpenZeppelin contracts; do not roll your own ERC-20/721
# - CEI pattern + ReentrancyGuard
# - Multisig + timelock on all admin functions
# - TWAP oracles, not spot prices
# - Bug bounty program AFTER audit (Immunefi, HackenProof)

# ===== Pitfalls =====
# - One audit and you are done forever (no — re-audit on changes)
# - Skipping fuzz tests because 'we have unit tests'
# - Audit as a checkbox; team does not absorb findings
# - Deploying audited code with last-minute 'small' changes

Why it matters

Audits are defensive code review for contracts. Know the bug classes (reentrancy, MEV, oracle manipulation, access control), use OpenZeppelin + ReentrancyGuard + multisig + timelock, hit 100% coverage with fuzzing, and prepare a clean codebase + threat model before the auditors arrive. Bug bounty AFTER the audit. Never deploy unaudited code with real funds.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// Pre-audit checklist:
// - Reentrancy on every external call
// - Integer over/underflow assumptions (Solidity 0.8+ checks by default)
// - tx.origin never used for authZ
// - Slither + Mythril runs are clean
// - Tests cover the unhappy paths
// - Upgrade key custody is documented
Try it Yourself »

Discussion

Loading…