Most AI auditors work like a very fast junior reviewer. They read each function, look for things that seem wrong, and write them up. Sometimes they’re right. Often they flag code that only looks dangerous, and they miss bugs that look perfectly normal.
I wanted something closer to how I actually hunt. So I took an idea from an older corner of security, taint analysis, and built an AI audit method around it. This post covers the core idea, the workflow, and a handful of lessons I’d have liked to know when I started. It’s still research in progress, so I’ll keep some details to myself, but the ideas below are the parts that changed how I audit.
The idea I borrowed
Taint analysis comes from application security. You mark everything an attacker can control as tainted: request parameters, cookies, uploaded files. Then you follow that taint through the program. If tainted data reaches a sensitive sink, such as a database query, a shell command or a file path, without being cleaned on the way, you have a bug.
The power of the idea is that it doesn’t ask “does this line look bad?”. It asks “can the attacker influence what reaches this point?”
Smart contracts are a perfect fit, with a twist. In a web app, taint is mostly binary: user input or not. In DeFi, an attacker can influence a value in many more ways than typing it into calldata. They can move a price with a swap. They can donate tokens to change a balance. They can choose when a value is read, or stop an update from happening at all.
So instead of a single “tainted” flag, my method asks a richer question for every value that matters:
Who can influence this value, and how cheaply?
Classes of influence, not a yes/no flag
Every important value gets a class: the weakest attacker capability that’s enough to influence it. Roughly, from safest to most exposed:
- Fixed. Constants and immutables. Nobody can move these.
- Configured. Set only by a trusted admin. Moving it means compromising that admin.
- Protocol-derived. Computed purely by the protocol from safe inputs.
- Direct. The attacker sets it literally, through a function argument.
- Economic. The attacker moves it with a legal market action, like a swap, a donation or a liquidity change. Often almost free with a flash loan.
- Delegated. It’s decided by code the protocol trusts but doesn’t control: a token, an oracle, an integrated protocol, a callback.
- Timing. The attacker doesn’t set the value but controls when or in what order it’s read: stale prices, reads in the middle of an update, block position.
- Absence. The attacker controls whether an update happens at all, through a forced revert, a skipped accrual or running out of gas.
The rule for finding bugs is simple to say:
Every operation quietly assumes its inputs come from certain classes. A bug is the gap between the class the code assumes and the class the value really has, reachable for less than the attacker gains.
A lending protocol that prices collateral assumes the price is “protocol-derived” or “configured”. If it’s actually “economic”, because it’s a spot price from a thin pool, that’s the bug. A vault assumes its share price is protocol-derived. If anyone can donate to it, it’s economic. The same lens catches oracle bugs, donation attacks, access-control gaps and stale-read bugs, because they’re all the same question.
The workflow
The method runs in stages. Each AI stage runs as a separate process with its own context, for a reason I’ll come back to.
- Mechanical layer, with no AI. Static analysis works out which functions read and write which storage, the call graph, the guards on each path, and a taint pass that traces which caller-supplied inputs reach which stored values. This is the part a model should never have to guess.
- Substrate. The model turns those facts into a shared picture of the protocol: what users give, what claim they get back, what that claim is worth, where profit comes from, and who absorbs a shortfall. It also lists the protocol’s invariants and marks which ones the code actually enforces.
- Interrogations. Several focused hunting passes, each owning one question. One asks whether the recorded total moved when value moved (conservation). One asks who can influence each value and how cheaply (provenance, the taint idea above). Others cover arithmetic and mismatched paired operations.
- Judge. A separate reviewer tries to refute each claim before accepting it.
- Execution. A surviving claim becomes a Foundry test, so the result is something a protocol team can run, not just an argument.
Alpha: lessons from building it
1. “No source found” is not “no source exists”
When the taint pass finds a caller input flowing into a value, that’s strong evidence. Something concrete flows in.
When it finds nothing, that’s weak evidence. More than once my analysis reported a money variable as untouchable because it missed a path through nested mappings, a callee’s parameters or local variables. Every one of those was a false negative on exactly the kind of variable you care about most.
So the method treats the two results differently. A positive result saves you work. A negative result saves you none: it becomes a claim to disprove by reading every writer yourself.
2. “Protocol-derived” is the most dangerous assumption
Code assumes values are protocol-derived far more often than they really are. It’s the class that sounds safest and is most often wrong. So the method doesn’t let anyone, human or model, mark a value as protocol-derived without walking every function that writes it. Because the mechanical layer lists every writer, that walk is bounded and cheap. If it hasn’t been done, the honest answer is “unknown”.
3. Report the cheapest way in
Left alone, everything gets labelled “attacker passes it as an argument” or “attacker moves the price”, because those are the first things you notice. The interesting bugs live in the quieter classes: timing (reading a value mid-update) and absence (making an update never happen). Forcing every value to be labelled with its cheapest class of influence, not the first one you spot, is what surfaces those.
4. Your dataflow must follow calls, not stop at functions
Many writes that matter happen two or three calls below the entry point. A dataflow check scoped to one function will say “no input reaches this”, when in fact it does, through an internal call. Make sure your taint tracking is transitive across internal calls, and test that it still discriminates rather than marking everything as tainted.
5. Compare flows, not just function pairs
Asymmetry bugs, where deposit and withdraw don’t mirror each other, are a classic. Most checklists compare functions by name. But a “flow” is an entry point plus everything it calls, including modifiers. Compare the full set of state each flow touches, and in which direction, and you’ll find state written three calls deep on one side and never touched on the other. A function-by-function comparison can’t see that.
6. The judge must not see the finder’s reasoning
If the judge reads the finder’s explanation, it checks whether the argument is coherent instead of whether the claim is true. A well-written wrong argument passes. So each finding is split into the claim and its argument, and the judge only ever sees the claim. It has to rebuild the reasoning from the source itself.
This only works if the judge really is separate. Running every stage in one long session quietly defeats it, because later stages inherit earlier reasoning.
7. Any output nobody reads is a leak
In an early run, the substrate correctly listed an oracle check as missing. The hunting pass that read it decided, reasonably, that oracles weren’t its job, and moved on. The bug had been found and then thrown away.
The fix wasn’t a smarter model. It was a rule: anything flagged as unenforced becomes a mandatory queue. Every item comes back as a claim, a lead, or an explicit “out of scope, owned by that other pass”. Saying “not mine” is fine. Dropping it silently isn’t. More generally, if a stage produces something no later stage reads, you have a leak.
8. Coverage comes from the bug space, not your design
My first design had passes that matched the shape of my data, not the shape of real bugs. I missed an arithmetic bug because no pass owned arithmetic. Build your coverage list from how real findings are distributed, and have every report say which classes were checked. “We looked and found nothing” and “nothing looked” should never read the same.
9. A test beats an argument
Most AI audit outputs argue exploitability in prose. One stage of my method takes a property the method already states, such as “if every user withdraws in the worst order, is the last one paid in full?”, and runs it as a Foundry test against a prebuilt deployment fixture. Don’t ask the model to set up the protocol from scratch. That’s where it burns its effort. Prebuild the fixture once and let the model write only the attack.
10. “Nothing found” is a valid result
Every stage is allowed to come back empty. A model told to fill a findings template will fill it. Make an empty result an explicit, successful outcome, and cite a file:line for everything else.
How this changed my manual auditing
Even when I audit by hand now, I work the same way. I start by asking, for every number that moves money, who can influence it and how cheaply. I don’t trust “this value is safe” until I’ve read every function that writes it. I keep a queue of open questions I’m not allowed to drop. And I try to refute my own findings before I write them up.
The AI part is still evolving. The taint-analysis mindset is the part I’d recommend to every auditor, with or without a model.