Oct 27, 20268 min read

The DeFi audit is there. Is it the code we're actually using?

An audit covers a particular version of the code. Does it match the contracts and strategy currently handling your deposit?

JohnnyTimeFounder, Ginger Security

Suppose your team is ready to deposit into a DeFi vault. You have the audit PDF, the contract address and a link to the verified source code.

The address is a proxy, and the strategy that handles withdrawals was changed recently.

Now I have a different question: does the audit describe the code that will actually handle this money today?

Before a fund or trading team relies on that report, I’d match its reviewed revision to the active deployment. The vault and its separate strategy both belong in that comparison.

In the due-diligence article, we met Cedar Vault. The vault code matched the reviewed deployment, but a new strategy withdrawal path had no review coverage. Here I’ll show how I’d follow the trail to reach that conclusion, and what I’d ask for before treating the gap as closed.

The local Cedar demo below recreates that mismatch. Its audit scope is assumed for the exercise.

What did the report actually cover?

I want the repository and commit, the files and contracts the reviewers examined, and any exclusions, time limits or assumptions. For Cedar, I’d check whether the engagement included the vault, proxy, strategy and withdrawal path. If fixes were made, I’d also check whether the reviewers examined the fixed revision.

I’d record the full commit hash, repository, report version, scope and any follow-up review. Then I’d get the exact source at that commit, including pinned dependencies, and compare it with the source used for the deployment. If the report only lists a branch or a short identifier that can’t be resolved unambiguously, I’d ask for the full revision and supporting records.

Then find out what the proxy is running

A proxy is an address users interact with that delegates execution to another contract, called the implementation. The proxy can keep its address and storage while its implementation changes.

For a proxy that follows ERC-1967, the implementation address is usually stored in a standard slot. Using Foundry’s Cast, I can inspect it and fetch its runtime bytecode:

cast chain-id --rpc-url "$RPC_URL"
cast block-number --rpc-url "$RPC_URL"
cast implementation "$PROXY" --block "$BLOCK" --rpc-url "$RPC_URL"
cast code "$IMPLEMENTATION" --block "$BLOCK" --rpc-url "$RPC_URL"

I’d independently confirm the chain and proxy address, record the block number and block hash, and use the same block for related reads. If the RPC supports it, use a finalized block suitable for the decision. I’d cross-check material reads with another trusted node.

Not every proxy uses ERC-1967. A beacon proxy needs the beacon resolved to its implementation. Other designs can route calls differently. A blank or unexpected slot calls for a closer look at the proxy code and its upgrade paths. The explorer’s proxy label is a useful starting point.

Can I reproduce the code on-chain?

Once I know the implementation, I compare its deployed runtime bytecode with the result of compiling the relevant source. Runtime bytecode is the code stored at the contract address. It is different from the creation bytecode used to deploy it.

For a meaningful comparison I need the exact source and dependencies, compiler version, optimizer settings, EVM target and metadata settings. Linked libraries can change the result too, so I need their actual addresses and the code at those addresses. Solidity’s metadata documentation explains how source references and build settings support reproducible verification.

There is a wrinkle: constructor-set immutables can be embedded in deployed runtime code. The compiler artifact may contain placeholders before deployment, so a raw comparison against that template can fail even when the correct source was used. I’d account for the deployed immutable values and library links using the deployment records and a verification tool that handles them, then examine any remaining difference. I wouldn’t simply strip unexplained bytes until a comparison passes.

Explorer verification and Sourcify can help establish a source-to-bytecode match. I’d inspect whether the result is an exact match or a more limited match and what was actually compared. A mismatch can come from build inputs, metadata, libraries or immutables. It can also mean we have the wrong source. Until it’s explained, the link remains open.

The vault matches. What about the strategy?

The vault implementation matches the reviewed code. Its storage points to a separate strategy contract. The strategy’s code determines where and how assets can move on withdrawal.

I’d read the strategy address through the proxy at the same block, using the actual contract’s ABI and getter. For a contract with a strategy() getter, the shape is:

cast call "$PROXY" 'strategy()(address)' --block "$BLOCK" --rpc-url "$RPC_URL"
cast code "$STRATEGY" --block "$BLOCK" --rpc-url "$RPC_URL"

Then I’d identify whether the strategy is itself a proxy, resolve it if necessary, and compare its deployed code with its own build and the report’s scope. I’d also inspect the vault’s relevant configuration: strategy, asset, withdrawal destination or pool, privileged roles and upgrade controls. The exact getters and storage layout depend on the contracts. Read state through the proxy where the live application keeps its state. The implementation’s own storage can return different values.

Try it locally

I built a small downloadable Foundry demo to make the difference visible. It deploys a vault implementation, a proxy and two strategies into a temporary local EVM. The vault and original strategy are designated as reviewed. The changed strategy is outside that scope.

Unzip it, open the extracted folder and run:

forge test -vvvv

The trace emits the proxy, active implementation, configured strategy and original strategy, plus their code hashes. The test reads the ERC-1967 slot, confirms the active vault runtime matches its locally compiled runtime, and confirms the configured strategy matches the changed build but differs from the original. It also checks the changed strategy’s example withdrawal destination.

The demo contains no linked libraries or immutables and doesn’t implement asset transfers or production access controls. Keep funds away from this teaching code. Build settings are in the README.

Once the team has mapped the deployment, the DeFi monitoring article shows how I would watch for changes that could affect the decision.

Where tools and AI agents help

I’d use Git to check out the reported commit and inspect changes, Foundry to build and test, and Cast to query code, storage and configuration. An explorer or Sourcify can provide source and verification artifacts. I’d check them against the specific chain, address, block and scope of the decision.

An AI agent can speed up the investigation: extract candidate scope and commit references from the report, build a dependency map, summarize a diff, propose Cast commands and assemble a table of sources and results. I would give it the actual documents and read-only access, then check its claims against the report, source and raw chain results. An agent can miss an exclusion, mistake a proxy for an implementation or invent a link between two revisions.

For stronger assurance about a particular on-chain storage value, an RPC can provide an account and storage proof, for example with Cast’s proof command. The proof must be verified against a trusted block header’s state root. Receiving a proof and a header from the same untrusted RPC leaves that trust problem unresolved. A proof of the implementation slot establishes its value at that block. Audit coverage, safe behavior and future state each need separate checks.

What changes after today?

A proxy upgrade, strategy replacement, configuration change or dependency upgrade can invalidate the conclusion without changing the vault address. I’d record the chain, block, addresses, code hashes, build inputs, report and scope, relevant state, unresolved gaps and owner of the decision. Then I’d monitor the important changes and reopen the review when they occur.

If you’d like help tracing an audit to the contracts and configuration your team actually uses, we can discuss it through my ongoing security advisory service.