close

🌌 MIDNIGHT-NEXUS

A Cryptographic Compliance Shield for AI β€” Built at the Midnight Blockchain Hackathon


What We Were Trying to Solve

AI is useful. It's also, in most enterprise deployments, a privacy disaster waiting to happen. You upload a patient record or a financial filing to get an insight, and suddenly that raw data is somewhere in a cloud pipeline you don't control.

The problem isn't the AI. It's that we've built AI pipelines around a simple but flawed assumption: the model needs to see the data to reason about it.

That assumption is wrong. And MIDNIGHT-NEXUS is our attempt to prove it.

The idea: let AI reason over facts about data, not the data itself. A doctor doesn't need to hand over a patient file to prove that person is over 18. A bank doesn't need to expose an account balance to prove it clears a threshold. Zero-knowledge proofs have made this kind of attestation cryptographically sound for years. We just hadn't wired them to AI yet.


How the System Works

The core flow looks like this:

Raw Private Data (stays local)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Local ZK Prover        β”‚  ← Compact Language circuit runs on-device
β”‚  (sub-second compile)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚  Proof Token
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Midnight Blockchain    β”‚  ← State commitment anchored on-chain
β”‚  (Consensus Register)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚  Anchored Hash
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  AI Verifier Layer      β”‚  ← Reads proof tokens, not raw data
β”‚  (Proof-Aware Inference)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
    Certified Compliance Insight
    (zero raw bytes ever touched)

The math at the heart of this:

$$P(\text{statement} \mid \text{proof}) \implies \text{valid}$$

We generate a \(\text{proof}\) that a \(\text{statement}\) about private data holds β€” without exposing the underlying data at all. The AI consumes that proof token, verifies it against the blockchain anchor, and produces an insight. At no point does it see what the statement is about.


Architecture at a Glance

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   MIDNIGHT-NEXUS                         β”‚
β”‚                                                          β”‚
β”‚  Frontend (Next.js + TypeScript)                         β”‚
β”‚      β”‚                                                   β”‚
β”‚      β”œβ”€β”€ ZK Circuit Layer (Compact Language)             β”‚
β”‚      β”‚       └── Local WASM prover sandbox               β”‚
β”‚      β”‚                                                   β”‚
β”‚      β”œβ”€β”€ Blockchain Bridge (Midnight SDK)                β”‚
β”‚      β”‚       └── State commitments β†’ mainnet ledger      β”‚
β”‚      β”‚                                                   β”‚
β”‚      β”œβ”€β”€ AI Verifier (OpenAI inference layer)            β”‚
β”‚      β”‚       └── Reads: proof tokens                     β”‚
β”‚      β”‚       └── Outputs: compliance insights            β”‚
β”‚      β”‚                                                   β”‚
β”‚      └── UI (Spline 3D + Framer Motion + shadcn)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech used:

  • Next.js + TypeScript β€” application shell
  • Compact Language β€” ZK circuit definition and compilation
  • Midnight SDK β€” blockchain state anchoring
  • openai β€” proof-aware AI inference
  • @splinetool/react-spline + framer-motion β€” 3D and animation
  • shadcn + lucide-react β€” UI components

Data Privacy: Traditional AI vs MIDNIGHT-NEXUS

Here's what actually changes:

TRADITIONAL AI PIPELINE
━━━━━━━━━━━━━━━━━━━━━━
User β†’ [Raw Data] β†’ Cloud API β†’ AI Model β†’ Insight
                        ↑
               Data leaves your hands here.
               You have no idea where it goes.


MIDNIGHT-NEXUS PIPELINE
━━━━━━━━━━━━━━━━━━━━━━
User β†’ [Raw Data] β†’ Local ZK Prover β†’ [Proof Token] β†’ Blockchain Anchor
                         ↑                                    ↓
               Data never leaves device.          AI reads proof, not data.
                                                        ↓
                                              Verified Insight

The key property: the proof token is computationally binding but semantically opaque. An observer can verify the proof is valid without learning anything about what it proves.


What We Learned

Three things genuinely surprised us during the build.

1. Compact Language is a different way of thinking. Writing ZK circuits in Compact isn't like normal programming. You're not describing what to compute β€” you're describing what constraints must hold. It took a while to stop thinking procedurally and start thinking in terms of witnesses and assertions.

2. The AI integration was the hardest part β€” and not for the reasons we expected. We assumed the blockchain integration would eat most of our time. It didn't. The hard problem was getting the AI layer to treat proof tokens as meaningful inputs rather than opaque blobs. We had to redesign how we represented the proof structure in the prompt context.

3. Sub-second local ZK compilation is genuinely achievable. WASM provers are fast now. We were surprised how close to interactive performance we got. The main cost is circuit size β€” keeping circuits lean pays off immediately.


What We Built, Step by Step

# 1. Compile ZK circuits locally
npx compact compile src/circuits/proof.compact

# 2. Run the local proving pipeline
npm run nexus-start

The flow from there:

  1. User supplies private data (locally, never transmitted)
  2. Compact circuit compiles and generates a proof token
  3. Proof token + minimalist state hash gets anchored to the Midnight mainnet
  4. AI verifier reads the token, cross-checks the chain anchor, returns an insight
  5. User gets a compliance result. No raw data ever left step 1.

Honest Challenges

The crypto-AI interface was messier than we expected. ZK circuits and AI inference engines don't speak the same language. Getting a proof token into a form the AI could actually reason about β€” not just acknowledge β€” meant going back to circuit design multiple times.

Time. 48 hours is not a lot of time to learn the Midnight SDK, design circuits, build an AI verifier, and ship a frontend with 3D visualizations. We cut a few features we wanted. The decentralized proof registry is rougher than we'd like.

Making this explainable. Zero-knowledge proofs are genuinely hard to explain. We used Spline and Framer Motion partly because we needed something visual to show what's happening without drowning people in math. It helped, but we still think the UX explanation layer has a lot of room to grow.


What's Next

The prototype proves the concept works. A few things we didn't finish that we want to:

  • A richer proof registry UI with historical audit trails
  • Support for more complex circuit types (range proofs, set membership)
  • Formal benchmarking of circuit compilation time vs. proof complexity
  • A developer SDK so others can build proof-aware AI features without re-implementing the whole stack

Team

Built at the Midnight Blockchain Hackathon in 48 hours.

Built With

Share this project:

Updates