How to Prepare a Smart Contract for a Security Audit
Audit readiness means the code is frozen, the docs are complete and the tests pass before auditors start. Here is how to get there.
On this page
Short answer
A smart contract is ready for a security audit when the code is frozen, the architecture and trust assumptions are written down, the test suite passes, and a threat model lists the assets and the attacks to check. Preparing properly takes about two weeks for a typical token contract, and it is the cheapest way to get a useful audit.
What does smart contract audit readiness mean?
Smart contract audit readiness is the state where a contract, its documents and its tests are complete enough for auditors to start work without waiting on the team. The code is frozen, the architecture is written down, the tests pass, and the team has listed what it already knows is wrong.
Readiness matters because auditors charge for their time, and time spent waiting for documents or chasing a moving codebase is time not spent finding bugs. A team that arrives ready gets a deeper audit for the same fee.
| Readiness item | What ready looks like |
|---|---|
| Frozen code | No changes during the audit, except fixes the auditors request |
| Architecture doc | How the contracts fit together, in one page or two |
| Trust assumptions | Who is trusted, and what happens if they misbehave |
| Test suite | Passing, with unit, invariant and fork tests |
| Threat model | Assets, attackers and worst cases listed |
| Known issues | A list of problems already found, with reasons |
Readiness is not the same as the audit itself. It is the preparation that makes the audit useful, and it is the team's job, not the auditor's. For what an audit covers, see what a smart contract audit is.
What documents should you prepare?
Auditors need four documents before they start: an architecture note, a list of trust assumptions, a list of known issues, and deployment notes. Each one answers a question the auditor would otherwise have to ask, and each one saves audit time.
The architecture note explains how the contracts fit together, which contract holds funds, which one can mint or burn, and how upgrades work. It should fit on one or two pages. A long document that nobody reads is worse than a short one that is kept current.
Trust assumptions state who is trusted and what happens if they misbehave. If the owner can pause the contract, say so. If an oracle price can be manipulated, say so. Hiding a trust assumption does not remove the risk; it only means the auditor finds it later, when fixing it costs more.
Known issues are the problems the team already found and chose not to fix, with the reason for each. Auditors will find most of them anyway, so listing them saves a round of back-and-forth and shows the team has thought about the design.
What tests should pass before the audit?
Four kinds of tests should pass before the audit: unit tests, invariant tests, fork tests and fuzzing. Each kind catches a different class of bug, and together they show the auditors that the team has tested the contract seriously.
| Test type | What it checks |
|---|---|
| Unit tests | Each function behaves as designed |
| Invariant tests | Rules that must always hold, such as supply matching balances |
| Fork tests | Behaviour against the real chain state |
| Fuzzing | Random inputs that break hidden assumptions |
Invariant tests deserve special attention. An invariant is a rule that must always hold, such as the total supply equalling the sum of all balances, or a vault never paying out more than it holds. A test that checks invariants across many random actions catches bugs that single-case tests miss.
Fuzzing feeds random inputs to the contract and watches for failures. It is cheap to run and often finds edge cases the team never thought of, such as a zero-amount transfer or a call in an unexpected order. Run it before the audit, not after.
How do you build a threat model?
A threat model lists what the contract protects, who might attack it, and what the worst case looks like. It starts with assets: the funds held, the tokens that can be minted, and the permissions that can change the rules.
Next, list the actors. The owner, the users, the oracle, the keepers and the other contracts it talks to are all actors, and each one can misbehave or be compromised. For each actor, ask what it can do and what damage that would cause.
Then list the entry points: every public function, every callback, and every external call. Each entry point is a place an attacker can reach, so each one needs a check on who can call it and what state it can change. A function that anyone can call and that moves funds is the first place an auditor looks.
Finally, write down the worst cases: a drained vault, an unlimited mint, a frozen contract, a manipulated price. For each one, note the control that stops it, such as a cap, a pause or a timelock. A threat model without controls is only a list of fears. See smart contract audit services for how auditors work with this material.
Example (hypothetical): a token audit timeline
Example (hypothetical): a team plans an audit for a token contract with a fixed supply and a vesting schedule. Preparation takes 2 weeks, the audit takes 3 weeks, fixing the findings takes 1 week, and the auditors re-check the fixes in 3 days.
The total is 2 + 3 + 1 = 6 weeks, plus 3 days for the re-check, so about 6.5 weeks from the start of preparation to a finished report. The launch is planned for week 8, leaving about 1.5 weeks of slack.
If the team skips preparation and the auditors wait a week for documents, the total becomes about 7.5 weeks and the slack disappears. The lesson is that preparation is not overhead: it protects the launch date, because a week lost at the start is a week lost at the end.
What are the common mistakes?
The most common mistakes in audit preparation are changing the code during the audit, hiding known issues, and skipping the re-check. Each one wastes audit time or leaves a known bug in the deployed contract.
- Changing code mid-audit. Auditors review a fixed version; a change forces them to start that part again.
- Hiding known issues. Auditors find them anyway, and trust in the team drops when they do.
- No pause mechanism. A contract with no way to stop it cannot be protected if a bug is found live.
- Unaudited dependencies. A library or oracle that nobody reviewed is still part of the system.
- Skipping the re-check. Fixes that nobody verifies can introduce new bugs while closing old ones.
- No deployment plan. A contract deployed without a checked address and a verified source is hard to trust.
The pause mechanism deserves care. A pause that only the owner can lift is a trust risk, while a pause with a timelock gives users time to react. Write the choice down in the trust assumptions so the auditors can judge it. For the deployment steps, see how to create a smart contract on BSC.
What happens after the audit?
After the audit, the team fixes the findings, the auditors re-check the fixes, and the report is published. The fix round is part of the audit, not an extra: a finding without a verified fix is still a live risk.
Fixes should be small and focused. A large rewrite in response to a finding can introduce new bugs, and the auditors may need to review the changed code again. If a fix needs a redesign, say so early and agree a new review window.
Publishing the report, including the findings that were fixed, builds trust with users and exchanges. A report that only lists the clean result hides the work that went into it. Keep the report public, keep the deployed code verified on the block explorer, and keep monitoring the contract after launch, because an audit is a snapshot, not a guarantee.
Key takeaways
- Freeze the code before auditors start
- Write down trust assumptions and known issues
- Pass unit, invariant, fork and fuzz tests
- Build a threat model with assets and worst cases
- Always get fixes re-checked before launch
Frequently asked questions
What does audit readiness mean?
It means the code is frozen, the architecture and trust assumptions are written down, the test suite passes, and a threat model lists the assets and the attacks to check. A team that arrives ready gets a deeper audit for the same fee, because auditors spend their time finding bugs instead of waiting.
How long does preparation take?
About two weeks for a typical token contract, covering documents, tests and a threat model. The audit itself usually takes two to four weeks depending on the size of the codebase, and fixing the findings takes about a week more.
What documents do auditors need?
An architecture note, a list of trust assumptions, a list of known issues, and deployment notes. Each one answers a question the auditor would otherwise have to ask, and each one saves audit time. Keep the architecture note to one or two pages.
Can I change the code during an audit?
No. Auditors review a fixed version, and a change forces them to start that part again. Freeze the code when the audit starts, and make only the fixes the auditors request, then have those fixes re-checked.
What is a threat model?
It is a list of what the contract protects, who might attack it, and what the worst case looks like. It covers assets, actors, entry points and controls such as caps, pauses and timelocks. A threat model without controls is only a list of fears.
Is an audit a guarantee the contract is safe?
No. An audit is a snapshot of the code at one point in time, and it cannot catch every bug or every future change. Keep monitoring the contract after launch, publish the report, and keep the deployed code verified on the block explorer.