Cover photo

A passing PoC is not a proof

forge test tells you the code did what your harness told it to. It does not tell you an attacker could have done it. I turned the privilege audit I used to run by hand into a static checker for Foundry tests, ran it over 886 reproductions of real exploits, and read every finding it raised. This is how it works, what it found, and where it is wrong.

A few weeks ago I wrote about the PoC that lied to me. The mechanism was real, the test was green, and the impact was something the harness had manufactured: the attacker's write and the protocol's read ran inside one transaction that, on chain, only the operator could sign. I ended that article with a checklist I now run before any write-up. Senders, transaction boundaries, privilege, state, assertions.

Checklists have a known failure mode. You run them carefully on the first ten PoCs and skim them on the eleventh, which is the one that matters. Most of that checklist is about things that are written in the test: a vm.prank with an admin's name in it, a deal into the vault, an assertion whose right-hand side is zero. If it is written in the test, a program can read it.

So I built one. It is called realism-gate, it is open source, and it answers a single question about a Foundry PoC: does this test show what an unprivileged attacker can do, or only what the harness made true?

realism-gate check test/

This article is the long version: the patterns it looks for and why each one sinks a report, why a regex could not do this, how the tool rebuilds what a test actually does, what happened when I pointed it at a public corpus of real exploit reproductions, and the places where it is wrong.


The ways a green test lies

None of these patterns is exotic. Every one of them passes locally, and every one of them is something a triager reads in the first minute.

The exploit step runs as somebody else. The test needs the vault configured a certain way, so it does vm.prank(admin); vault.setWithdrawalFee(0); in the middle of the attack, and then the attacker drains it. The test is green. What it proved is that an admin can set a fee to zero. A step that runs as a privileged address is a step the attacker cannot sign, and unless the report argues why the attacker can rely on that role acting, the whole finding is a privileged-role finding, which most programs exclude.

The attacker is the deployer. This is the honest version of the same mistake, and I think it is the most common one. setUp() does vault = new Vault();. The test then calls vault.sweep(token) from the test contract, without ever changing sender. The test contract deployed the vault, and constructors commonly hand the deployer ownership or every role. The test proved that the owner can sweep. Whether anyone else can is untested.

The donation is not a donation. Inflation and donation attacks need tokens to arrive in a contract without going through its accounting. The shortcut is deal(address(token), address(vault), 1_000e18). But deal does not transfer anything. It overwrites a storage slot. Pointed at a protocol contract it does two wrong things at once: it creates value nobody paid for, and it erases whatever balance the vault already had. A donation attack demonstrated with deal has not demonstrated a donation attack.

The broken state is written, not reached. vm.store(address(lender), slot, 0) clears a debt. vm.etch(oracle, staleOracleCode) replaces a dependency. vm.mockCall(oracle, price.selector, abi.encode(1)) makes the price whatever the test wants. Each of these is a legitimate tool for unit testing and an assumption in a PoC. If the impact flows through that slot, that code or that return value, the test shows what happens if the state were broken, not that an attacker can break it.

The assertion cannot fail. Sometimes there is no assertion at all, only a log line with the attacker's balance and a reader expected to trust it. Sometimes there is one, and it is assertEq(stolen, 100e18) two lines after uint256 stolen = 100e18. A check of the test's own arithmetic passes no matter what the protocol did.

The gain has no baseline. assertGt(token.balanceOf(attacker), 0) reads like proof of profit. It passes if the attacker already had tokens, from deal in setUp(), from a fork where that address already holds funds, or from a transfer three helpers away. A gain is a difference. Without the before-value, the test cannot tell the exploit's effect from the starting state, and neither can the reader.

The fork floats. vm.createSelectFork(rpcUrl) with no block number runs against the chain as it is the day someone runs it. Balances move, parameters get changed, bugs get patched. A PoC that only reproduces on the day it was written is a PoC the triager has to take on trust.

Two transactions are written as one. This is the one from my earlier article, and it is the subtlest. The test wraps the victim's action and the attacker's action in a single vm.startPrank block, or puts the attacker's step inside a callback that only the victim's transaction would trigger, and the result depends on both happening atomically. On the EVM a transaction has one sender. Nobody can append a call to a transaction somebody else signed.


