Prompt to Pwn: Automated Exploit Generation for Smart Contracts
This paper introduces \textsc{ReX}, an execution-grounded framework that leverages LLMs and the Foundry stack to automate end-to-end exploit generation for smart contracts, revealing that while current models can effectively synthesize deterministic proofs-of-concept for single-contract vulnerabilities, they struggle with cross-contract attacks and face significant gaps between technical exploitability and real-world economic impact.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Big Picture: The "Robot Hacker" Experiment
Imagine smart contracts as digital bank vaults that run on a blockchain. Once you build one and lock it in place, you can't change the locks or fix a broken hinge without rebuilding the whole vault. If there's a flaw, a thief can steal everything forever.
For years, security experts have used tools to find these flaws (like a metal detector for bugs). But this paper asks a scary new question: What if we give a super-smart AI (a Large Language Model or LLM) the job of not just finding the flaw, but actually building the key to break in?
The researchers built a system called ReX to test this. They asked five of the world's smartest AIs to act as "script kiddies" (novice hackers) and try to generate working "Proof of Concept" (PoC) exploits—basically, a working lockpick for the digital vaults.
How the System Works (The "ReX" Factory)
Think of ReX as a high-tech factory assembly line where the AI is the worker, and the "Foundry" is the quality control inspector.
- The Blueprint (Preprocessing): The researchers clean up the code of a vulnerable contract so the AI doesn't get confused by messy notes.
- The Construction (Script Generation): The AI is asked to write two things:
- The Lockpick: A script designed to break into the vault.
- The Test: A script to prove the lockpick actually works.
- The Inspection (Foundry): The code is fed into a testing engine called Foundry. If the code doesn't compile (like a car that won't start) or the test fails, the machine rejects it.
- The Fix-It Loop: If the AI fails, the machine sends the error message back to the AI: "Hey, you forgot a semicolon," or "Your math is wrong." The AI tries again. This happens until the AI either succeeds or gives up.
What Did They Find? (The Results)
The researchers tested the AIs on two types of vaults:
- Training Vaults (SmartBugs): Simple, textbook examples of broken locks.
- Real-World Vaults (Web3-AEG): Actual contracts that were hacked in the past, causing millions in losses.
1. The Good News for Defenders: AIs are "One-Trick Ponies"
The AIs are surprisingly good at breaking simple, single-contract vaults.
- Analogy: If the vault has a broken hinge (a simple math error or a bad password check), the AI can easily pick it.
- Result: On simple bugs, top AIs like Gemini 2.5 Pro and GPT-4.1 succeeded about 60–90% of the time.
2. The Bad News for Defenders: AIs Can't Handle "Heist Movies"
The AIs struggle terribly with complex, multi-contract attacks.
- Analogy: Real-world hacks often look like a heist movie where the thief has to trick the bank, the security guard, and the delivery truck all at once, using a chain of events.
- Result: When the attack required coordinating between multiple different contracts (like a flash loan attack), the AIs mostly failed. They could see the broken door, but they couldn't figure out how to run through the maze of hallways to get the money.
3. The "Human" Gap
When the AIs did succeed, they usually just found the technical hole.
- Analogy: The AI might successfully pick the lock and open the vault door. But a human expert would know to immediately grab the gold, swap it for cash, and run before the alarm goes off. The AI often just opens the door and stands there. It lacks the "economic intuition" to turn a technical bug into a profitable crime.
What Makes the AI Succeed or Fail?
The researchers wanted to know: Is it because the code is too hard? Is the prompt wrong? Or is the AI just not smart enough?
- It's the AI's Brain, Not the Code: Surprisingly, the size or complexity of the code didn't matter much. A tiny, simple contract was just as hard (or easy) for the AI to hack as a massive, complex one. The deciding factor was simply which AI model you used. Some models are just better at "thinking" like a hacker.
- The "Prompt" Doesn't Help Much: Telling the AI "Be a security expert!" or "Think step-by-step!" helped a little, but it didn't fix the fundamental problem. If the AI doesn't understand the logic, no amount of polite instructions will make it work.
- Iterative Repair is Key: The biggest boost came from the "Fix-It Loop." If you let the AI try, fail, read the error, and try again, its success rate nearly doubled. It's like letting a student take a practice test before the real one.
How Do We Defend Against Robot Hackers?
If AIs are getting better at hacking, how do we stop them? The paper suggests some "Asymmetric Hardening" techniques—tricks that make life hard for the AI but easy for humans.
- Split the Vault (Code Splitting): Instead of one big contract, break the logic into many small, disconnected pieces.
- Analogy: If the AI is trying to solve a puzzle, give it 100 tiny puzzles instead of one big one. It gets confused trying to connect the dots.
- Use "Secret Handshakes" (Rare Syntax): Use obscure, weird coding features that AIs rarely see in their training data.
- Analogy: If the AI is trained on standard English, speak to it in a dialect it doesn't know. It will stumble over the words.
- Set Traps (Decoy Vulnerabilities): Intentionally put fake "broken locks" in the code that look real but aren't.
- Analogy: Put fake treasure chests in the hallway. The AI wastes time trying to pick the fake ones, while the real gold is safe.
- The "Bad Luck" Defense: The paper found that AIs are terrible at predicting things that depend on randomness or time (like "what will the weather be in 5 minutes?"). Using these in your code confuses the AI.
The Bottom Line
The Verdict:
Current AI models are becoming dangerous tools for finding simple bugs in smart contracts. They can act as "force multipliers" for novice hackers, allowing them to break simple locks they couldn't break before.
However:
They are not yet "super-hackers." They cannot yet orchestrate complex, multi-step heists that require deep economic reasoning or navigating a maze of different contracts.
The Takeaway:
We don't need to panic that AI will instantly drain all crypto wallets. But we do need to stop treating AI as a magic wand. The best defense isn't just better code; it's making the code look weird and complex enough to confuse the robot, while keeping it simple enough for a human to understand.
The paper concludes that while AI is a powerful new weapon, the "human element" of understanding the business logic and economic incentives of a hack is still the ultimate shield.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.