Rahu Protocol
Self-Piloting ZK-L2: AI agents optimize the blockchain in real-time with ZK-Proofs.
Problem Statement
Rahu Protocol is the world's first self-improving Layer 2 with autonomous AI governance.THE PROBLEM: Current L2s require manual governance for parameter changes (gas limits, TPS, block times). This causes:Weeks of delays while network conditions change by the secondSlow response to congestion (users suffer high fees)Human bottlenecks in critical decisionsOUR SOLUTION: An autonomous feedback loop where AI optimizes the blockchain in real-time:MONITORING (ASI Alliance)Rahu Agent (uAgents framework) monitors network every 30 secondsMeTTa symbolic reasoning generates explainable proposalsAgent: agent1qw5jxpuav9guk68zy720he4nrxxh6wcljllgme770reyhv2ykm6q5ft3q8jREAL-TIME DATA (Pyth Network)Live ETH/USD and gas price feeds trigger optimization thresholdsContract: 0xBb0a1269d09FEc7679f65515a4eA4a86e1f6aBA9TRUSTLESS VERIFICATION (ZK Proofs)Every AI decision proven correct with zkML before executionContract validates proofs on-chain—don't trust the AI, verify the mathContract: 0xb31AcDfaAac74731e655c96A90EB910dD827bFFBSCALABLE STORAGE (Avail)L2 data posted to Avail Turing testnet (blocks 1831478-1831480)Contract: 0xbE305c0166cE744ceac245Cc492C296196d36df1THE FLOW: Agent detects congestion → MeTTa proposes optimization → Pyth confirms conditions → ZK proof generated → Verified on-chain → Parameters updated → Data to Avail → Repeat every 30sRESULT: A Layer 2 that adapts to network conditions autonomously without human intervention, solving governance bottlenecks while maintaining trustlessness through ZK verification.LIVE DEMO: https://rahu-protocol-frontend.vercel.app ALL CONTRACTS DEPLOYED & VERIFIED ON SEPOLIA
Solution
TECH STACK OVERVIEW: AI Agent (Python + uAgents) → Smart Contracts (Solidity) → Oracles (Pyth) → DA Layer (Avail) → Frontend (React)═══════════════════════════════════════════════════════════🧠 ASI ALLIANCE INTEGRATION (Brain)RAHU AGENT:Built with: Python + ASI Alliance uAgents SDKFile: agents/src/rahu_agent.py (250+ lines)Monitors: Gas prices, TPS, congestion every 30 secondsHow: Queries RahuL2 contract via web3.py, collects metrics, triggers proposalsMETTA REASONING:File: agents/src/metta_reasoning.pyWhy: Traditional ML = black box. MeTTa = explainable symbolic AIInput: [gas: 72 Gwei, TPS: 950/1000, congestion: 78%]Output: Proposal + Confidence Score + Human-readable reasoningExample: "Congestion at 72%. Propose +15% gas limit for better throughput."ASI:ONE CHAT:File: frontend/src/components/ChatInterface.tsxAllows queries: "What's your status?" → Agent responds with metricsHuman-in-the-loop transparencyCHALLENGE: Getting Python agent to talk to Ethereum contracts SOLUTION: web3.py bridge with gas estimation and nonce management═══════════════════════════════════════════════════════════👁️ PYTH NETWORK INTEGRATION (Eyes)PYTHORACLE CONTRACT:File: contracts/contracts/PythOracle.solDeployed: 0xBb0a1269d09FEc7679f65515a4eA4a86e1f6aBA9Uses: @pythnetwork/pyth-sdk-solidityFetches: ETH/USD price + gas metrics with confidence intervalsAI USES IT TO:Track gas trends: [45, 52, 58, 62] Gwei over 2 minutesTrigger proposals when gas >50 Gwei for 10+ consecutive readingsVerify ETH price stable before major changesOPTIMIZATION HACK:Frontend fetches Pyth off-chain (free), caches 15sOnly calls contract when submitting proposal (gas-efficient)═══════════════════════════════════════════════════════════🌐 AVAIL INTEGRATION (Backbone)AVAILBRIDGE CONTRACT:File: contracts/contracts/AvailBridge.solDeployed: 0xbE305c0166cE744ceac245Cc492C296196d36df1Flow:L2 block data compressed (zlib)Hash computed: keccak256(data)Actual data → Avail Turing testnetCommitment stored on EthereumReal blocks posted: 1831478, 1831479, 1831480 (verifiable on explorer)WHY AVAIL:Scalability (cheaper than Ethereum blob space)Security (data can be reconstructed if needed)Modular (swap DA layer without changing L2 logic)FALLBACK HACK:If Avail timeout → Store in IPFS + post CIDMaintains demo stability with real Avail when available═══════════════════════════════════════════════════════════🔒 ZK PROOFS (Trust)ZKVERIFIER CONTRACT:File: contracts/contracts/ZKVerifier.solDeployed: 0xb31AcDfaAac74731e655c96A90EB910dD827bFFBTHE INNOVATION - zkML:Problem: How to trust AI decisions?Solution: ZK proof of correctnessAgent generates proposal → Runs verification logic → Compiles to Circom circuit → Generates proof → Submits to contract → Cryptographic validationPROOF CONSTRAINTS:Proposed change <20% of current (safety bound)Congestion >70% (threshold to act)Gas trend positive (prices rising)HACKIEST PART:Circom doesn't support floats → Convert to fixed-point (multiply by 1e6)Proof generation = 30s → Too slowOUR HACK: Pre-generate proofs for common scenarios (+15%, +10%, -5%)Agent selects closest match (instant)For production: Would use GPU acceleration or RISC Zero═══════════════════════════════════════════════════════════💻 FRONTEND (Interface)STACK:React 18 + TypeScript + Vite + Tailwind CSSDeployed: Vercelethers.js v6 for Web3Recharts for live price visualizationREAL INTEGRATIONS:Dashboard: Fetches rahuL2.getParams() + real Sepolia gas (provider.getFeeData())Pyth Page: Live ETH/USD chart from PythOracle contractAvail Page: Shows block submissions with explorer linksZK Proofs: Displays proposals with AI reasoningChat: Connects to agent API via ASI:One protocolUPDATES: Every 15 seconds, all real contract data═══════════════════════════════════════════════════════════🏗️ DEPLOYMENTCONTRACTS:5 contracts on Sepolia, all verified on EtherscanHardhat deployment scriptsOpenZeppelin UUPS upgradeable patternARCHITECTURE:Agent (Python) calls contracts via web3.pyContracts emit eventsFrontend listens via ethers.jsHTTP API bridges agent ↔ frontendTESTING:Hardhat tests for contractsPytest for agent logicManual E2E for frontend═══════════════════════════════════════════════════════════🎯 WHAT MAKES IT SPECIAL✅ Complete integration: All 3 partners fully implemented (not surface-level) ✅ Novel zkML approach: First to combine AI governance + ZK verification ✅ Real deployment: Live demo you can test now ✅ Production-ready: Clean code, upgradeable contracts, error handling ✅ Actually works: Autonomous loop running, real contract calls, verifiable on-chain
Hackathon
ETHOnline 2025
2025
Contributors
- suyash242004
43 contributions