A smart contract audit is a time-boxed security review of a fixed version of your code. You agree a scope (files and commit hash), freeze the code, and one or more reviewers spend days to weeks reading it line by line, running static analysis, fuzzing and sometimes formal verification, and testing your assumptions about how it can be attacked. You get a report of findings ranked by severity, fix them, and the auditors run a fix review before a final report is published. Preparing well means a frozen commit, a written specification and threat model, passing tests with meaningful coverage, and a clean static-analysis run, so the reviewers' hours go into finding real bugs rather than understanding your code.
What an audit is, and what it isn't
An audit gives you expert eyes on a specific snapshot. It does not certify that the code is safe, it does not cover code outside the scope or written after the audited commit, and it does not review your off-chain infrastructure, keys or front end unless you pay for that separately. Plenty of exploited protocols had audits; the usual gaps were unaudited changes, integrations outside the scope, or economic attacks nobody modelled. Treat an audit as one layer alongside tests, monitoring, a bug bounty and careful key management.
The examples below use Solidity and Foundry, since most audits cover code for Ethereum and other EVM chains, but the process is the same for Rust programs on Solana, Move on Sui and Aptos, or Cairo on Starknet. Only the tools change.
The audit process, step by step
| Stage | What happens | Your job |
|---|---|---|
| Scoping | Auditors look at the repo, count lines of code (usually nSLOC: non-blank, non-comment source lines), identify complexity and integrations, and quote a duration and price | Share the repo, docs, target chains and deadlines early |
| Scheduling | Reputable firms are often booked weeks or months ahead | Book before the code is finished, then hold the date |
| Code freeze | A specific commit hash is fixed as the audit target | Tag it; don't push "small fixes" to it |
| Kickoff | A call to walk through architecture, roles and concerns | Bring the engineers who wrote the code |
| Review | Manual review plus tooling. Auditors ask questions in a shared channel | Answer quickly; slow answers burn audit days |
| Preliminary report | Findings with severity, description, proof of concept and recommendation | Triage: fix, acknowledge or dispute each one |
| Fix review | Auditors check your fix commits, and only those | Keep fixes small and separate from new features |
| Final report | Published, usually listing the audited and fixed commit hashes | Deploy exactly that code |
What the reviewers actually do
Most of the value is manual. A reviewer reads the code with your specification beside it and asks, for every function: who can call this, with what inputs, in what state, and what happens if they do it twice, out of order, or inside a callback. Common finding categories:
- Access control: missing modifiers, unprotected initialisers, roles that can do more than documented.
- Business logic: accounting that drifts, rounding in the attacker's favour, edge cases at zero or at maximum values.
- External calls: reentrancy, including cross-function and read-only variants, unchecked return values, tokens that behave unusually (fee-on-transfer, rebasing, missing return values).
- Oracles and pricing: spot prices that can be moved inside one transaction, and unsafe reads of Chainlink feeds that skip staleness checks.
- Economic attacks: anything that becomes profitable with large temporary capital, which is where flash loan attacks come from.
- Signatures: replay across chains or contracts, missing nonces or deadlines, malleability.
- Upgradeability: storage layout collisions, uninitialised implementations, upgrade paths controlled by one key.
Tooling supports the manual work: static analysers such as Slither and Aderyn, fuzzers such as Echidna, Medusa and Foundry's own fuzzer, symbolic execution with Halmos, and for some engagements formal verification with tools like Certora.
Severity levels
Labels vary by firm, but most use something like this:
| Severity | Typical meaning |
|---|---|
| Critical / High | Direct loss or freezing of funds, or takeover, with realistic conditions |
| Medium | Loss under specific conditions, or a broken core function |
| Low | Minor issues, unlikely or low-impact edge cases |
| Informational | Code quality, documentation, best practice |
| Gas | Optimisation suggestions |
Severity usually combines impact and likelihood. If you disagree with a rating, argue with a concrete reason (a precondition that can't occur, an admin action that is already trusted), not with "we'd never do that".
Types of review
- Private audit: one firm or a small team of named reviewers. Predictable schedule and a direct relationship; coverage depends on the people assigned.
- Competitive audit (contest): platforms such as Code4rena, Sherlock, Cantina or CodeHawks open the code to many independent researchers for a fixed period, paying for valid findings. You get breadth and many perspectives, but also many duplicate or low-quality submissions to judge.
- Solo researchers: independent auditors, often booked for a focused review.
- Bug bounty: an ongoing reward for vulnerabilities in deployed code, commonly run through Immunefi. It complements an audit; it does not replace one.
Larger protocols commonly combine a private audit, then a contest, then a bounty at launch.
How do I prepare for an audit?
Freeze and tag the code
git checkout main && git pull
git tag audit-v1 && git push origin audit-v1
git rev-parse audit-v1 # this hash goes in the scope document
Pin compiler and dependency versions so the auditors build exactly what you will deploy. A floating pragma solidity ^0.8.0; and an unpinned lib/ make it impossible to say what was reviewed.
Write a scope document
Put it in the repo root. Auditors read this first.
## Audit scope
Commit: 3f9c2e1 (tag audit-v1)
In scope: src/Vault.sol, src/Strategy.sol, src/lib/Math.sol (~1,150 nSLOC)
Out of scope: test/, script/, src/mocks/
Chains: Ethereum mainnet, Base
Compiler: solc 0.8.28, evm_version cancun
## Roles
- OWNER (3/5 Safe behind a 48h timelock): set fees (max 10%), pause, upgrade
- KEEPER (bot EOA): harvest(), can't move user funds
## Integrations and token assumptions
- Uniswap v3 pools (TWAP 30 min), Chainlink ETH/USD
- Supported tokens: USDC, WETH only. No fee-on-transfer or rebasing tokens.
## Invariants
1. totalAssets() >= sum of user claims
2. Only the user or their approved operator can withdraw their shares
3. Pausing never blocks withdrawals
## Known issues (please don't report)
- First depositor can receive dust rounding; mitigated by seeded deposit at deploy
The invariants section is the most valuable part. It tells reviewers what "broken" means, and it should match the properties your own tests check.
Get the tests into shape
Every external function should have tests for the happy path, the reverts and the boundary values. Then add property-based tests: fuzz and invariant tests in Foundry turn the invariants above into code that runs millions of random call sequences. Fork tests against real integrated contracts catch wrong assumptions about tokens and pools.
forge build --sizes # also confirms contracts fit the 24 KiB limit
forge test -vvv
forge coverage --report summary # look for untested branches, not a magic number
forge test --fork-url $MAINNET_RPC --match-contract Integration
Coverage is a map of what you haven't tested, not a score. Line coverage of 100% with no failure-path assertions proves little.
Run the static analysers yourself
slither . --filter-paths "lib/|test/" --exclude-dependencies
aderyn .
Fix what's real and document what isn't. Paying auditors to report issues a free tool would have flagged wastes their time and pads your report with noise.
Clean up
- Remove dead code, commented-out code, unused imports and
TODOs. - Add NatSpec to every external function: what it does, who may call it, what it assumes.
- Include deployment and upgrade scripts in scope if they set roles or initialise proxies. Many incidents start with a misconfigured deploy, not a contract bug. If you use proxies, make sure the team understands how UUPS and transparent proxies handle initialisation and upgrades.
- For a re-audit, provide a diff against the previously audited commit and the old report.
During and after the audit
During the review, have an engineer available every working day. Don't change the frozen commit; collect fixes on a branch.
When the report arrives:
- Write a failing test for each valid finding before you fix it, so the fix is proven and can't regress.
- Fix in small, separate commits that reference the finding id.
- Don't sneak features into the fix-review commits. Anything not in the original scope or a finding's fix is unaudited.
- Deploy the final audited commit, then verify the deployed bytecode on Etherscan so anyone can compare it with the report.
- Publish the report and the commit hashes.
After launch, keep the layers going: on-chain monitoring and alerts, a bug bounty, a pause mechanism where appropriate, and admin keys held in a multisig with a timelock. The operational side, from hardware wallets to signer policies, is covered in how a team should hold crypto safely.
Checklist
- Book the audit early; freeze and tag the commit before the start date.
- Pin the compiler, EVM version and dependency versions.
- Scope document: files, nSLOC, chains, roles, integrations, token assumptions, invariants, known issues.
- Unit, fuzz, invariant and fork tests passing; coverage reviewed for gaps.
- Slither and Aderyn run, findings fixed or documented.
- Dead code removed, NatSpec on external functions, deploy scripts included.
- One engineer on call throughout the review.
- Test-first fixes, one commit per finding, no new features in fix review.
- Deploy and verify the exact final commit; publish the report.
- Monitoring, bug bounty and multisig plus timelock after launch.
Get the weekly commit
New blockchain deep dives every week.