How to Audit a Smart Contract, Step by Step
A smart contract audit is a step-by-step security review that finds bugs before funds are at risk. This guide covers scoping, tools, manual review and reporting.
On this page
Short answer
To audit a smart contract, freeze the code, define the scope and threat model, run static analysis and fuzzing tools, review the code line by line against known attack patterns, test fixes, and write a report that lists each issue by severity. A good audit combines automated tools with manual review, because tools catch known patterns while people catch logic errors.
What is a smart contract audit?
A smart contract audit is a structured security review of the code that controls funds or assets on a blockchain. Auditors read the code, test it against known attack patterns, and check the business logic for errors that could lock or drain funds.
The result of an audit is a written report. Each issue is listed with a severity rating, a description of what could go wrong, and a suggested fix. The report also states what was in scope and what was not checked, so readers know the limits of the review.
An audit is not the same as a code review by a colleague. A code review checks style, clarity and correctness in general. An audit is adversarial: the reviewer assumes an attacker will try every entry point, every edge case and every interaction with other contracts. You can read more about what the review covers in a smart contract audit explainer.
What should you audit first?
You should audit the contracts that hold funds, control access or can be upgraded first, because those are the places where a bug costs the most. Start by listing every contract in the system and marking which ones touch money, permissions or external calls.
Scope matters more than size. A small token contract that holds user deposits deserves more attention than a large contract that only stores public settings. Map the flow of funds through the system: where money enters, where it is stored, who can move it, and where it leaves.
Write the scope down before the review starts. A short scope document lists the contracts, the commit hash of the frozen code, the known risks the team already worries about, and anything deliberately out of scope. Without a frozen commit, fixes made during the audit can quietly introduce new bugs that nobody re-checks.
How do you audit a smart contract, step by step?
A smart contract audit follows a fixed sequence, so nothing important is skipped. The steps below work for a single contract or a whole protocol, and they apply whether the audit is done by an outside firm or by an internal team.
- Freeze the code and agree the scope. Pick one commit, list the contracts in scope, and write down the threat model: who the attackers are and what they could gain.
- Read the documentation. Read the design notes, the intended behaviour of each function, and any past audit reports. If the intended behaviour is not written down, ask the developers before reading code.
- Run static analysis tools. Run the tools over the frozen code and triage every finding. Tools catch known patterns fast, and the triage step separates real issues from noise.
- Review the code line by line. Read each function with the threat model in mind, checking entry points, access control, arithmetic and interactions with other contracts.
- Write tests for suspected bugs. When a line looks wrong, write a test that proves it. A failing test turns a suspicion into a confirmed finding.
- Verify the fixes. After the developers fix each issue, re-check the changed code. A fix can close one hole and open another, so fixes need their own review.
- Write the report. List each issue by severity, explain the impact in plain language, and record what was checked and what was left out.
The order matters. Running tools before reading the docs wastes time on findings that do not apply, and writing the report before verifying fixes means the report describes code that no longer exists.
Which audit tools should you use?
Audit tools fall into four groups, and a serious audit uses at least one from each. No single tool finds every class of bug, so the tools are a starting point for the manual review, not a replacement for it.
| Tool type | What it does | What it misses |
|---|---|---|
| Static analysis (Slither) | Reads the code without running it and flags known patterns such as reentrancy and unchecked calls | Business logic errors and design flaws |
| Symbolic execution (Mythril) | Explores many execution paths to find states that break the contract | Issues that need real-world context, such as bad prices |
| Fuzzing (Echidna) | Throws random inputs at the contract to break properties you define | Bugs in properties you did not think to define |
| Unit and invariant tests (Foundry, Hardhat) | Prove that specific behaviours hold under the cases you write | Any case you did not write a test for |
Start with static analysis because it is fast and cheap to run. Then use fuzzing on the functions that move funds, since random inputs often find edge cases that hand-written tests miss. Keep the tool output in the audit record, so the team can see which findings were confirmed and which were dismissed. A list of tools used in real audits is in this comparison of smart contract audit tools.
What does a manual review look for?
A manual review looks for the bugs that tools cannot see, mostly in the logic of the contract rather than its syntax. The reviewer works through the same checks on every contract, so the review is systematic instead of a matter of luck.
- Reentrancy. Can an outside contract call back into this one before the first call finishes, and withdraw more than it is owed?
- Access control. Can anyone call a function that should be restricted to an owner or a specific role? Are there functions with no access check at all?
- Arithmetic and rounding. Do divisions round in the attacker's favour? Can a tiny deposit or a huge withdrawal break the maths?
- Oracle and price use. Does the contract trust a price feed that can be moved by a single trade? What happens if the feed stops updating?
- Upgrade and proxy risk. Who can upgrade the contract, and what happens to stored funds and state if the new code is wrong?
- Centralisation. Does one key control the funds, the pause switch or the fee settings? What happens if that key is lost or stolen?
For each check, the reviewer writes down the answer and the evidence: the line numbers, the test that proves it, or the reason it does not apply. That record is what makes the audit repeatable. If your team needs outside help with the review, a smart contract audit service can run the full process.
Example (hypothetical): auditing a rewards contract
Example (hypothetical): a rewards contract holds 100 tokens for 10 users, each owed 10 tokens. Users call a withdraw function that sends their tokens and then marks their balance as zero.
The auditor reads the withdraw function and sees that the token transfer happens before the balance is set to zero. That ordering is the classic reentrancy pattern: an attacker's contract can call withdraw again while the first call is still running, because the balance still shows 10 tokens.
The auditor writes a test to prove it. One user withdraws 10 tokens, re-enters, and withdraws 10 more, taking 20 tokens in total. That leaves 80 tokens for the other 9 users, who are owed 9 x 10 = 90 tokens, so the contract is 90 - 80 = 10 tokens short and the last user cannot be paid in full.
The fix is to set the balance to zero before sending the tokens, and to add a reentrancy guard. The auditor then re-runs the test to confirm that a second withdrawal in the same call now fails, and records the finding in the report as a high-severity issue with the fix verified.
What are the common mistakes?
The most common audit mistakes are not technical. They are process mistakes: starting before the code is frozen, trusting tools too much, and treating the report as a guarantee.
- Auditing code that keeps changing. If developers push fixes during the audit, the report describes code that no longer exists. Freeze the commit first.
- Skipping the threat model. Without a written list of attackers and assets, the review drifts into style comments and misses the dangerous paths.
- Trusting tools alone. Tools find known patterns. They do not understand what the contract is supposed to do, so logic errors pass straight through them.
- Not verifying fixes. A fix that is never re-checked can introduce a new bug. Every fix needs its own short review.
- Ignoring upgrade logic. Proxy and admin functions are often the most powerful code in the system, and they are easy to leave out of scope.
- Treating the report as a guarantee. An audit reduces risk; it does not remove it. A clean report means no issues were found in scope, not that none exist.
Key takeaways
- A smart contract audit is an adversarial review, not a general code review
- Freeze the code and write the scope and threat model before the review starts
- Use static analysis, symbolic execution, fuzzing and unit tests together, not one alone
- Manual review checks reentrancy, access control, rounding, oracles, upgrades and centralisation
- Every fix needs its own re-check, and the report must state what was out of scope
Frequently asked questions
How long does a smart contract audit take?
It depends on size and complexity. A single token contract often takes one to two weeks, while a protocol with several interacting contracts can take a month or more. Preparation time, such as writing docs and freezing code, is part of the schedule.
How much does a smart contract audit cost?
Cost depends on the size of the code, the complexity of the logic and who does the audit. Firms usually quote after reading the code, so ask for a quote based on a frozen commit and a written scope. See the guide to smart contract audit cost for the factors that move the price.
Can I audit my own smart contract?
You can run tools and review your own code, and you should, but a self-review is not a substitute for an independent audit. The developers who wrote the code share its blind spots, so an outside reviewer is more likely to question the assumptions.
What is the difference between an audit and a penetration test?
An audit reviews the contract code itself for logic and security flaws. A penetration test probes the running system, including the front end, the servers and the deployment, for ways an attacker could get in. Most teams need both.
Do I need an audit before launching?
Yes, if the contract will hold user funds or control valuable assets. An audit before launch is far cheaper than fixing a bug after funds are at risk, and many exchanges and partners ask for an audit report before they list or integrate a project.
What happens after the audit report is published?
The team fixes the issues, the auditor verifies the fixes, and a final report is published with the fixes confirmed. Any issue the team chooses not to fix should be recorded as an accepted risk, so users and partners can see the decision.