Skip to content

Nkovaturient/GhostLock-MEV-Reaper

Repository files navigation

GhostLock: MEV Reaper Randamu Inc

A stealth shield against MEV, encrypting trades and settling them fair.

Glance

ChatGPT Image Aug 30, 2025, 09_57_54 PM

🛡️ Overview

GhostLock: MEV Reaper is a cutting-edge DeFi platform that significantly endeavours to protect traders from Maximal Extractable Value (MEV) attacks through a 3-layer defense strategy: ENCRYPT → RANDOMIZE → EQUALIZE. Built on Base Sepolia and Arbitrum One, it leverages blocklock encryption, VRF-based ordering, and AI-optimized batch auctions to eliminate front-running, sandwich attacks, and price manipulations at each levels.

GhostLock Banner

✨ Key Features

3-Layer MEV Protection Strategy

  1. 🔒 ENCRYPT (Layer 1): Blocklock time-locked encryption hides trading intents until execution block
  2. 🎲 RANDOMIZE (Layer 2): EpochRNG VRF-based fair ordering prevents sandwich attacks via deterministic randomization
  3. ⚡ EQUALIZE (Layer 3): Batch auctions with uniform pricing eliminate front-running opportunities and price manipulations.

Additional Features

  • 🤖 Trade Intents Settlement: Automated solver with AI-optimized clearing prices
  • 📊 Transparency Panel: Gas estimates, unlock block ETA, expected receive amounts via 1inch API
  • 💳 Mock ERC-20 Tokens: ETH, USDC, WETH for development and testing
  • 🌐 Multi-Chain: Deployed on Base Sepolia (testnet) and Arbitrum One (mainnet-ready)

🏗️ Architecture

Frontend (React + TypeScript)

  • Framework: React 18 with TypeScript
  • Styling: TailwindCSS with custom design system
  • Animations: Framer Motion + Three.js for 3D components
  • Web3: Wagmi + RainbowKit for wallet integration
  • State: Zustand for client state management

Backend (Node.js + Express)

  • Runtime: Node.js with Express framework
  • Blockchain: Ethers.js for smart contract interaction
  • APIs: RESTful API design with comprehensive endpoints
  • Solver Service: Automated batch settlement with epoch seed management (Layer 2)
  • Scheduler: Proactive epoch seed monitoring and VRF request handling
  • Real-time: WebSocket support for live updates

Smart Contracts (Solidity)

  • GhostLockIntents: Manages encrypted trading intents
  • EpochRNG: Provides verifiable randomness for fair ordering
  • BatchSettlement: Handles uniform-price batch auctions
  • MockTokens: Test tokens for development and testing

Layer 2: EpochRNG Randomization

Purpose: Prevents sandwich attacks by randomizing intent execution order using verifiable randomness.

How it works:

  1. Backend solver automatically requests VRF seed from Drand network via EpochRNG contract for each epoch
  2. When intents are decrypted (after Layer 1), solver ensures epoch seed exists before processing
  3. Intents are grouped by epoch and ordered deterministically using keccak256(epochSeed || requestId || user)
  4. This creates fair, unbiased sequencing that attackers cannot predict or manipulate
  5. Same seed always produces same order → verifiable and deterministic

Implementation:

  • Backend: solver.js automatically requests epoch seeds, waits for VRF callback, then orders intents
  • Backend: scheduler.js proactively monitors and pre-requests seeds for upcoming epochs
  • Frontend: useEpochRNG hook reads seeds for display, useAutoEpochSeedRequest monitors availability (read-only)
  • Utilities: epoch-ordering.ts provides deterministic comparison functions matching backend logic

Tackles:

  • ✅ Sandwich attacks (can't predict order to insert front/back-run)
  • ✅ Front-running (order is randomized, not first-come-first-served)
  • ✅ MEV extraction via sequencing manipulation

⚔️ How GhostLock is Different

Compared to other MEV-resistant efforts, GhostLock stands apart:

  • Flashbots / SUAVE

    • Focus: private mempools + off-chain transaction sequencing.
    • Limitation: requires trust in relays / builders; opaque order-flow markets.
    • GhostLock advantage: no trusted relay; instead, ciphertexts are natively encrypted on-chain and decrypted only after safe block height. No privileged actors.
  • CoW Protocol

    • Focus: batch auctions with solver competition.
    • Limitation: intents visible before clearing → still exploitable; solvers can extract flow.
    • GhostLock advantage: adds 3-layer protection (ENCRYPT + RANDOMIZE + EQUALIZE), so intents remain hidden until reveal, then shuffled via VRF to remove sequencing edge, then settled uniformly. GhostLock inherits batch auction fairness but eliminates pre-reveal leakage and sequencing manipulation.
  • MEV-Boost / PBS

    • Focus: splitting block builders and proposers.
    • Limitation: improves validator decentralization but not user-level trade protection.
    • GhostLock advantage: user-first MEV protection, solving leakage at the transaction level.
  • Secret Network / TEEs

    • Focus: hardware-enforced secrecy.
    • Limitation: trust in hardware enclaves, supply-chain risk.
    • GhostLock advantage: cryptographic, open, and verifiable; no hardware black box.

⚠️ Limitations & Edge Cases

  • Decryption timing mismatch: If unlock block < inclusion block, could allow premature reveal. Mitigation → safety margins + epoch alignment.
  • Solver centralization: Current AI call is centralized; roadmap includes solver marketplace + bond/slashing to prevent manipulation.
  • Metadata leakage: Ciphertext size/timing may leak info. Roadmap → padding + dummy intents.
  • Latency vs UX tradeoff: Batch auctions add delay (~minutes). Mitigation → deploy on L2 for faster block times.
  • Oracle/API dependency: Reliance on 1inch & external VRF oracles. Add fallback quoting + distributed randomness in roadmap.

🚀 Quick Start

Prerequisites

  • Node.js 18+ and npm

Installation

  1. Clone the repository
git clone https://github.com/your-org/ghostlock-mev-reaper.git
cd ghostlock-mev-reaper
  1. Install dependencies
# Install root dependencies
npm install

# Install server dependencies
cd server && npm install && cd ..
  1. Environment Setup
# Copy environment files
cp .env.example .env
cp server/.env.example server/.env

# Update with your configuration
# - Add your WalletConnect Project ID
# - Configure RPC URLs
# - Set contract addresses (after deployment)
  1. Start Development Servers
# Terminal 1: Start frontend
npm run dev

# Terminal 2: Start backend API
npm run server
  1. Access the Application locally
  • Frontend: http://localhost:3000
  • Backend API: http://localhost:4800
  • Health Check: Preview
  • Peak the server here 👀: Preview

📋 Smart Contract Deployment

Base Sepolia (Testnet)

Arbitrum One (Mainnet)

📖 API Documentation

Endpoints

Auctions

  • GET /api/auctions - List all auctions
  • GET /api/auctions/:id - Get specific auction
  • GET /api/auctions/stats - Get auction statistics

Markets[ZEROMEV API]

  • GET /api/markets - List all markets
  • GET /api/markets/:id - Get specific market
  • GET /api/markets/stats - Get market statistics

Future Roadmap

  • Batch auctions with uniform pricing - Solver Competiton board
  • Liveness guarantees → Bond + slashing for missed reveals, fallback threshold revealers, and permissionless settlement calls so no one can grief the auction.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Acknowledgments

Happy building! 😄😊

About

Encrypt. Randomize. Equalize :: A stealth shield against MEV, encrypting trades and settling them fair

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •