How to review smart contract changes since your last audit

To review a smart contract release that changed after its audit, pin the audited commit and the release commit, diff the files that were in scope and classify every change by what it can break. Then re-check each finding's fix and the report's assumptions, write Foundry invariant and fuzz tests for the changed paths, and use the kind of change to decide between a focused review of the diff and a full re-audit.

Last updated . 11 minute read. By the QuillShield team.

An audit report describes one commit. Code merged after that commit was never part of the audit, and the report's assumptions about roles, tokens and integrations may no longer match the code you deploy. 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. The method below is the review a security engineer runs on such a release before it ships. You need git, Foundry and the audit report, and none of it depends on QuillShield.

What does an audit report cover once the code changes?

It covers the commit it names, the files in its scope and the assumptions it states, and nothing else. A report usually gives the commit hash and the file list in its scope section, along with assumptions such as which roles are trusted and which tokens the protocol accepts. Code added after that commit, files left out of scope, and any role, token or integration the auditors were told the protocol would not use have had no audit review.

How do you review a release that changed after its audit?

Work through these eight steps in order. The sections after the list explain each one.

  1. 1 Pin the audited commit and the release commit. Take the audited hash from the report, check that it is in your release history and tag both commits, so the whole team diffs the same pair.
  2. 2 Diff the files that were in scope. Then list every Solidity file the release adds, deletes or renames, and every change to dependencies and compiler settings, because none of that was audited.
  3. 3 Classify each change as a new entry point, a storage layout change in an upgradeable contract, an accounting or rounding change, a new external call or integration, a change to roles and initialization, or a change to pause and emergency paths. Comments, renames and other edits that change no behavior go in a separate pile you skim.
  4. 4 Re-check each finding's fix by confirming that every fix the report accepted is still in the release commit and that no new path reaches the same state another way.
  5. 5 Re-check the report's assumptions, and mark every trusted role, token type, oracle and chain the report assumed that the release no longer matches.
  6. 6 Test the changed paths with Foundry invariant and fuzz tests for each class of change you found in step 3.
  7. 7 Choose between a focused review of the diff and a full re-audit, using the criteria below, and write the decision down with the reason.
  8. 8 Keep every later pull request checked, so the next release starts from reviewed code.

How do you pin the audited commit and the release commit?

Use the commit hash printed in the audit report, not a branch name or a tag that someone can move. Then check that the audited commit is an ancestor of the commit you plan to deploy.

git fetch origin --tags
git tag audited <hash from the audit report>
git tag release <commit you plan to deploy>
git merge-base --is-ancestor audited release && echo "audited commit is in the release history"
git log --oneline audited..release -- src/

The last command lists every commit that touched src/ since the audit. If the ancestor check prints nothing, the history was rebased or squashed after the audit. A diff between the two commits still compares the code, but the commit log no longer tells you what changed, so rely on the diff. If the new implementation is already deployed and waiting for an upgrade transaction, check that its bytecode matches the release commit, for example with forge verify-bytecode, so the code you review is the code the upgrade will point to.

How do you diff only the files that were in scope?

Copy the file list from the report's scope table into audit-scope.txt, one path per line, and diff those paths first. Then check the whole tree for code the scope never covered.

git diff --stat audited release -- $(cat audit-scope.txt)
git diff audited release -- $(cat audit-scope.txt) > in-scope.diff
git diff --name-status audited release -- '*.sol'
git diff audited release -- foundry.toml remappings.txt lib/

In the --name-status output, A marks a file added since the audit and R a renamed one. Treat every added file as unaudited code, however small it is. The last command catches dependency bumps and compiler settings, because a new library version, compiler version, evm_version or optimizer setting changes the bytecode you deploy without touching your own files.

Which changes need the closest review?

Read the in-scope diff hunk by hunk and give each change one or more of the classes below. Judge each change by what it touches, because a one-line change can carry the most risk in a release.

New entry points

List every external and public function the release adds, functions that used to be internal, new receive and fallback functions, and new callbacks such as onERC721Received or a flash loan callback. For each one, check who can call it, what state it changes and whether it skips a check that the existing paths run. Euler Finance added donateToReserves in a later improvement proposal, eIP-14, and the function did not check the health of the account making the donation. On 13 March 2023 an attacker used it to drain about $197M.

Storage layout in upgradeable contracts

