Inspiration
Modern web applications frequently require users to prove their eligibility—such as verifying they are 18+ for age-restricted services, or confirming an active VIP/professional membership. Today, this requires users to upload raw dates of birth, identity card scans, and government IDs over standard HTTP requests.
This creates a massive privacy dilemma: centralized servers and database logs store sensitive Personally Identifiable Information (PII) indefinitely, exposing users to identity theft and burdening companies with severe GDPR, CCPA, and data breach liabilities.
We were inspired by Midnight's zero-knowledge privacy architecture to solve this problem at its root. We asked ourselves: Why should an API need to know your exact birthday or identity when all it really needs is a verifiable cryptographic true?
## What it does
Midnight ZK Gatekeeper upgrades legacy Web2 APIs and authentication endpoints into privacy-preserving zero-knowledge gatekeepers:
- Client-Side ZK Evaluation: When a user encounters an age or credential gate, their device evaluates their private data (e.g., date of birth and private user salt) locally using a Midnight Compact smart contract circuit.
- Succinct Proof & Nullifier Generation: The circuit verifies that the user's credential matches a trusted issuer anchor and satisfies the threshold (e.g., current_year - birth_year >= 18). It generates a succinct Zero-Knowledge Proof along with a one-time session nullifier.
- Zero-PII API Verification: The existing Web2 API receives only the cryptographic proof payload. It mathematically verifies access authorization without ever seeing, transmitting, or storing the user's date of birth, name, or private secrets.
- Anti-Replay Protection: Built-in nullifier state tracking prevents malicious actors from intercepting and reusing proof artifacts.
## How we built it
• Midnight Compact Smart Contract (gatekeeper.compact): Wrote the core zero-knowledge circuit logic in Midnight's domain-specific Compact language. It enforces cryptographic commitment anchors, evaluates chronological inequality constraints on private witnesses, and generates deterministic session nullifiers. • Midnight Prover & Verifier Bridge (src/midnight_zk_bridge.ts): Implemented a TypeScript engine simulating client-side witness proving and server-side verification against public state. • Side-by-Side Upgrade CLI (src/index.ts): Built an interactive terminal application demonstrating the exact transition from an insecure legacy Web2 API (leaking raw PII) to the upgraded Midnight ZK privacy flow. • Automated Verification Suite (test/gatekeeper.test.ts): Created 6 comprehensive unit tests covering eligible adults, underage rejections, tampered SNARK proof detection, replay prevention, and strict zero-leak privacy audits.
## Challenges we ran into
- Bridging Web2 API State with Stateless ZK Proofs: Web2 services typically rely on persistent sessions tied to user accounts. We solved this without compromising anonymity by introducing ephemeral, year-scoped session nullifiers into the Compact circuit, enabling APIs to prevent replay attacks without tracking user identity across platforms.
- Modeling Compact Witness Constraints: Ensuring private witnesses (secret_birth_year, secret_user_salt) remained strictly local to the client execution environment while ensuring the public verifier could validate authenticity against trusted credential anchors.
## Accomplishments that we're proud of
• Working End-to-End ZK Pipeline: Built a fully functioning Zero-Knowledge proof generation and verification flow with 100% passing test coverage. • Zero Privacy Leakage: Validated through automated privacy audits that zero private witness entropy leaks into public transaction payloads or server logs. • Seamless Upgrade Path: Demonstrated how an existing application can upgrade its security model without rewriting its entire backend infrastructure.
## What we learned
• The Power of Midnight & Compact: We gained practical experience with Midnight's dual private/public state execution model and how domain-specific ZK languages like Compact drastically simplify writing secure cryptographic circuits. • Decoupled Privacy Architecture: We learned that user data sovereignty and corporate compliance don't have to be mutually exclusive—zero-knowledge technology can satisfy strict regulatory standards while keeping user data private.
## What's next for midnight-zk-gatekeeper
• Testnet & Devnet Deployment: Deploy the Compact contract directly onto the Midnight Testnet using the Midnight TypeScript SDK and indexing nodes. • Drop-in Middleware Library: Publish an open-source @midnight/zk-gatekeeper npm package providing plug-and-play Express, Fastify, and Next.js middleware. • W3C Verifiable Credentials Integration: Extend the circuit to verify decentralized identity credentials (DID) and multi-issuer trust federations.
Built With
- javascript
- midnight
- typescript