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
How the DePIN is Built
Actor-critic model handling continuous state adjustments (swap fees) to balance grid load and AMM depth without crashing the physical network.
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.
Inference & Settlement Pipeline
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)
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
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)
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
Challenges & Solutions
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).
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.
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.
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.
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.
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.