How to Run a Smart Contract Audit Before You Ship
A smart contract audit checks your code for logic errors, access flaws and economic attacks before real money is at stake. Here is how to run one, step by step.
On this page
Short answer
A smart contract audit is a structured review of your contract code by independent reviewers who look for logic errors, access control flaws, rounding issues, and ways an attacker could drain funds or lock them. You prepare the code, freeze it, agree the scope, run the review, fix the findings and retest. An audit reduces risk, but it does not prove the code is safe.
What is a smart contract audit?
A smart contract audit is an independent security review of smart contract code, carried out before the contract handles real funds. Reviewers read the code line by line, test how it behaves under attack, and report the issues they find with a severity rating.
It is not a code review by your own team and it is not a test suite. The value is independence: reviewers who did not write the code and have no stake in the launch date are more likely to spot the flaw everyone else walked past. Most audits combine manual reading with automated tools, and the manual part is where the serious issues are usually found.
What an audit normally covers:
| Area | What reviewers check | Why it matters |
|---|---|---|
| Access control | Who can call each function | Stops strangers running admin functions |
| Logic and math | Rounding, overflows, edge cases | Small errors can move large sums |
| External calls | Reentrancy and untrusted contracts | Stops one call draining the contract |
| Economic attacks | Price feeds, front-running, incentives | Stops attackers gaming the rules |
| Upgrades and admin | Proxy patterns, keys, timelocks | Stops a single key taking over |
| Gas and denial of service | Loops, storage, unbounded lists | Stops the contract grinding to a halt |
An audit report is a list of findings with severity, not a pass or fail stamp. How you handle the findings matters as much as the review itself. The background is covered in what a smart contract audit is.
Why run an audit before launch?
You run an audit before launch because a deployed contract is hard to change and easy to attack. Once funds are in it, anyone in the world can read the code and probe it for weaknesses, and a flaw found after launch is a live incident, not a bug ticket.
Three reasons make the timing matter. First, fixing a flaw before deployment costs a code change; fixing it after deployment can mean migrating funds, pausing the product and explaining the incident to users.
Second, an audit forces your team to document what the contract is supposed to do, which often surfaces design problems before reviewers even start. Third, users, partners and exchanges treat an audit report as a basic signal of care, even though it is not a guarantee.
An audit does not remove risk. It reduces the chance that a known class of flaw ships, and it gives you a written record of what was checked and what was fixed. That record is useful long after launch, when new team members need to understand why the code looks the way it does.
How to run a smart contract audit, step by step
Running an audit is a process with a clear order. Skipping the preparation steps is the most common reason audits run late or miss the code that matters.
- Freeze the code. Pick the exact commit to be audited and stop changing it. Reviewing moving code wastes the reviewers' time and leaves findings that no longer apply.
- Write down what the contract should do. A short specification, the intended invariants and the threat model: who the attackers are and what they can do. Reviewers test against this, not against their guesses.
- Agree the scope. List every contract, library and dependency in scope, and say what is out of scope. Hidden dependencies are where surprises live.
- Run your own checks first. Tests, linting and automated scanners should pass before the audit starts, so reviewers spend their hours on logic, not on issues a tool would have caught.
- Run the review. Reviewers read the code, write attack scenarios, test edge cases and raise findings with severity ratings. Expect questions; a good audit is a conversation, not a silent report.
- Fix, then retest. Fix the findings in order of severity, then ask the reviewers to check the fixes. A fix that introduces a new flaw is a real risk, so the retest matters.
Budget for the whole cycle, not just the review. Preparation and fixes usually take as long as the review itself. If you need help scoping the work, smart contract audit services describe what a typical engagement covers.
Example (hypothetical): auditing a staking contract
Example (hypothetical): a team is about to launch a staking contract where users deposit tokens and earn rewards over time. The audit team has three reviewers, and each spends 30 hours on the code, so the review takes 90 hours in total.
The reviewers raise 22 findings: 2 high severity, 6 medium and 14 low. One high-severity finding is a rounding error that lets the first staker claim a larger share of rewards than they deposited. The other is an admin function that any address can call, because the access check was written for the wrong role.
The team takes 5 working days to fix the findings, starting with the two high-severity issues. The reviewers then spend 10 hours retesting the fixes and confirm both high-severity issues are closed and all 6 medium findings are addressed. The 14 low findings are fixed or documented as accepted risks, with a reason written next to each one.
The contract launches with the audit report published and the fixes listed. The arithmetic is simple: 90 hours of review, 22 findings, 5 days of fixes, 10 hours of retesting. The value was not the hours; it was the two flaws that would have cost real money if they had shipped.
What happens after the audit?
After the audit you have a report, a fixed codebase and a decision to make. The report lists findings by severity, and your job is to close the high and medium findings, document the low ones you accept, and publish the report with the fixes noted.
Publishing the report is standard practice. Users and partners expect to read it, and hiding it raises more questions than the findings themselves do. Publish the fixed code too, so anyone can check that the fixes match what the report describes.
Then plan for the next audit. Any change to the contract after launch, from a new feature to a dependency upgrade, can introduce a fresh flaw. Teams that ship often audit often, and they treat the audit as part of the release process rather than a one-off event before launch. The cost side is covered in smart contract audit cost, which explains what drives the price.
How to choose an auditor
Choose an auditor by their track record on contracts like yours, not by price alone. A team that has audited lending protocols may not be the best fit for a token sale contract, and the reverse is also true.
Ask for sample reports and check how the findings are written: clear severity, a description of the attack, and a suggested fix. Ask who will actually do the work, since the senior reviewers on the sales call are not always the people reading your code. Ask how long the retest takes and whether it is included in the price.
Check what the auditor needs from you. A good auditor asks for the specification, the threat model and the test suite before quoting, because those tell them how much work the review really is. An auditor who quotes without asking is guessing. Readiness matters too, and smart contract audit readiness covers how to prepare.
Common mistakes in smart contract audits
The most common audit mistakes are made before the reviewers start. Teams change the code during the review, skip the specification, or treat the report as a marketing asset instead of a work list.
- Auditing code that is still changing, so findings no longer match the shipped code
- No written specification, so reviewers guess what the contract should do
- Leaving dependencies out of scope, so the weakest link is never reviewed
- Skipping the retest, so a fix that introduces a new flaw ships unchecked
- Treating the audit as a guarantee and telling users the contract is safe
- Publishing only the clean summary and hiding the findings
- Waiting until the week before launch, when there is no time to fix anything serious
If you are building contracts and want the audit built into the release process, smart contract development covers how teams plan for it from the start.
Key takeaways
- A smart contract audit is an independent review before launch, not a guarantee of safety.
- Freeze the code and write a specification before reviewers start, or the review wastes time.
- Scope every contract, library and dependency, and run your own checks first.
- Fix findings by severity and always retest the fixes before shipping.
- Publish the report with the fixes noted, and audit again when the code changes.
Frequently asked questions
What does a smart contract audit cost?
It depends on the size and complexity of the codebase, the number of contracts in scope and how much preparation the team has done. A small, well-documented contract costs far less than a large protocol with custom math. Ask auditors for a scoped quote after sharing the code, or see vendor site for current pricing.
How long does a smart contract audit take?
A small audit can take one to two weeks, while a large protocol can take a month or more, including fixes and retesting. Preparation usually takes as long as the review itself, so start the specification and test suite well before you contact an auditor.
Do I need an audit for a small contract?
If the contract will hold real funds or control access to them, yes. Small contracts have caused large losses, because a single flaw in a short contract is easy to miss and easy to exploit. The size of the code is not the measure; the value at risk is.
Can automated tools replace a manual audit?
No. Automated scanners catch known patterns, such as reentrancy and overflow issues, but they miss logic errors, economic attacks and design flaws. A good audit uses tools first, then spends most of its hours on manual reading and attack scenarios.
What is the difference between an audit and a bug bounty?
An audit is a structured review by a hired team before launch, with a report and a retest. A bug bounty invites the public to find flaws after launch in exchange for a reward. They work together: the audit catches what it can, and the bounty keeps watch afterwards.
Should I publish the audit report?
Yes. Publishing the report with the fixes noted is standard practice and builds trust with users and partners. Hiding it raises more questions than the findings themselves, and a report that lists fixed issues is a sign of care, not weakness.