In a contract behind a proxy, new state variables go after the existing ones, into a namespace as ERC-7201 describes, or into a __gap that shrinks by the same number of slots. No existing variable may change type or order, and no base contract may be inserted before an existing one, because that shifts every slot after it. The loop below compares the storage layout and the function selectors of a contract at both commits.

git worktree add ../audited audited
git -C ../audited submodule update --init --recursive
for view in methodIdentifiers storageLayout; do
  (cd ../audited && forge inspect Vault $view) > before-$view.txt
  forge inspect Vault $view > after-$view.txt
  diff before-$view.txt after-$view.txt
done

Replace Vault with each contract in scope. A new line in the selector diff is a new entry point. In the layout diff, any existing variable whose slot or offset moved will read the wrong data after the upgrade. OpenZeppelin's upgrades plugins run the same layout check with validateUpgrade.

Accounting and rounding

Read every change to share math, fees, interest, exchange rates, decimals and the order of multiplication and division. Check the rounding direction on each conversion. ERC-4626 says a vault should round in its own favor on deposit, mint, withdraw and redeem, and new share math should follow the same rule. Then work the new formula through with an empty vault and with a pool that holds one wei, because first depositor and donation cases break share math that looks right for normal balances. Uranium Finance changed the fee constant in its swap function from Uniswap V2's 1,000 to 10,000 but left the constant product check at 1,000, and on 28 April 2021 an attacker used the mismatch to take over $50M across 26 pairs.

New external calls and integrations

Every new call to another contract trusts that contract. For an oracle, check the staleness limit, the decimals, what happens when the feed returns zero or reverts, and whether trades in one block can move the price, as they can for a spot price read from a single pool. For tokens, check whether the release now accepts tokens that call back into your contract during a transfer, such as ERC-777 tokens, tokens that charge a fee on transfer and tokens whose balances rebase. Then check that each function updates its state before the external call or holds a reentrancy guard. 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.

Roles and initialization

List every new role, every changed modifier and every function whose access check moved. Check who holds each role at deployment, who can grant it, and whether a role the report treated as trusted can now reach code it could not reach before. For each new implementation, check that the initializer runs once, in the same transaction as the deployment or the upgrade, with the values you meant to pass. The implementation contract itself should not be open to initialization, which _disableInitializers() in its constructor prevents. Nomad's loss, described at the top of this guide, came from one value passed during an upgrade.

Pause and emergency paths

Check what the release adds to the pause logic and what it removes. Each new function that moves funds should either stop when the protocol is paused, for example with OpenZeppelin's whenNotPaused modifier, or stay open on purpose as an exit such as withdraw or repay, and the choice should match what the report assumed. Check who can pause and unpause, whether a timelock now sits in front of the pause, and how long a fix would take to reach the chain if the new code has a bug, counting any governance delay.

How do you re-check the audit's findings and assumptions?

Make a table with one row per finding: its ID, the status in the report (fixed, acknowledged or disputed), the commit that fixed it and whether the release still has that fix. A refactor can drop a fix without anyone noticing, and a new function can reach the protected state by another route. If the report included a proof of concept for a finding, run it against the release commit. For acknowledged findings, check whether the release makes them worse, for example a small rounding loss that a new fee now applies on every transfer.

Then list every assumption the report states and check it against the release. Common ones are that owner and admin roles are trusted, that only standard ERC-20 tokens are listed, that the oracle is fresh and honest, and that the code runs on one named chain. If the release gives a new role privileged access, accepts a token with hooks or fees, swaps an oracle or adds a chain, the report's conclusions about that code no longer apply, and step 7 has to account for it.

Which Foundry tests should cover the changed paths?

Write tests that state what must stay true, and let Foundry search for call sequences that break it. Start from the invariants the protocol already depends on and add at least one for each class of change from step 3. For a vault, two good first tests are an invariant that all holders together can never redeem more than the vault holds, and a fuzz test that a deposit followed by a redeem never returns more than went in.

// test/invariant/VaultInvariant.t.sol, for a vault that holds its assets (handler not shown)
function invariant_holdersCannotRedeemMoreThanVaultHolds() public view {
    uint256 owed;
    for (uint256 i; i < handler.actorCount(); i++) {
        owed += vault.previewRedeem(vault.balanceOf(handler.actors(i)));
    }
    assertLe(owed, asset.balanceOf(address(vault)));
}

