All projects

Carmen Sandiego On-Chain

A fully decentralized mystery game where AI runs inside Chainlink CRE WASM workflows

CRE & AI

What it is

Carmen Sandiego On-Chain is a blockchain mystery game where the ENTIRE game logic — including AI content generation — runs decentralized inside Chainlink CRE.

THE PROBLEM: Every blockchain game today runs its fun parts (AI content, game logic, state updates) on centralized servers. The smart contract is just a scoreboard. One server goes down and the game dies. Who decides if your answer is right? A backend you can't audit.

HOW IT WORKS: We built 7 CRE workflows (~3,500 lines of TypeScript) that compile to WASM and execute inside the Chainlink DON. All nodes run identical bytecode, reach consensus, and deliver threshold-signed reports on-chain.

The game flow:

  1. Player starts a mission → VRF v2.5 generates a random location → CRE calls Groq LLaMA 3.3-70b (temperature=0) to generate a noir-style mission briefing, ECIES-encrypts it with the player's public key, and delivers it on-chain
  2. Player investigates cities across 4 chains → CRE evaluates each guess using commit-reveal cryptography (keccak256(chainId, salt) == targetHash), generates clues, and delivers encrypted results
  3. Carmen moves autonomously every 3 minutes via CronCapability
  4. Player captures Carmen → CRE generates an SVG trophy + ERC-721 metadata using AI, mints an on-chain NFT

Key innovation: The AI (LLM) runs INSIDE the decentralized oracle network. Every DON node executes the same prompt with temperature=0, produces identical output, reaches consensus, and the result is delivered with threshold signatures. No centralized backend. No trusted API. The game can't be shut down.

All 7 workflows compiled to WASM and successfully simulated via CRE CLI (10 batch runs, all passed). Full end-to-end demo completed on live Sepolia testnet in 4 minutes.

How it Works

ARCHITECTURE:

CRE Workflows (7 TypeScript → WASM modules, ~3,500 LOC):
• generate-briefing: LogTrigger → EVMClient reads Data Feed + mission state → HTTPClient calls Groq LLaMA 3.3-70b → ECIES secp256k1 encryption → writeReport delivers on-chain
• mission-start: LogTrigger → EVMClient reads mission + salt → brute-forces commit-reveal hash → generates encrypted clue → writeReport
• generate-finale: LogTrigger → HTTPClient calls Groq LLaMA for SVG trophy + ERC-721 metadata → writeReport sets tokenURI on-chain
• carmen-moves: CronCapability (every 3 min) → EVMClient reads active missions → relocates Carmen → writeReport
• player-registration: LogTrigger → validates nickname → registers player gaslessly → writeReport
• player-check: LogTrigger → reads player data → writeReport
• citynode-resolver: LogTrigger → resolves cross-chain CityNode requests back to GameMaster on Sepolia

Smart Contracts (Solidity 0.8.24, ~3,354 LOC, 65 tests):
• GameMaster.sol — VRFConsumerBaseV2Plus, commit-reveal (targetHash = keccak256(chainId, salt)), CCIP Router for cross-chain messaging, AggregatorV3 for ETH/USD pricing
• GameMasterProxy.sol — ReceiverTemplate for KeystoneForwarder, routes 11 CRE action types
• CityNode.sol — CCIPReceiver for cross-chain Carmen location updates
• MissionNFT.sol — ERC-721 with fully on-chain SVG data URIs (no IPFS)
• PlayerRegistry.sol — Player profiles + gasless CRE registration

Chainlink Services Used:
• CRE (Chainlink Runtime Environment) — 7 WASM workflows, EVMClient, HTTPClient, writeReport, LogTrigger, CronCapability
• VRF v2.5 — Provably fair random location assignment
• Data Feeds — Live ETH/USD pricing read inside CRE WASM
• CCIP — Cross-chain Carmen movement notifications
• Automation — CronCapability for autonomous Carmen relocation
• Keystone Forwarder — Threshold-signed report delivery

Multi-Chain Deployment:
• Sepolia (Hub) — GameMaster, PlayerRegistry, MissionNFT
• Arbitrum Sepolia — CityNode (Tokyo)
• XDC Apothem — CityNode (Sydney)

Frontend: React 19, Vite 7, Zustand, ethers.js v6, Privy (embedded wallet)
Encryption: ECIES secp256k1 (end-to-end clue privacy, keys stored in IndexedDB)
AI: Groq LLaMA 3.3-70b via HTTPClient inside CRE WASM (temperature=0 for DON consensus)
Tests: 124 passing (65 contracts + 59 frontend)

Links

Created by

  • Marco Túlio Rocha Nascimento
  • Juliano Sales
  • William Fabre
  • Geovane Cazal
  • João Augusto Perin de Souza