Active defense for Uniswap v4. Monitor toxicity & rescue liquidity with automated exits
Wraith Protocol is a decentralized, AI-driven "Agent Guard" architecture designed to provide an active defense layer for Liquidity Providers (LPs) in the Uniswap v4 ecosystem. Wraith automates the detection of malicious on-chain patterns, such as rug-pulls, exploit attempts, and toxic MEV flows and executes atomic "Flash-Rescues" to secure user capital before an attack can be finalized.
At its core, the protocol operates through a multi-layered defensive stack:
The Intelligence Layer (Gensyn Sentinel): Utilizing Gensyn’s Verifiable Compute (AEL), autonomous Sentinel agents monitor the Unichain mempool in real-time. They analyze contract bytecode for malicious opcodes (like SELFDESTRUCT) and run toxicity models within a Bitwise Reproducible Execution Environment (REE). This ensures that every threat detection is backed by a cryptographic "Proof of Malice," preventing false positives and ensuring decentralized trust.
The DeFi Integration Layer (WraithHook): Leveraging Uniswap v4 Hooks, the protocol intercepts pool actions before they occur. It implements a dynamic "Poison Fee" mechanism that can instantly override pool fees to 99.9% for flagged malicious actors, effectively trapping their capital. Furthermore, it utilizes EIP-1153 Transient Storage to manage toxicity states with extreme gas efficiency.
The Execution Layer (KeeperHub Flash-Rescue): When a critical threat is verified, the protocol triggers a "Quantum Exit." Orchestrated via KeeperHub, this process bundles multiple operations like removing liquidity, swapping assets to stablecoins, and depositing them into a secure vault, into a single, atomic transaction. By utilizing high-priority MEV-protected bundles, Wraith ensures that the LP's assets are rescued before the attacker’s transaction can land on-chain.
The Messaging Layer (AXL P2P Mesh): To maintain decentralization, Wraith agents (Python-based Sentinels and Node.js-based Keepers) communicate via the AXL P2P Mesh Network. This encrypted, agent-to-agent communication layer removes the need for centralized relayers, ensuring the defense system remains resilient and censorship-resistant.
By combining the modularity of Uniswap v4 hooks with the verifiable intelligence of Gensyn and the reliable execution of KeeperHub, Wraith Protocol transforms liquidity provision from a passive, high-risk activity into a protected, autonomous experience. It is a comprehensive "Active Defense" system for the next generation of decentralized exchanges.
Building Wraith Protocol was a journey into the next-generation DeFi security, combining cutting-edge blockchain features with decentralized AI agents. Here is the breakdown of how the project was constructed:
The Tech Stack & Integration The protocol is a hybrid architecture that bridges the gap between high-speed on-chain execution and intensive off-chain analysis.
On-Chain (Solidity & Uniswap v4): I built WraithHook.sol, a custom Uniswap v4 hook that acts as the "enforcement officer." It leverages EIP-1153 Transient Storage (tstore/tload) to pass toxicity states between beforeSwap and `beforeRemoveLiquidity calls within a single block, saving massive gas costs compared to traditional persistent storage.
The Intelligence Layer (Python & Gensyn AEL): The Sentinel Agent is written in Python (3.13) to leverage powerful libraries like numpy and web3.py. It uses Gensyn's Verifiable Compute (AEL) to run toxicity models. This ensures that when a pool is flagged, there is a cryptographic "Proof of Malice" submitted on-chain, making the defense system provably fair and decentralized.
The Messaging Layer (AXL Agent Mesh): I solved the "Agent Communication" problem using AXL. Instead of a centralized API, the Python Sentinel broadcasts encrypted threat alerts to the Node.js Keeper via the AXL P2P mesh. This keeps the entire defense stack decentralized and censorship-resistant.
The Execution Layer (Node.js & KeeperHub): When an alert is received, a Node.js-based Keeper Agent interacts with KeeperHub to submit atomic "Flash-Rescue" bundles. These bundles ensure that the LP's liquidity removal and swap to safety happen in the same transaction, effectively outrunning the attacker.
Partner Technology Benefits Uniswap v4 Hooks: This was the fundamental enabler. In Uniswap v3, we could only react after an attack. V4 hooks allow us to intercept and "poison" an attacker's transaction before it even executes. Gensyn REE: By running our scoring logic in a Bitwise Reproducible Execution Environment (REE), we ensure that every Sentinel produces the exact same toxicity score for the same input, which is critical for on-chain verification. KeeperHub: This is our core reliability and execution layer. KeeperHub allows us to submit Atomic Flash-Rescue bundles directly to block builders. This is crucial because a standard "rescue" transaction could be front-run by the very attacker we are trying to escape. By using KeeperHub, we guarantee that the Remove Liquidity -> Swap -> Vault Deposit sequence happens in a single, protected block, providing our users with enterprise-grade MEV protection and guaranteed execution
Particularly "Hacky" & Notable Details Bytecode Entropy Analysis: To detect malicious contracts that use obfuscation or packing, we implemented a Shannon entropy calculator in the Python Sentinel. It analyzes the statistical distribution of bytes in a contract's bytecode; a low entropy score often signals hidden, malicious logic that traditional scanners might miss.
The 99.9% Poison Fee: We used a "hook-specific fee override" trick. By returning the LPFeeLibrary.OVERRIDE_FEE_FLAG in the beforeSwap hook, we can dynamically jack up the fee to 99.9% specifically for flagged attacker addresses, essentially "trapping" their capital in the pool.
Sovereign Override: We realized AI can sometimes make mistakes. We built a "Sovereign Override" safety valve that allows a user to manually flag their own liquidity as "safe" for a 5-block window, bypassing the Sentinel’s blocking logic if they need to exit urgently during a false positive.
macOS SSL "Magic": During development, we hit persistent certificate verification issues with Python's asyncio and Unichain RPCs on macOS. We implemented a custom SSL context bypass in the Sentinel's initialization to ensure 100% uptime for local development and monitoring.
By stitching these diverse technologies together, Solidity hooks, Python AI, and P2P mesh networking, we've created a protocol that doesn't just watch for rug-pulls, but actively fights back.