// test/VaultFuzz.t.sol
function testFuzz_depositThenRedeemNeverProfits(uint256 assets) public {
    assets = bound(assets, 1, 1e30);
    deal(address(asset), alice, assets);
    vm.startPrank(alice);
    asset.approve(address(vault), assets);
    uint256 shares = vault.deposit(assets, alice);
    uint256 back = vault.redeem(shares, alice, alice);
    vm.stopPrank();
    assertLe(back, assets);
}

Keep the audited commit's tests passing on the new code, and read the diff of test/ as closely as the diff of src/, because a deleted test or a loosened assertion is also a change. For a new integration, run the tests on a fork of the chain you deploy to with forge test --fork-url $RPC_URL, so the oracle and the token behave as they do in production. When Foundry finds a failing sequence, turn it into a plain unit test so the fix stays covered.

Do you need a focused review of the diff or a full re-audit?

A focused review of the diff, ideally by the auditors who wrote the report, is enough when all of these hold.

  • Every change sits in files the audit covered, and the release adds no contract and no external dependency.
  • Storage layout is unchanged, or new variables are only appended or placed in a namespace.
  • Every assumption in the report still holds, with the same trusted roles, token types, oracles and chains.
  • Each change can be judged from the code around it, such as a new check, a fixed branch or a new event.
  • Every finding's fix is still in place.

Plan a full re-audit, at least of the contracts involved and the code that calls them, when any of these is true.

  • The release adds a contract, or an entry point that moves funds or changes accounting.
  • Core accounting changed, such as share math, interest, fees, liquidation or the way prices are read.
  • The release adds an integration, such as an oracle, a bridge or a DEX, or a new kind of token, such as tokens with hooks, fees on transfer or rebasing balances.
  • Storage layout changed in any way other than appending, or the proxy or upgrade pattern changed.
  • An assumption in the report no longer holds.
  • A core function was rewritten end to end, for example a new liquidate or a new share price formula, so the auditors' earlier reasoning about it no longer applies.

When one contract crosses these lines and the rest of the diff does not, re-audit that contract with its callers and give the rest a focused review. Write the decision down with the commit pair, the files and the reason, so the next review knows what this one covered.

How do you keep every later pull request checked?

Once the release ships, its commit is the new reviewed baseline. Review every pull request into the release branch against it, so the diff at the next release is made of changes someone has already reviewed. On GitHub, a CODEOWNERS entry that names your security reviewers for src/, with code owner review required in branch protection, puts one of them on every change to contract code. Make the Foundry tests, including the invariant tests, a required check. For each upgradeable contract, commit the output of forge inspect <Contract> storageLayout, regenerate it in CI and fail the job when it differs, so no layout change merges without a reviewer seeing it.

Where QuillShield fits

QuillShield is an AI security auditor for smart contracts. It runs a full audit of a Solidity codebase, builds a security graph and tests its findings with proofs of concept, then checks every pull request against that graph. In this method, a full QuillShield audit of the release commit gives you a second review of the whole codebase before the decision in step 7, and its pull request checks cover step 8. 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. How to add smart contract security checks to CI on GitHub has the setup.

QuillShield does not replace a manual audit. It reviews every change between audits, and you can request a manual audit from QuillAudits. It supports Solidity today, for Foundry projects. Sign-up is free, and you see the exact price before anything is charged. Start now to audit your release commit, or talk to an auditor if your diff meets the re-audit criteria above.

Common questions

Is an audit still valid after the code changes?

For code that is unchanged and still runs under the report's assumptions, yes. For any changed line, any new file and any broken assumption, the report says nothing, so that code needs its own review before it ships.

Does a small change after an audit need a new audit?

Only when it changes what the audit relied on. A change inside audited files that keeps the storage layout, the roles, the integrations and the report's assumptions the same can get a focused review of the diff. A new contract, a new integration, changed accounting or a broken assumption needs a full re-audit of at least the code involved.

How do you find the commit that was audited?

The audit report names it, usually in the scope section, as a full or short git hash. Use that hash and not a branch name, and check that it is an ancestor of your release commit with git merge-base --is-ancestor.

Can an AI auditor review the changes between manual audits?

An AI auditor can review them, and QuillShield does. It runs a full audit of a Solidity codebase, builds a security graph and tests its findings with proofs of concept, then checks every pull request against that graph. QuillShield does not replace a manual audit. It reviews every change between audits, and you can request a manual audit from QuillAudits.

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