Polycourt - AI judge
Trustless AI dispute resolution. Cryptographically verifiable for a sovereign internet.
Problem Statement
Polycourt.xyz: Trustless Multi-LLM Dispute Resolution on TEE — For a Sovereign Internet Polycourt is a trustless AI judge system that resolves contractual disputes without relying on centralized authorities or trusted operators. The system queries multiple independent AI providers (Claude, Gemini, Perplexity, OpenAI, Grok) concurrently and aggregates their responses using weighted voting to determine which party is correct based on contract terms and evidence. What makes it sovereign and secure: The system runs on Oasis ROFL (Trusted Execution Environment), providing cryptographic guarantees that eliminate single points of trust.Zero operator trust: Service operators cannot manipulate results. All execution happens inside a hardware-enforced TEE, making code tampering cryptographically impossible.Cryptographic verification: Every response is signed using SECP256K1 keys generated inside the TEE. Public keys are verifiable against on-chain attested state, proving response authenticity without trusting any party.Verifiable execution: Remote attestation cryptographically proves the exact Docker image running in the TEE matches the open-source repository. Anyone can independently verify the code execution matches the source code.No single point of failure: The multi-provider consensus architecture means no single AI provider controls the outcome. Even if one provider is compromised or biased, the weighted voting system ensures fair aggregation.Reproducible builds: Docker images are built reproducibly, allowing anyone to verify the deployed code matches the repository through cryptographic digests.Technical architecture: Concurrent queries to 5+ LLM providers acting as independent judges (mockup for MVP) Weighted voting system with configurable thresholds All responses cryptographically signed inside the TEE Public key verification against on-chain ROFL registry Open-source, fully auditable codebase x402 micropayments for pay-per-dispute access (mockup for MVP)Use cases: Smart contract dispute resolution (escrow, freelancer platforms) DAO governance decisions requiring evidence evaluation Automated contract enforcement without centralized arbitrators Censorship-resistant dispute resolution for protocolsThis is a real contribution to a sovereign internet because it enables trustless dispute resolution that cannot be censored, compromised, or manipulated by operators or centralized authorities. The combination of TEE-based execution, cryptographic signatures, and multi-provider consensus creates a system where users can verify everything themselves—no trust required.
Solution
Technical Architecture & Implementation Details Core Stack: Backend: FastAPI (Python 3.12) with async/await for concurrent LLM queries Task Queue: Huey with SQLite for background job processing (separate server/worker containers) Database: SQLite via Huey for job storage and metadata Frontend: Vanilla JavaScript with Vite, using x402-fetch and viem for wallet integration Containerization: Reproducible Docker builds with pinned Debian snapshots and SOURCE_DATE_EPOCH for deterministic builds Partner Technologies & Integration: Oasis ROFL (TEE): Runs in Intel TDX TEE. Uses oasis-rofl-client for: Key generation via ROFL keymanager (SECP256K1 keys generated inside TEE) Cryptographic signing of all responses using coincurve library Remote attestation proving exact code execution Metadata sync to ROFL registry for public key verification x402 Protocol: Micropayments via Coinbase CDP facilitator: Custom async-settlement middleware to avoid proxy idle timeouts (returns 200 immediately, settles in background) Retry logic with exponential backoff for 404s during settlement Browser paywall HTML for wallet payments API client support via X-PAYMENT header Agent0 SDK: Service discovery and registration on Base Sepolia: Auto-registers x402 endpoints on startup IPFS metadata via Pinata for agent discovery Single-worker lock to prevent duplicate registrations Architecture Highlights: Server/Worker Separation: Two-container architecture (compose.yaml): Server container: FastAPI handles HTTP, payment verification, job creation, health checks Worker container: Huey workers process LLM queries, generate signatures, update job results Shared SQLite database via Docker volume for job coordination Concurrent LLM Queries: Uses asyncio.gather() to query 5+ providers in parallel: Each provider wrapped in _safe_query() with per-provider error isolation Continues even if 2 providers fail (fails only if >2 fail) Weighted voting aggregates responses with configurable provider weights Background Processing Flow: Payment verified via x402 middleware → job created in database Settlement callback (on_settlement_success) queues Huey task Worker picks up task, queries all LLMs concurrently Results aggregated via weighted scoring Response signed using TEE-generated key Job status updated in database Notable Hacks & Solutions: Async Settlement Middleware (x402_custom_middleware.py): The x402 library blocks on settlement, causing 6+ second responses that hit proxy timeouts. Solution: Custom middleware that verifies payment, returns 200 immediately, then settles asynchronously via asyncio.create_task(). Includes retry logic (5 attempts with exponential backoff) for 404s when facilitator hasn't registered payment yet. Reproducible Docker Builds: For cryptographic verification, Docker images must be bit-for-bit reproducible. Used: Pinned Debian snapshot archives (DEBIAN_SNAPSHOT=20250815T025533Z) SOURCE_DATE_EPOCH for deterministic timestamps find . -exec touch -d @${SOURCE_DATE_EPOCH} to normalize all file timestamps Disabled debug symbols (CFLAGS="-g0") to avoid randomized paths CI/CD verifies SHA256 digest matches between local builds and deployed images Single-Worker Initialization Lock: Multiple worker containers would race to initialize ROFL signing service and register with Agent0. Solution: File-based lock (_acquire_init_lock()) ensures only primary worker initializes, others skip gracefully. TEE Signing Integration: ROFL keymanager generates keys inside TEE, but signing happens in Python. Used coincurve library to sign canonical JSON (excluding signature/public_key fields) with recoverable ECDSA signatures. Public keys stored in database metadata and synced to ROFL registry every minute for on-chain verification. Error Isolation: Each LLM provider wrapped in try/catch with per-provider error handling. Failed providers return LLMResponse with error field set, allowing aggregation to continue with remaining providers. Only fails if >2 providers fail (configurable threshold). Data Flow: User → Frontend (x402-fetch) → FastAPI Server → x402 Middleware (verify) → Job Store (SQLite) → Settlement Callback → Huey Queue → Worker → Oracle (async gather 5 LLMs) → Weighted Scorer → Signing Service (TEE) → Job Store Update → User polls /query/{job_id} → Returns signed result Deployment: ROFL app deployed on Oasis Sapphire mainnet with TDX TEE, 8GB RAM, 4 CPUs, 35GB persistent storage. Uses rofl.yaml manifest with pinned firmware/kernel hashes for attestation verification.
Hackathon
ETHGlobal Buenos Aires
2025
Contributors
- ptrus
25 contributions
- zevictordantas
12 contributions