Use Your Spell Against You: A Proactive Threat Prevention of Smart Contract Exploit
This talk presents a proactive, post-launch security mechanism designed to detect and block DeFi smart contract exploits by automatically synthesizing and executing a 'rescue' transaction. The technique involves monitoring the mempool for malicious transactions, simulating them to identify the attack logic, and reconstructing a counter-transaction that replaces the attacker's address with a secure one. This approach allows for the recovery of assets from vulnerable protocols without requiring prior integration or access to the target smart contract. The speaker demonstrates the effectiveness of this method by successfully blocking real-world attacks and recovering over 20 million USD.
How to Hijack a DeFi Exploit in Real-Time
TLDR: Researchers have developed a post-launch security mechanism that monitors the mempool for malicious smart contract transactions, simulates them to extract the attack logic, and synthesizes a "rescue" transaction to intercept the funds. By replacing the attacker's address with a secure one in the reconstructed transaction, this method allows for the recovery of assets from vulnerable protocols without prior integration. This approach effectively turns an attacker's own exploit against them, providing a proactive defense layer for live DeFi environments.
DeFi security is currently a game of cat and mouse where the mouse usually has a massive head start. When a vulnerability is discovered in a live protocol, the exploit happens in milliseconds, often leaving the development team scrambling to figure out what went wrong while the drainer wallet is already being laundered through mixers. Traditional pre-launch measures like code auditing and fuzzing are essential, but they cannot account for the zero-day logic flaws that emerge in complex, composable environments. The research presented at Black Hat 2024 shifts the focus from static analysis to active, post-launch interception.
The Mechanics of the Counter-Exploit
The core of this research relies on the window of time between a transaction being broadcast to the peer-to-peer network and its inclusion in a block. On Ethereum, this is typically around 12 seconds. During this interval, the transaction sits in the mempool, visible to anyone running a node. The researchers built a system that monitors this mempool, identifies transactions interacting with known DeFi protocols, and simulates them to determine if they are malicious.
If the simulation confirms an exploit, the system does not just alert the team; it generates a "rescue" transaction. This is the most impressive part of the research. The system automatically reconstructs the attack logic but swaps the attacker's destination address for a secure, protocol-controlled address. By using gas-bidding strategies, the system attempts to get this rescue transaction mined before the original malicious one.
Technical Challenges in Transaction Synthesis
Synthesizing a functional exploit transaction is non-trivial because attackers often use obfuscated code or complex, multi-step logic. The researchers identified three primary hurdles: extracting the attack logic, identifying the revenue addresses, and handling pre-conditions.
Extracting the logic involves analyzing the opcode trace of the simulated transaction. The system must filter out the verification logic—which often checks if the caller is the attacker—and focus on the actual fund-draining operations. A significant challenge arises when the attack involves loops, which can lead to a generated contract that exceeds the maximum allowed size on the blockchain. To solve this, the researchers implemented a technique that reuses basic blocks from the original trace and uses a "trampoline" to redirect execution flow, effectively compressing the logic while maintaining the exploit's functionality.
Identifying the revenue address is handled via a try-and-catch approach. The system calculates a balance change table during simulation to pinpoint which addresses receive the stolen funds. If replacing an address causes the transaction to revert, the system iterates through potential candidates until it finds the correct one. This ensures the rescue transaction is as precise as the original exploit.
Real-World Impact and Limitations
This technique is not just a theoretical exercise. The researchers have already deployed this mechanism and successfully blocked over 20 attacks, recovering more than 20 million USD in assets. Notable rescues include ParaSpace and Saddle Finance. For a pentester or bug bounty hunter, this research highlights a shift in how we should view "exploitability." If a protocol has a public, observable state, it is potentially susceptible to this kind of automated interception.
However, the technique has clear limitations. It is highly dependent on the mempool's transparency. If an attacker uses a private mempool or a direct-to-validator submission service like Flashbots, the monitoring system will never see the transaction until it is already confirmed on-chain. Furthermore, the system requires a significant amount of capital to outbid the attacker's gas fees, which might not be feasible for smaller protocols or during periods of extreme network congestion.
What This Means for Security Research
Defenders are finally moving beyond passive monitoring. By treating the mempool as a battleground rather than just a queue, researchers are creating a new class of "active" security tools. The tool developed by the team, Phalcon, is a direct result of this research and provides a platform for others to experiment with these monitoring and blocking capabilities.
For those of us in the trenches, this is a reminder that the "security" of a smart contract is not just about the code itself, but about the entire ecosystem of transactions surrounding it. As these automated rescue systems become more common, we should expect to see attackers evolve their own techniques to bypass mempool monitoring, perhaps by further obfuscating their transaction intent or moving toward more decentralized, private submission methods. The race is on, and the tools are getting faster.
Vulnerability Classes
Tools Used
Target Technologies
OWASP Categories
Up Next From This Conference
Similar Talks

Web2 Meets Web3: Hacking Decentralized Applications

How to Read and Write a High-Level Bytecode Decompiler