Why a regex cannot do this

The obvious first version is a grep. Search the test for vm.prank(admin, vm.store, deal(. My private pipeline had exactly that for a while, as a list of "privilege idioms" a harness had to declare. It was better than nothing, and it was wrong in both directions.

It missed things, because the privileged address is rarely called admin at the call site. It is owner, and owner was assigned from vault.owner() in setUp(), or it is keeper, and the keeper got its role through grantRole in a base contract in another file. The prank that matters is often inside _attack(), three helpers down, or inside an onFlashLoan callback the protocol calls back into.

And it fired on things it should not. vm.prank(admin) in setUp() is configuration, which is fine. The same line in the test body is an exploit step, which is not. deal(token, attacker, 1e18) is funding, which is fine. deal(token, vault, 1e18) is injection. vm.prank(whale) is a perfectly ordinary way to borrow a real holder's tokens. A grep cannot tell any of these apart, because the difference is not in the line. It is in when the line runs, who it names, and what that name was assigned from.

So the tool has to do what a careful reviewer does: reconstruct the test's execution, then judge each line in context.


How it rebuilds a test

realism-gate never runs anything. There is no compilation, no forge, no RPC. It reads the Solidity and works in five stages.

1. Parse with a real parser. It uses solar, the Solidity parser written for the Foundry toolchain. Each file is parsed into an AST and then lowered into a small owned model: contracts, state variables, functions, modifiers, statements and expressions, each with its source text and line. A file that does not parse cleanly is not thrown away; the parser recovers, and whatever it recovered is checked, with the file listed in the report.

2. Resolve the suite. A suite is a concrete contract with a public test* function. Its bases are resolved by name, preferring a definition in the same file, which matters for PoC collections where hundreds of files define a contract with the same name. The inheritance is linearized depth-first, most-derived first, which is enough to find the right setUp, resolve super.setUp(), and find helpers and modifiers defined in a base test.

3. Build the trace. For each test, the tool lays out what runs, in order:

state initializers and constructors     (base to derived)
setUp()                                  (super.setUp() followed)
modifiers ─┐
           └─ test body                  (helpers inlined at the call site)
callbacks                                (onFlashLoan, receive, fallback, ...)

Modifiers wrap the body the way Solidity runs them: the modifier's statements before _; run first, then the rest of the chain, then the statements after. Internal helpers are inlined where they are called, up to eight deep, with recursion cut. Inside each statement, expressions are visited in evaluation order, so in vault.withdraw(token.balanceOf(me)) the read comes before the withdrawal. Every call gets a class: cheatcode, forge-std helper, assertion, log, builtin, cast, internal, external, or deployment.

4. Replay the senders. The trace is replayed to work out who sends each external call and deployment. vm.prank switches the sender for the next call, vm.startPrank until it is stopped, hoax and startHoax likewise, and each phase starts as the test contract, which is how Foundry runs setUp(), the test, and a callback the protocol triggers. After this step the tool can answer the question the grep could not: this withdrawal was sent by admin, this sweep was sent by the test contract that deployed the vault.

5. Decide who is who. This is the part that is a heuristic, and it says so. Each address is classified as attacker, privileged, user, mock, helper or protocol, from evidence in the test:

  • a role word in its name or makeAddr label: owner, admin, governance, keeper, guardian, minter, and so on (tokenOwner and nftOwner are users, not roles);

  • what it was assigned from: address owner = vault.owner() makes owner privileged wherever it is used;

  • what the harness did to it: an address passed to grantRole, transferOwnership or setOperator holds a role from that line on;

  • how it was made: makeAddr("alice") and address(uint160(1)) are accounts, new Vault() is a protocol contract, and a contract defined in the test's own file is the PoC's own helper.

It cannot read the deployed contract's access control. It reads what the test says about it. When that is wrong, a declaration file (below) overrides it.

Only then do the rules run, and they are graded by phase. A cheat in setUp() is usually configuration and is reported one level lower than the same cheat in the exploit. A finding on a setUp() line shared by twenty tests is reported once, listing all twenty.


The rules

There are fourteen. Eleven read the code; three read a declaration.

Rule

Fires when

RG01

error

the harness grants the attacker a role, or the attacker is a privileged address

RG02

warn

the exploit body runs a step as a privileged address or as a protocol contract

RG03

warn

the test deploys the protocol and attacks it as the deployer

RG04

error

vm.store writes a slot of a contract under review

RG05

error

vm.etch or deployCodeTo replaces a dependency's code

RG06

error

deal writes a protocol contract's balance

RG07

warn

vm.mockCall makes a dependency return a value it would not

RG08

error

the test asserts nothing (warn if it only logs)

RG09

error

an assertion compares constants, or an expression with itself

RG10

warn

a gain is asserted on a value read only after the attack

RG11

warn

a fork has no block number

RG12

error

an attacker step is declared inside the victim's transaction

RG13

warn

a same-block step names no ordering mechanism

RG14

note

the attack depends on a victim, a role or a third party acting

A few of them needed more care than the table suggests.

RG01 looks at who makes the grant. An unprotected transferOwnership that the attacker calls on themselves is not a harness shortcut; it is the bug. So RG01 fires only when the grant is made by someone with the power to grant: a privileged address the test pranks as, a protocol contract it impersonates, or the test contract on a contract it deployed itself.

RG04 checks whose slot it is. vm.store into a token's balance mapping keyed by the attacker is funding, the manual version of deal for tokens deal cannot handle. The rule follows the slot expression back through the local it was computed into, and when it names the attacker or a user, it reports one level lower and says why.

RG10 only judges directional claims. An exact assertion, assertEq(balance, 1_250_000e6), would break on a pre-existing balance, so it does not need a baseline. Neither does "drained to zero". A require in a test is almost always a precondition guard. What RG10 looks for is "more than" and "less than" claims whose every measurement is read once, after the exploit has changed something. It treats a call written inside an assertion or a log as a read, and a contract the harness deployed as starting from zero.

RG12 is one sentence of chain semantics. On the EVM a transaction has one sender. A declaration that says the attacker performs a step with boundary: victim_transaction is describing something the chain cannot produce. The rule exists because I once submitted exactly that.

Every rule has a page that says why it exists, shows a test it fires on and a sound test it must not fire on, and lists the ways it is known to be wrong. The pages, realism-gate explain and the SARIF rule table are generated from one catalog in the code, and a test fails if they drift apart.


Here is what it says

This is a deliberately bad PoC, the kind that passes forge test and still fails triage:

function setUp() public {
    vm.createSelectFork(vm.envString("RPC_URL"));
    vault = new Vault(admin, address(token));
    deal(address(token), attacker, 10e18);
}

function test_attackerDrainsVault() public {
    vm.prank(admin);
    vault.setWithdrawalFee(0);

    deal(address(token), address(vault), 1_000_000e18);

    vm.prank(attacker);
    vault.withdrawAll(attacker);

    assertGt(token.balanceOf(attacker), 0);
}

And this is the output, trimmed to the findings:

warn   RG11 unpinned-fork            test/VaultDrain.t.sol:17:9
       The fork has no block number, so it runs against the chain as it is today.
warn   RG02 privileged-step-in-exploit  test/VaultDrain.t.sol:24:9
       The exploit runs a step as `admin`: the name `admin` reads as the `admin` role.
error  RG06 balance-injection        test/VaultDrain.t.sol:28:9
       deal() sets the `token` balance of `vault` (Vault) in the exploit. It transfers
       nothing and overwrites the balance the contract had.
warn   RG10 no-baseline              test/VaultDrain.t.sol:33:9
       The asserted value `token.balanceOf(attacker)` is read only after the attack.

SUMMARY  1 error · 3 warnings · 0 notes · 0 suppressed
RESULT   FAIL  (fails on error and above)

Notice what is not flagged. new Vault(admin, ...) hands ownership to admin through the constructor, so the deployer rule stays quiet. deal(token, attacker, ...) in setUp() is funding. Both pranks are judged by who they name and when they run, not by the word prank.

Every finding can be argued with. If a finding is wrong for your test, you silence it on the line with a reason:

// realism-gate: allow(RG11) the block is pinned in foundry.toml
vm.createSelectFork("mainnet");

A comment without a reason is ignored, and the output says so. Silenced findings stay in the JSON and SARIF output, marked as suppressed, so a reviewer can see what was waved through and why.


Declaring the attacker model

The identity heuristics will sometimes be wrong. The attacker is called mallet, or the exploit genuinely depends on a keeper's routine harvest. For that there is realism.yaml:

version: 1
attacker:
  identities: [mallet]
privileged:
  - identity: keeper
    role: keeper
    reason: harvest() runs on a schedule from a public keeper network
preconditions:
  - step: deposit right before the harvest
    performed_by: attacker
    boundary: same_block
    ordering_guarantee: public mempool; the attacker back-runs the keeper

Declaring attacker.identities switches the name heuristic off entirely. A declared privileged step silences RG02 for that address, because the declaration is now the claim, and its reason is the argument. The preconditions feed the three boundary rules. The schema is strict, so a typo is an error rather than a silent no-op.

The file is written for the triager, not for the tool. A declaration that makes the output quiet by stating something untrue has only moved the lie into a second file the triager will also read.


What 886 real exploits look like through it

A checker for PoCs needs a control set of PoCs that reproduce something real. The best public one is DeFiHackLabs: several hundred Foundry tests, each reproducing an exploit that actually happened. I ran realism-gate over all of src/test at a pinned commit, with no declaration and no suppressions, and then read every finding in context.

One caveat shapes the whole reading. These are post-incident reproductions, not bounty submissions. A reproduction is allowed to impersonate a compromised key, because a key really was compromised. So the question is not "how many of these PoCs are wrong". It is "does each rule fire on what it says it fires on, and how often does it fire on something it should not".

The run covered 891 files, 869 suites and 886 tests, in about two seconds. One file did not parse completely (a non-ASCII character in a plain string literal) and was still checked.

The headline number is about assertions: 611 of the 886 tests, 69.0 percent, assert nothing. 595 of them log values and leave the comparison to the reader, through a shared modifier that prints the attacker's balance before and after. Sixteen neither log nor assert. That is the corpus's convention, and a reasonable one for a teaching archive. It is also exactly the habit RG08 exists to break in a bounty PoC, where the triager should not have to trust a log line.

Beyond that, 23 tests had at least one other finding, 33 findings in all. I read each of them against the surrounding code and classified them:

Rule

Findings

Correct

Debatable

False positive

RG01

1

1

0

0

RG02

15

15

0

0

RG04

7

7

0

0

RG05

4

0

1

3

RG10

5

4

1

0

RG11

1

1

0

0

Total

33

28

2

3

The correct ones are instructive, and I will describe them without naming the incidents. The single RG01 is a test that pranks as the real owner of a helper contract and transfers its ownership to the PoC's attack contract; the test's own comment calls that line harness setup. The fifteen RG02s are steps run as an owner, a deployer, a keeper, a minter, a whitelisted account, a withdrawal-queue contract and a pool manager, and the comments next to several of them say outright that the line is there because only that role can call the function. One reads, in full, "quick hack to bypass the onlyAuthorisedOperators modifier". In a reproduction of a key compromise, that is the history. In a bounty PoC, it is the line the triager stops at. The RG04s restore historical rollup roots, mark an address tax-exempt and set a token balance slot, and the last of those funds the attacker and is reported one level lower for it.

The three false positives are all RG05, and all the same shape: the reproduction recreates the attacker's own historical contract, or a chain-specific system contract, at its original address with vm.etch. The rule cannot tell an attacker's address from a protocol's when both are bare hex constants with neutral names. That limitation is written on the rule's page, along with the fix: name the address for what it is.

RG03, RG06, RG07 and RG09 did not fire anywhere. For RG03 and RG06 that is expected, since they are about harnesses that deploy the protocol themselves, and this corpus forks real chains.


What reading the corpus changed, and why that matters

I want to be precise about what those numbers are. They are in-sample. I used this corpus while writing the rules, and two heuristics changed after the first run, both to remove false positives:

  • RG08 originally ignored modifiers, so a test wrapped in the corpus's logging modifier looked as if it logged nothing. Modifier bodies are now inlined around the test body.

  • RG10 originally counted every external call as a state change and treated equality assertions as claims of gain. That made a check of the victim's starting balance look like an unmeasured profit. It now treats calls written inside an assertion as reads, ignores checks made before the exploit changes anything, and only judges directional claims.

Both changes are covered by tests, and both are listed on the benchmark page. The review is one person's judgement, mine, and "correct" means I would have stopped at that line as a reviewer. I am not presenting any of this as a measured false-positive rate. It is a sanity check that the rules fire where they claim to, on code they were not written for, plus an honest count of where they did not.

An out-of-sample measurement needs PoCs the rules have never seen, ideally real bounty submissions with known triage outcomes. I do not have a shareable set. If you do, and can share counts rather than PoCs, I would like to hear from you.

To keep the published numbers honest over time, the benchmark is part of CI. A script fetches only src/test at the pinned commit, runs the checker, reduces the report to the counts on the benchmark page, and fails the build if any of them move. A rule change that shifts the numbers has to update the page in the same pull request, with a reason.


Using it

It is a single Rust binary with two names, realism-gate and rgate, built for Linux, macOS and Windows.

realism-gate check test/                    # text report, exit 1 on any error
realism-gate check --format sarif -o r.sarif
realism-gate check --fail-on warn --skip RG08
realism-gate explain RG06                   # why it exists, how it is wrong
realism-gate init                           # write a realism.yaml template

Exit status is 0 when nothing reaches --fail-on, 1 when something does, and 2 for a usage, input or declaration error. A run that finds no parseable suite at all exits 2 rather than reporting a clean result, because silence is not a pass.

In CI, the repository is a composite GitHub Action. It downloads the release binary for the runner, verifies it against the release checksums, and can upload SARIF so findings show up inline on the pull request. JSON and SARIF are the stable interfaces; the text output is for people.

Two properties are enforced rather than promised. It never touches the network: the PoCs it reads may be for embargoed findings, so CI fails if a network crate appears anywhere in the dependency graph or socket code appears in the source. And the repository ships no one's PoCs: the fixtures are synthetic, and a hygiene check fails the build on host paths or target names.


What it cannot tell you

A tool that checks proofs should be exact about what it does not check.

It reads the test, not the protocol, so it does not know the deployed contract's access control. A role it cannot see is a role it cannot flag, and a variable that merely sounds privileged will be flagged. It does not read foundry.toml, so a fork pinned there still trips RG11. It flattens control flow, so a prank inside an if counts whether or not the branch runs. It follows plain assignments and a few levels of aliasing, not storage or return values of external calls.

Most importantly, a clean result means no known defect pattern was found. It does not mean the bug is real, the impact is what the report says, the program pays for it, or nobody reported it first. A PoC with zero findings can still be wrong, and a PoC with findings can still be right once each one is justified.


Where it fits

This is the fourth open-source tool I have built around one question, why security findings do not get paid, and each one covers a different place a report dies.

The rejection taxonomy is my log of every rejection, classified by the earliest gate that could have caught it. bounty-economics asks whether a finding can pay at all on a given program. viability-gate checks the written report against the anti-patterns that close findings in triage. And realism-gate checks the part the report rests on: whether the proof of concept proves what the write-up claims.

The order matters. A finding can be real, in scope, well written and paid at its severity, and still be closed because the PoC shows a privileged action, or because the triager reads deal(token, vault, ...) and stops. That is the cheapest rejection to prevent, because every piece of evidence for it is already sitting in your test file.

The code, the rule pages and the benchmark are at github.com/KhomDev/realism-gate. The most useful thing you can send me is a false positive, reduced to a synthetic test.

A green test is evidence about your harness. Make it evidence about the attacker before anyone else reads it.