How to prepare a Foundry project for a smart contract audit

Freeze one commit, make forge build and forge test pass from a clean clone, list what is in scope, and write down how the system is meant to behave. Those four steps decide how much of an audit goes into finding bugs instead of working out what the code is for. They apply to a manual audit and to an AI audit alike.

Published . 5 minute read. By the QuillShield team.

QuillAudits has audited 1,500+ protocols since 2018, and it makes QuillShield, an AI security auditor for smart contracts. The same three problems slow down both kinds of audit: code that changes during the review, a build that only works on one laptop, and no written answer to what the contracts should never allow. This checklist fixes them in that order, then covers what changes for an AI audit.

Freeze one commit

An audit reviews one version of the code. Pick a commit, tag it, for example git tag audit-2026-12, and send the auditor that hash. Anything merged after it is code nobody has reviewed, so keep a list of what changes after the tag.

That list matters after the audit too. Nomad's bridge lost about $190M on 1 August 2022 because an earlier routine upgrade had marked the zero hash as a trusted root, which is also the value the contract returns for a message nobody has proven. How to review smart contract changes since your last audit covers what to check when code lands after the tag.

Make it build from a clean clone

Clone the repository into an empty folder, run forge install and then forge build. If the build fails there, it fails for the auditor too, and the first day of the review goes on fixing your setup.

  • Pin the compiler in foundry.toml, for example solc = "0.8.26", so every build uses the version you deploy with.
  • Keep dependencies in lib/ at fixed commits, and commit remappings.txt if you use one.
  • If tests fork a chain, list the variables they read, such as MAINNET_RPC_URL, in a .env.example with no real values in it.

Get the tests green, and show what they cover

forge test should pass on the frozen commit. A failing test either hides a bug or teaches the reader to ignore your tests. Run forge coverage and send the summary, so the auditor knows which lines and branches no test reaches.

Then write the rules that must always hold as invariant tests. Forge calls your contracts' functions in random sequences and checks each invariant after every call. For a token, the classic one is that all balances add up to totalSupply. For a vault, it might be that the vault always holds at least as many assets as its users can withdraw. The Foundry invariant testing guide shows how to write them with handlers.

Write down the scope

List the files in scope, usually everything under src/, and name what is out: tests, deployment scripts, mocks and libraries you use unmodified, such as an OpenZeppelin release. Give the number of lines in scope, because it sets how long the review takes. Add the chains you deploy to and which contracts sit behind a proxy.

Write down how the system should behave

An auditor finds bugs by comparing what the code does with what it should do, so the second half has to be written down somewhere. One page is enough:

  • Actors and roles: who can call what, what an admin can change, whether changes wait behind a timelock, and who holds the keys.
  • External contracts: which oracle feeds you read and what happens when a price is stale, and which tokens you accept.
  • Your rules in plain words, each linked to the invariant test that checks it.
  • Known issues and accepted risks, plus earlier audit reports, so nobody spends time reporting them again.

Token assumptions are a common gap between what a team meant and what its code accepts. Lendf.Me lost about $25M in April 2020 when an attacker used imBTC, an ERC-777 token whose transfers call hooks on the sender and the recipient, to re-enter the protocol in the middle of a deposit. If your contracts should never see a token like that, say so, and enforce it in code.

Clear out what nobody should read

Delete dead code and commented-out blocks. Turn each TODO into an entry on the known-issues list, or remove it. Add NatSpec comments to external and public functions that say what each one is for. Every line left in scope is a line someone has to read.

What changes for an AI audit

Everything above still applies. An AI auditor reads the same code, and its proofs of concept are tests, so they need the project to build.

QuillShield supports Solidity today, for Foundry projects. A full audit takes a GitHub or GitLab.com repository, a git URL, a Foundry .zip of up to 50 MiB, a folder, or a single .sol file. Zip uploads get a full audit and no pull request checks. A separate reviewer agent tries to disprove every finding before you see it. Each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, the proof of concept result.

Run the AI audit before the manual one and fix what it finds, so the auditors can spend their time on design and economics. QuillShield does not replace a manual audit. AI audit vs manual audit sets out what each one is for.

After the audit

Fix each finding in its own commit, so each fix can be checked on its own. Keep every proof of concept in your test suite, changed to assert that the attack now fails. Then review every change you merge after the audited commit.

QuillShield checks every pull request against the last full audit. On GitHub, with branch protection or rulesets, a required QuillShield check blocks a merge while the pull request has a High or Critical finding, or one at the threshold you set. Each full audit comes with five pull request checks, and more can be added. Checks need a GitHub or GitLab.com repo.

What to do next

Run this checklist on your repository, then start a full audit on the frozen commit. Sign-up is free, and new accounts get $50 in credit, good for up to half of an order. Run your first smart contract audit walks through it step by step.

Common questions

What should be frozen before a smart contract audit?

One commit. Tag it, send the hash, and keep a list of every change merged after it, because that code has not been reviewed.

Do tests need to pass before a smart contract audit?

Yes. forge test should pass on the frozen commit, and a summary from forge coverage shows the auditor which lines no test reaches. Invariant tests turn the rules your system must keep into checks that Forge runs after random sequences of calls.

Can QuillShield audit a project that is not on GitHub?

Yes. A full audit also takes a git URL, a Foundry .zip of up to 50 MiB, a folder or a single .sol file. Zip uploads get a full audit and no pull request checks. Pull request checks need a GitHub or GitLab.com repo.

Sources

QuillShield is building the security layer between AI and money, so you can keep shipping between audits.

Sign-up is free, and new accounts get $50 in credit, good for up to half of an order.

  1. 1Sign up and import a repo
  2. 2See the exact price before anything is charged
  3. 3Approve it, and the audit starts