Inspiration

Directly sending sensitive personal credentials, age verification records, or raw API keys to centralized AI inference providers exposes users to serious privacy risks and data leakage. We built Midnight PromptGuard to create a verifiable, privacy-first boundary: users prove that their queries meet compliance, safety, and identity constraints through Zero-Knowledge proofs without ever revealing their private values or keys to the AI provider.


What It Does

  • Client-Side Witness Protection: Sensitive data (private user keys, exact age, and prompt safety metrics) stays strictly inside local browser memory.
  • Compact ZK Circuit Verification: Uses a Midnight Compact smart contract to mathematically verify: $$\text{age} \ge 18 \quad \land \quad \text{safetyScore} \ge \text{minSafetyScore} \quad \land \quad \text{key} \neq 0$$
  • Private AI Inference Gating: Passes only a cryptographic proof hash ($\pi$) to authorize execution on the inference engine, shielding raw user credentials completely.
  • On-Chain Ledger Tracking: Publicly increments verified query executions ($C_{\text{verified}} \leftarrow C_{\text{verified}} + 1$) on the Midnight Network ledger.

How We Built It

  1. Compact Smart Contract Circuit: Authored and compiled promptguard.compact using the Midnight Compact compiler (v0.34.0), defining private witness declarations and circuit-level assertion constraints.
  2. Interactive UI Dashboard: Built with Next.js 14 (App Router), TypeScript, and Tailwind CSS, featuring dark glassmorphic panels, real-time constraint validation badges, and interactive Compact concept explainers.
  3. Proof Execution Engine: Designed a client-side execution simulator mirroring the 3-step proof lifecycle (Local Witness commitment $\rightarrow$ Circuit constraint evaluation $\rightarrow$ Midnight ledger attestation).

Challenges We Overcame

  • Compact Type Coercion & Integer Bounds: Handling bounded integer additions in Compact (e.g., standard addition expanding type ranges) by implementing strict explicit type casts back to Uint<32>.
  • Zero-Knowledge UX Design: Designing an intuitive interface that clearly differentiates between data that remains strictly private locally versus public cryptographic attestations submitted to the network.

What We Learned

  • How to model privacy-preserving dApps using Midnight's unique private witness vs. public ledger architecture.
  • Writing domain-specific ZK constraints and compiling them into verifiable circuit representations (.zkir).

Accomplishments We're Proud Of

  • A complete, working zero-knowledge gated AI pipeline where user secrets are never transmitted.
  • Clean, modular architecture separating the on-chain Compact verification logic from the client UI.

Built With

  • ai-privacy
  • blockchain
  • compact
  • lucide-react
  • midnight
  • next.js
  • smart-contracts
  • tailwind-css
  • typescript
  • web3
  • zero-knowledge-proofs
  • zk-snarks
Share this project:

Updates

Submission history