Engineering
What an audit-ready codebase looks like
- Written by
- Maitreya Kulkarni, Co-Founder and CTO
- Published
- Reading time
- 5 min
A security audit buys a fixed amount of expert attention. Every hour reviewers spend working out how to build your project, which files are in scope or what a function is supposed to do is an hour they are not spending on the code paths that move money. The teams that get the most from an audit are not the ones with the fewest bugs going in. They are the ones whose codebase lets reviewers get to the hard questions fastest.
This is the checklist we use to prepare a protocol before it goes to review, whether the reviewer is us, an independent firm or both. Much of it overlaps with Trail of Bits' smart contract security checklist and their building-secure-contracts guidelines, which are worth reading in full.
1. A frozen scope
Give reviewers one commit hash and a list of the files in scope, with line counts. Say what is out of scope and why: libraries you import unchanged, peripheral contracts, offchain services. Then stop changing the code. An audit of a moving target is an audit of nothing in particular, and fixes merged during the review are fixes nobody reviewed.
If something must change mid-audit, tell the reviewers, give them the diff, and expect to pay for the time it takes to look at it.
2. A specification a stranger can read
Reviewers can only find places where the code does something other than intended if someone has written down what is intended. A good specification is short and concrete:
- the actors (users, keepers, admins, oracles, other protocols) and what each can do;
- the main flows, step by step, with the state they change;
- the assumptions: which tokens are supported, what an oracle may return, which external calls can fail;
- what must never happen.
NatSpec on every external function helps, but it does not replace the overview. If the only explanation of the system is in a founder's head, reviewers will reconstruct it from the code, which means they will reconstruct the code's mistakes as intentions.
3. The admin-powers table
List every privileged action: who can take it, with what threshold, after what delay, and the most value it can move or put at risk. We ask for this table before any review because it is where the largest losses of the past few years started, as we explain in most onchain money is lost through keys, not code. It also tells reviewers which functions deserve the closest reading.
4. Invariants, written down and tested
An invariant is a property that must hold after any sequence of calls: total shares never exceed total assets, no user can withdraw more than they deposited plus earned interest, the sum of balances equals the total supply, a paused protocol moves no funds. Write them in plain language in the specification, then encode them.
Foundry's invariant testing calls your contracts in random sequences and checks the properties after each call; tools such as Echidna and Medusa do the same with different strategies. A handful of well-chosen invariants, run against long random sequences in CI, finds a class of bug that unit tests do not, and it gives reviewers a precise statement of what you believe to be true. Their job then becomes finding the sequence that breaks it.
5. Clean static analysis
Run Slither and any other analysers you use in CI, on every change. Before the audit, triage everything they report: fix what is real, and annotate what is a false positive and why. Reviewers should not spend their first day reading two hundred warnings you already knew about.
6. Tests that run from a clean clone
One command should install dependencies, build and run the whole suite on a fresh machine, with pinned compiler and dependency versions. Check it by doing exactly that. Then look at what the tests actually cover. Most suites test the happy path thoroughly and the failure paths barely: reverts on bad input, behaviour at limits, what happens when an external call fails or a token charges a fee on transfer. Coverage numbers are a rough guide; the failure paths are the point.
7. Deployment and upgrade scripts in scope
Many incidents begin in a deployment: an initializer left callable, a constructor argument wrong, a role granted to a deployer key and never revoked, an upgrade that reorders storage. Put deployment and upgrade scripts in scope, with the parameters you intend to use on mainnet. After the audit, confirm that the bytecode you deploy matches the commit that was reviewed, and record the check.
8. Known issues and design decisions, listed
Write down what you already know: accepted risks, deliberate trade-offs, behaviour that looks like a bug but is intended, issues from earlier reviews and how you handled them. Reviewers will still examine them, but they will not spend a day rediscovering a decision you made on purpose, and you will not pay for findings you could have predicted.
9. Time for fixes, and a fix review
Plan the calendar so that there is room between the end of the review and your launch to fix what is found, and for the reviewers to check the fixes. A findings report followed by an untested patch the night before mainnet is a common way to ship a new bug. Every fix should come with a test that fails before it and passes after.
After the audit
An audit is a snapshot of one commit. Keep the invariant suites running. Review every upgrade as a diff against the audited version. Put monitoring on admin actions and outflows, and consider a bug bounty sized to the value at risk. The code will change; the discipline that made it reviewable should not.
What we bring
When we prepare a codebase for review, we bring an audit-prep pack: templates for the specification and the admin-powers table, an invariant and fuzzing harness wired into CI, a static-analysis baseline, deployment checks, and the monitoring and pause runbooks that should exist before launch. It is the same material we use on our own smart contract builds, and the starting point for our security reviews. If you have a review coming up, tell us when.
Read next
Related pages.
Smart contract security audit
Most onchain money is lost through keys, not code
Use case: security and admin-key risk
- Security
Most onchain money is lost through keys, not code
The largest crypto thefts of recent years broke no contract logic. What public reports show, and the controls we build around keys and admin powers.5 min read - Tokenization
Tokenizing real-world assets without a liquidity trap
Many tokenized assets only move through mint and redeem. Seven decisions to make before you choose a chain, so your token can actually trade.5 min read
Start a build
Bring us the contract you're not sure about.
What happens next
- 01Tell us what you are buildingA short note or a 30-minute call: the product, the chain if you know it, and where the money sits.
- 02Hear back within 48 hoursEvery message is read by the team, not a filter.
- 03A first working sessionWe walk through the threat model and the admin powers with you, then propose a scope and a plan.