Your smart contracts are going to be attacked by frontier models. Here's how to defend them.
Attackers now have access to increasingly capable models that can search software for exploitable edge cases at machine speed. At Ground, we’ve responded by building an LLM-based adversarial testing pipeline that continuously reviews smart contract changes, assigns agents to hunt specific vulnerability classes, uses separate agents to challenge findings, reproduces credible exploits in code, and searches for related failures elsewhere in the system.
The Truebit exploit
Earlier this year, $26.4 million was stolen from Truebit, one of the pioneers of the verifiable compute space, which was able to pass a carefully crafted input into a Truebit smart contract. Unlike many recent protocol hacks, this hack exploited a pure onchain vulnerability, with no social engineering required.
By requesting to buy 240,442,509,453,545,333,947,284,131 base units of TRU (about 240 million tokens) with ETH from Truebit’s purchase contract exactly when the outstanding supply of TRU was 161,753,242.367424992669183203 TRU and the Truebit ETH reserve had exactly 8,539.408935947150350830 ETH in it, the attackers were able to take advantage of an integer overflow to manipulate Truebit’s TRU/ETH pricing formula to “purchase” about 240 million TRU for exactly 0 ETH.
This vulnerability had been sitting in the open on Ethereum Mainnet for nearly five years before it was finally exploited this past January. How many other vulns like this still exist? And how do you protect yourself from accidentally shipping one? In a world where state-sponsored adversaries have access to cyber-capable LLMs, I suspect the exploit timeline has shortened from years to days.
Why we built an adversarial pipeline
The company I co-founded, Ground, is a financial infrastructure company and part of our stack is smart contracts that deploy funds onchain. So we need every confidence that our code will behave as expected when adversaries throw fleets of frontier LLMs at our smart contracts.
Organically over time, and in partnership with cybersecurity researchers, we’ve built an LLM-based adversarial testing pipeline around our development process. The security review pipeline is where every smart contract change gets scrutinized by a fleet of LLMs. At a high level, we are looking for three things:
- Can the inputs cause harm?
- Can someone reach something they shouldn’t?
- Is the runtime safe?
For example, integer overflow behavior, the type of bug that resulted in the $26.4 million Truebit hack, is one of the input safety classes that we look for in every new smart contract deployment. Once a vulnerability is found, we automatically assign an agent to identify an attack sequence that could cause harm. In Truebit’s case, that would have been the ability to mint TRU at a price that is obviously too low (0 ETH).
How the pipeline works
Here is how our adversarial testing pipeline works:
We start by giving the agents the same context we would give a human security reviewer: the code, the architecture around it, and an explanation of how the system is supposed to behave. We then run multiple agents in parallel, each looking for a specific class of failure across the relevant code.
Areas we recon in every smart contract change
Challenging every finding
When we first began using this framework, we ran into an issue where most of the findings were false positives or otherwise made inaccessible by operational procedure (order of deployment, role setting, etc.).
Thus, when a finding surfaces, a separate reviewer agent is given the opposite job: try to disprove the finding. It checks whether the attack can actually occur and whether another safeguard elsewhere in the system prevents it. Findings that don’t survive that review are closed as false positives.
Reproduce, fix, and verify
For findings that do survive, we try to reproduce the failure in code. We write a test that demonstrates the vulnerability, correct the code, and then rerun the test. At the same time, we send agents back through the rest of the system looking for other places where the same underlying mistake may exist to confirm that the issue isn’t a broader pattern. And then any related findings go back through the same review and reproduction process.
For example, we recently evaluated a security finding that a callback could continue processing a withdrawal after withdrawals were disabled. However, the challenger agent found that the callback could only advance an already-pending withdrawal that had passed the permission check when it started and that new withdrawals were indeed correctly blocked. This was marked as a false-positive finding.
Once the fix passes, we rerun the broader test suite and, where the behavior crosses our server and smart contracts, test the two together against a forked version of the relevant mainnet chain on our local machine. If the fix still fails, it goes back through remediation. If it passes, the finding, the correction, and the test evidence go to engineering review before release.
Independent human auditors
For changes involving fund control, valuation, settlement, or claims, we also require independent human professional auditors alongside the agent pipeline. Anything they find goes through the same correction and verification loop. Then we run the pipeline again as the software changes.
Defending at machine speed
In a world where state-sponsored groups have access to compute and cyber-capable frontier models, we expect attackers to throw parallelized intelligence against our smart contracts. Defenders on the frontline have to do the same.
If you are a team building onchain finance, we would be happy to share learnings to help you build your defense pipeline and make introductions to the security researchers we work with.