Dev.to Security 🔐 Cybersecurity 👁 0 📖 7 min read

It Compiled. It Passed Every Test. A Second AI Read the Code and Found the Free Mint.

The report said PASSED. The contract it described had zero functions. I'm building a tool that takes a verified Solidity contract and rewrites it for chains that don't run Solidity: Solana, CosmWasm, Aptos, Tezos. Code

The report said PASSED. The contract it described had zero functions.

I'm building a tool that takes a verified Solidity contract and rewrites it for chains that don't run Solidity: Solana, CosmWasm, Aptos, Tezos. Code handles the structure, a language model writes the function bodies, and then the tool deploys both versions and replays the same scenarios against each to check they behave the same.

My builder agents (Claude Code) had 420 green tests and a pipeline that printed PASSED. I believed it about as much as you'd expect, so I gave a different agent from a different vendor, Google's Antigravity running Gemini, API access to a test deployment and one instruction: break it, and read the generated code yourself.

It took one evening.

Round one: "PASSED" was too easy

Three critical findings, eight major, thirteen minor. The critical ones all had the same shape:

  • An empty contract passed. An old-compiler contract lost every function during parsing. The tool generated an empty shell, ran one empty scenario against it, and reported success.
  • A constant became zero. A reward period declared inline as 60 days came out as 0 on every target, which makes the reward function divide by zero. Nobody noticed, because every scenario ran with a reward rate of zero.
  • Wrong arithmetic passed. A staking rewrite computed (balance - paid) * rate where the original computes balance * (rate - paid). Same zero-reward scenarios, so both gave zero. The report even repeated the model's own note that the formula was preserved.

That last detail became a rule: a model's note about its own output is a claim, not evidence.

The loop

After that I stopped treating testing as a phase. I told the builder session to keep talking to the tester through my agents' inbox until the tester had nothing left:

iacp msg agy@greenmac:f2e65d43 "RETEST ROUND 5 READY: <changes> <priority tests> <known not done>"

Builders fix in separate git worktrees. The main session reviews and redeploys. The tester gets a change list, a priority list and, importantly, a list of what is knowingly not done. It replies with a report. Exit condition: the tester says "NO NEW CONFIRMED DEFECTS."

Each round took two to three hours. Six rounds ran in about a day and a half, most of it while I was doing something else.

The loop also broke my inbox, twice. The round-four brief was silently cut at exactly 2,000 characters, so the tester got half its instructions. And replies kept landing in whichever of my Claude sessions happened to check mail first. Both got fixed mid-loop: inboxes are now per session, messages are acknowledged instead of deleted on read, and long ones are handed over as files. Nothing finds the holes in a messaging system like two agents that actually depend on it.

The change I like most is the quietest one. In the early rounds I was the notification system: an agent would finish, and nothing happened until I told the other one to check its mail. Now neither waits for me. A tiny background service watches for unread mail, and when an agent that has gone idle has a message waiting, it starts a turn for it with "a new message has arrived for you." It works for both vendors. It also works between sessions of the same vendor: two of my Claude sessions on different projects now message each other directly, where they used to write notes to shared memory and wait for me to tell the other one to go read them. The follow-up round after the six in this post started that way: five wake-ups in the log, three for the tester and two for the builder, none of them from me.

Round five: check dropped, effect kept

By round five the easy bugs were gone, and the tester stopped trusting scenarios and read the rewritten code line by line. It found three critical security defects with one cause.

Some guards can't be expressed on the target chain. Recovering a signer from an Ethereum signature is the obvious one. When the model hit one of those, it did the reasonable-looking thing: translate what it could. Simplified, the result looked like this:

// rewritten "transfer with a signed authorization"
if sig.len() != 65 { return Err(BadSignature); }
if !(v == 27 || v == 28) { return Err(BadSignature); }
// (no signer recovery, no replay check)
balances[from] -= amount;
balances[to]   += amount;

It validates that the signature looks like a signature. It never checks who signed it. Anyone can move anyone's balance.

Same pattern elsewhere: a "wrap" function that minted the wrapped token without pulling in the token being wrapped, and a transfer that credited the receiver without debiting the sender. A free mint, twice.

All of it compiled. All of it passed the behaviour check, because every scenario was a legitimate user doing a legitimate thing. Nobody had written the scenario where the wrong person tries, so nothing ever exercised the path that should have said no.

The model fails open: when it can't translate the check, it drops the check and keeps the effect.

What changed

The fix was not a better prompt. It was taking the decision away from the model:

  • Fail closed, in code. If a function's guard can't be expressed on the target, the function is not translated at all. A missing function is an inconvenience. A function without its guard is a theft.
  • Lint before behaviour. A static security pass runs before any scenario and can mark a rewrite unsafe on its own.
  • Negative scenarios for every guarded function. The wrong caller, the reused signature, the missing deposit. If the denied path isn't tested, the function isn't verified.
  • Verdicts capped by coverage. PASSED now requires every state-changing function to be verified with non-zero values. Otherwise the best you get is "partially verified."

Round six was the first with no critical findings. The tester read 13 rewrites line by line and found zero unsafe ones that the report hadn't already flagged, including three new contracts it picked specifically to be nasty.

It also found three guard patterns the static check still misses, where the guard hides behind a library call or a helper two calls away. The other layers caught them this time. That fix is in progress, and the tool is not released.

Two things I didn't expect

The tester settled an argument. A builder had blamed one stubborn failure on "model logic." The tester traced it to the tool's own code generator: two structs aliasing the same account, with the stale one written last. The builder's diagnosis of its own failure was wrong, and it took an outsider to say so.

What I told one agent, the other never heard. I had told the tester that if nothing was breaking, I didn't want this dragged out. So its round-six report opened with "GO LIVE" and cited my preference. The builder had never heard me say that. From where it sat, another agent was claiming to speak for me, so it declined the sign-off and asked for one more short round. Its caution was right for what it could see. The gap was mine: an instruction given to one agent doesn't exist for the other until someone writes it where both can read it.

So that is the next thing I'm building: a board per project where I write an instruction once and every agent on it reads it, including the one that joins tomorrow. The agents never needed a ticket system from me. The tester numbered its findings from its first report, and from the second round on, every report opened with a table of which were fixed, partly fixed or still open. What they couldn't create was a record of what I wanted. Maybe tomorrow's coding agents don't need Jira. They still need somewhere the human's decisions live.

If you're shipping model-written code

  • Compiling and passing is a statement about your tests. Ask what your scenarios never tried.
  • Test the "no." For anything guarded, the denied path matters more than the happy path.
  • Let a different model read the output. Not a second run of the same builder. A different vendor with no stake in the code being right.
  • Give the tester your known gaps. It stops re-reporting them and spends its time on what you don't know.
  • Put security in code, not in the model's judgment. The model will be helpful. Helpful is how you get a free mint.

Numbers

Six rounds in about a day and a half. Round one: 3 critical, 8 major, 13 minor, found in one evening against 420 passing tests. Round five: 3 critical security defects in code that compiled and passed. Round six: 13 rewrites read line by line, zero unsafe ones unflagged.

The most dangerous output my tool produced wasn't the one that crashed. It was the one that worked.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.