Skip to content

Repository files navigation

PrivateInfer Logo

πŸ”’ PrivateInfer

Secure, Trustless Off-Chain AI Inference Powered by Midnight Preview Network's Zero-Knowledge Proofs.

Next.js TypeScript Midnight Prisma TailwindCSS


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


πŸ’‘ About the Product Idea

❌ The Problem

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.

βœ… The Solution

PrivateInfer leverages the Midnight Preview Network to solve this problem by providing a trustless marketplace for secure, off-chain AI inference.

  1. Encrypted Inputs: The Query Maker (e.g., a Hospital) submits highly sensitive, encrypted data.
  2. 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).
  3. 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.
  4. Trustless Escrow: The smart contract automatically manages the escrow and releases the tDUST payment only when a valid proof is verified on-chain.

πŸ›‘οΈ Public State vs. Private Witness in PrivateInfer

PrivateInfer's smart contract (contracts/privateinfer.compact) expertly uses Midnight's programming model to separate what the network knows from what the network verifies.

🌐 Public State (On-Chain)

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.

πŸ•΅οΈβ€β™‚οΈ Private Witness (Off-Chain Execution)

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.

πŸ“Έ Product Screenshots

Here is the step-by-step visual flow of the PrivateInfer application:

1. Landing Page 2. Creating a Secure Query
Landing Page Add Query
3. Query Deployed Successfully 4. AI Provider Dashboard
Query Successful Provider Dashboard
5. Secure AI Result & Payment Release
Query Status

πŸ“œ Smart Contracts

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

πŸ”— Sample Midnight Preview Network Transactions

Contract Deployment & Verification Visuals

Below are the visual proofs of our smart contract deployed and actively managing state on the Midnight Preview Network:

1. Contract Details

Tracking the compiled privateinfer.compact contract and mapping it to the on-chain state.


2. Successful Contract Deployment

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


3. Zero-Knowledge Proof: Create Query

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


4. Zero-Knowledge Proof: Submit Result

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


5. Zero-Knowledge Proof: Release Payment

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


πŸ—οΈ Architecture & Workflow

Project Architecture

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
Loading

User-Side Workflow

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
Loading

πŸ“‚ File Structure

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)

πŸ§ͺ Testing

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

Test Cases Passing


πŸš€ Future Implementations & Real-World Application

Real-World Applications

  1. 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.
  2. Proprietary Financial Modeling: Hedge funds can run complex algorithmic trading models securely on decentralized computing networks without exposing their alpha-generating strategies.
  3. Enterprise Intellectual Property: Law firms and tech giants can summarize confidential contracts or source code without handing their IP over to centralized cloud providers.

Future Enhancements

  • 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.

πŸ™ Salutation

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! πŸ’œ

About

Secure, Trustless Off-Chain AI Inference Powered by Midnight Preview Network's Zero-Knowledge Proofs.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages