Secure, Trustless Off-Chain AI Inference Powered by Midnight Preview Network's Zero-Knowledge Proofs.
Important
Network Notice: This application and its smart contracts are currently deployed exclusively on the Midnight Preview Network. All transactions, zero-knowledge proofs, and escrow mechanisms occur on the Preview testnet environment.
π Live Deployment | π₯ Demo Video | π X Profile
Quick Links: Setup Guide β’ Usage Guide β’ Project Proposal
As AI becomes integral to enterprise operations, industries dealing with highly sensitive data (like Healthcare, Finance, and Legal) face a massive roadblock: Data Privacy. If a hospital wants to use an advanced AI model to analyze a patient's medical history for early disease detection, they cannot simply send this data to a public LLM like ChatGPT or put it on a public blockchain. Doing so exposes confidential data, violates compliance laws (like HIPAA), and destroys user trust.
PrivateInfer leverages the Midnight Preview Network to solve this problem by providing a trustless marketplace for secure, off-chain AI inference.
- Encrypted Inputs: The Query Maker (e.g., a Hospital) submits highly sensitive, encrypted data.
- Secure Processing: A decentralized AI Provider Node picks up the task and processes the data strictly inside a secure "black box" (a Trusted Execution Environment / TEE).
- Zero-Knowledge Proofs: The AI Provider submits the result back to the Midnight smart contract along with a ZK-Proof. This mathematically guarantees to the hospital that the AI model was run exactly as requestedβwithout ever revealing the patient's data or the result on the public ledger.
- Trustless Escrow: The smart contract automatically manages the escrow and releases the tDUST payment only when a valid proof is verified on-chain.
PrivateInfer's smart contract (contracts/privateinfer.compact) expertly uses Midnight's programming model to separate what the network knows from what the network verifies.
The public state only tracks opaque identifiers, cryptographically secure hashes, and escrow balances.
- Query Commitment Hash: The hash of the encrypted input data (preventing tampering).
- Result Hash: The hash of the final AI inference output.
- Statuses: State machine markers (e.g., Processing, ResultReady, Paid).
- Escrow: The locked tDUST reward.
The actual sensitive data is handled strictly as private witnesses during local circuit execution.
- Caller Identity: We assert disclose(caller) == query.creator inside local circuits to prevent unauthorized users from releasing payments, but the network only validates the proof, never exposing the caller's identity publicly.
- AI Payload: The actual prompt and the AI's response remain entirely off-chain. The ZK-proof simply proves that the hash of the local result matches the commitment on-chain.
Here is the step-by-step visual flow of the PrivateInfer application:
| 1. Landing Page | 2. Creating a Secure Query |
|---|---|
![]() |
![]() |
| 3. Query Deployed Successfully | 4. AI Provider Dashboard |
|---|---|
![]() |
![]() |
| 5. Secure AI Result & Payment Release |
|---|
![]() |
Our compact smart contract securely manages the escrow lifecycle, enforces state transitions, and verifies Zero-Knowledge proofs for AI inference.
Main Contract Address (Midnight Preview Network): f8aa07189746565ff037f4c0e37e2d4da99424d0aff92a62344325a499533992
- π’ Create Query: ab8607371723...
- π‘ Submit Result & Proof: c7dfa24e3f66...
- π΅ Release Payment: 8ab94e92e295...
Below are the visual proofs of our smart contract deployed and actively managing state on the Midnight Preview Network:
Tracking the compiled privateinfer.compact contract and mapping it to the on-chain state.

Proof of the PrivateInfer escrow contract initialized on the Midnight Preview Network.

Proof of a successful transaction securely modifying the public state to deploy the query.

Proof of the AI Provider securely submitting the Zero-Knowledge verified result back to the network.

Escrow payment release, verified by the private caller witness securely on-chain.

graph TD
UI[Next.js Client UI] -->|Connects via| Wallet[Lace Wallet]
UI -->|Polls Metadata| DB[(Neon PostgreSQL DB)]
Wallet -->|Submits ZK Proofs & Txs| Midnight[Midnight Preview Network]
Midnight -->|Verifies Proofs| SC[Compact Smart Contract]
ProviderNode[AI Provider Node - TEE] -->|Reads Hash| Midnight
ProviderNode -->|Pushes Off-chain Data| DB
ProviderNode -->|Submits Result ZKP| Midnight
sequenceDiagram
participant U as User (Query Maker)
participant SC as Midnight Smart Contract
participant P as AI Provider (TEE)
U->>SC: 1. Deploy Query (Lock tDUST, Commit Hash)
SC-->>P: 2. Network Emits Event
P->>P: 3. Decrypt & Run AI Inference inside TEE
P->>SC: 4. Submit ZK Proof & Result Hash
SC->>SC: 5. Verify Proof (State -> RESULT_READY)
U->>SC: 6. Verify Result & Release Payment
SC-->>P: 7. Transfer tDUST Escrow to Provider
PrivateInfer/
βββ contracts/ # Midnight Compact Smart Contracts
β βββ privateinfer.compact # Core logic for ZK verification & Escrow
β βββ managed/ # Compiled TS/WASM outputs from Compact compiler
βββ prisma/ # Database Schema & Migrations
β βββ schema.prisma # Postgres models (Query, Provider, Result)
βββ src/
β βββ app/ # Next.js App Router (Frontend + API Routes)
β β βββ query/ # Query Maker UI flows (Create, Status tracking)
β β βββ provider/ # AI Provider Dashboard UI
β β βββ api/ # Backend API for syncing off-chain metadata
β βββ components/ # Reusable UI components (shadcn/ui)
β βββ contexts/ # React Contexts (Wallet connection state)
β βββ lib/ # Utility functions (crypto, DB client)
βββ scripts/ # Admin scripts (e.g., deploying the contract)
βββ .github/workflows/ # CI/CD pipelines (Lint, Typecheck, Smart Contract Build)
The project uses Jest for robust unit testing of our core cryptographic and parsing logic. We've ensured that sensitive operations (like parsing 1AM Wallet public keys into Uint8Array byte buffers for the ZK circuits) are 100% reliable and edge-case secure.
To run the test suite locally:
οΏ½ash npm install npm test
- Medical AI: Hospitals can use PrivateInfer to get AI-driven diagnoses on highly sensitive patient records without violating HIPAA. The ZK-proof guarantees the AI didn't hallucinate the result, and the privacy guarantees the data wasn't leaked.
- Proprietary Financial Modeling: Hedge funds can run complex algorithmic trading models securely on decentralized computing networks without exposing their alpha-generating strategies.
- Enterprise Intellectual Property: Law firms and tech giants can summarize confidential contracts or source code without handing their IP over to centralized cloud providers.
- Dynamic ZK-VM Integration: Integrating a complete Zero-Knowledge Virtual Machine so the provider can prove the entirety of an LLM execution trace.
- Reputation System: Implementing an on-chain staking and slashing mechanism for providers who consistently fail to submit results within a given timeframe.
- Multiparty Computation (MPC): Splitting the AI inference across multiple nodes for even higher security guarantees.
A massive thank you to the Midnight Network team! The ability to seamlessly blend public state verification with private local execution using compact is game-changing. This platform allowed us to build an enterprise-grade privacy product that would be completely impossible on traditional blockchains. Thank you for building the future of data protection! π





