03 // Web3 · DePIN · Applied RL 2025

Gridium Protocol

A team-built DePIN microgrid prototype integrating a simulated 15-node energy network, an EVM AMM, a PyTorch Deep Deterministic Policy Gradient (DDPG) agent, and a Groth16 proof flow.

500msPhysics Tick Rate
zk-SNARKGroth16 Proofs
DDPGActor-Critic RL
15Simulated Nodes
Overview

Traditional power grids are monolithic and brittle. As residential solar panels and batteries proliferate, the legacy grid struggles. Prosumers sell surplus energy back to utilities at wholesale pennies, but unmanaged peer-to-peer trading causes grid instability and severe physical privacy risks (ledgers revealing home occupancy).

Gridium operates at the intersection of AI, cryptography, and DeFi. It uses an Automated Market Maker for simulated energy liquidity, a continuous-control RL agent for fee adjustment, and a proof-of-surplus flow that demonstrates how raw telemetry could remain off-chain.

Team contribution: I focused on the Python AI engine, backend integration, and 3D visualization. Yash Pandit led smart contracts and zero-knowledge implementation; Sanket Deka worked on frontend and UI/UX.

Tech Stack & MLOps

🐍Python / FastAPI (Engine)
🤖PyTorch (DDPG Agent)
🟢Node.js / Socket.io (Gateway)
🔐SnarkJS / Circom (zk-SNARKs)
🌐React Three Fiber (Command Center)
🐳Docker / Render PaaS
⚙️ System Architecture

How the DePIN is Built

RL Engine (Python)
PyTorch DDPG · Physics Sim
🌐
Gateway (Node)
Socket.io Fan-out · snarkJS proofs
🖥️
Command Center
React Three Fiber · Zustand State
⛓️
Blockchain (EVM)
Solidity AMM · Groth16 Verifier
🤖
DDPG Reinforcement Learning

Actor-critic model handling continuous state adjustments (swap fees) to balance grid load and AMM depth without crashing the physical network.

🔒
ZK Architecture

Circuits compiled via circom. Outputting .wasm artifacts so the Node gateway computes Groth16 proofs representing off-chain node generation deltas, verified on-chain via Solidity.

Data Flow

Inference & Settlement Pipeline

01

Physics Engine Tick (500ms)

At tick t, the Python Engine builds an Observation State containing grid load, generation, energy reserves, and battery SoC. The DDPG Actor network outputs a continuous swap fee modifier to stabilize the system.

PyTorch Inference: S_t → DDPG Actor → A_t (Swap Fee)
02

Gateway State Broadcast

The Node.js Gateway polls the AI engine via REST (`/tick`) and broadcasts the high-frequency state via WebSockets to connected React frontends utilizing Zustand for 60fps 3D rendering.

FastAPI → Gateway → Socket.io Fan-out
03

Off-Chain ZK Proof Generation

When a prosumer trades energy, physical telemetry is NOT broadcasted. The Node Gateway securely computes a Groth16 zk-SNARK proof asserting mathematical relationships (e.g. Generation > Load) without exposing localized load data.

snarkjs.groth16.fullProve(signals, wasm, zkey)
04

On-Chain verifiable AMM Settlement

The cryptographically generated proof is submitted to the EVM blockchain. The `SurplusVerifier` smart contract validates the proof on-chain in milliseconds. If valid, the trade settles against the `AegisAMM` using the x*y=k invariant.

Verifier.sol → require(verifyProof(a,b,c,input)) → AMM Swap
DevOps & MLOps Problems Solved

Challenges & Solutions

Problem

Event Loop Blocking during ZK Proofs

Generating Groth16 proofs in Node.js is CPU-intensive. Initially, proof generation halted the v8 event loop, causing massive latency spikes (lagging WebSockets under load).

Solution

Decoupled Computation Architecture

Offloaded the PyTorch RL inference to a distinct containerized FastAPI microservice. The Gateway acts purely as a router, and ZK execution is parallelized utilizing Node `worker_threads` to keep the Socket.io tick running cleanly.

Problem

Discrete Action Spaces in Financial Systems

Initial attempts using a DQN (Discrete Q-Network) failed. Discretized fee "buckets" (e.g. 1%, 2%, 3%) caused severe market shocks, creating arbitrage loops that drained the AMM.

Solution

Continuous Control via DDPG

Deployed Deep Deterministic Policy Gradients (DDPG) — an actor-critic algorithm that natively supports continuous action spaces. The agent acts like a steering wheel rather than a simple switch, executing granular fee adjustments.

Problem

WebSocket Avalanches & Thundering Herds

A backend restart can cause every connected frontend client to retry at the same moment, amplifying load while the WebSocket gateway is still recovering.

Solution

Exponential Backoff with Jitter

Implemented a resilient reconnection algorithm on the React client. Clients wait progressively longer (2s, 4s, 8s) combined with randomized jitter, naturally smoothing out the spike to allow the Node server to recover.