The Middn whitepaper.
How Middn actually works under the hood. Smart contracts, ZK circuits, encryption, audits — everything we built, and how to verify it yourself.
Architecture overview
Middn is a P2P trading protocol built on three pillars: smart contracts that hold the funds, zero-knowledge proofs that verify conditions privately, and an AI agent that guides users through the flow. Every component is non-custodial and verifiable on-chain.
The flow at 10,000 feet
A Middn trade goes through 4 phases — each enforced by code, not by a backend service. There is no Middn server holding state in between.
Unlike a CEX, Middn has no order book, no matching engine, no custody layer. It's a protocol, not an exchange — closer to how Uniswap relates to Coinbase.
Smart contracts
The core of Middn is a set of atomic swap contracts built on HTLC primitives. Each trade deploys a new escrow instance (or registers in a singleton factory, depending on chain). Once deployed, the contract is immutable — neither we nor anyone else can modify it.
The escrow contract
A simplified version of the escrow logic:
Key properties
- Immutable — once deployed, the contract logic cannot be changed. No admin keys, no proxy upgrades.
- Atomic — settlement is all-or-nothing. Both transfers happen in the same transaction or neither does.
- Refundable — if conditions aren't met before the timeout, both sides can withdraw their deposits.
- Self-contained — no oracle dependency for settlement. The proof itself is sufficient.
Zero-knowledge proofs
Middn uses Groth16 zk-SNARKs to let users prove trade conditions are valid without revealing the underlying data. Amounts, identities, balances, conditions — everything stays private. The chain only sees a 192-byte proof.
Circuits we use
- conditionCheck — proves all trade conditions are satisfied without revealing them.
- balanceProof — proves a user has sufficient balance without exposing the amount.
- complianceProof — proves KYC status (when applicable) without leaking documents.
We chose Groth16 over PLONK/Halo2 for verification cost: ~280k gas per proof on Ethereum mainnet. Setup is per-circuit, but circuits are public and reproducible.
End-to-end encryption
Trade invitations and counterparty messages are encrypted client-side. Middn's backend never sees plaintext. Even if our servers were compromised, attackers would only find ciphertext.
The cryptography stack
| Component | Algorithm | Purpose |
|---|---|---|
| symmetric | AES-256-GCM | Payload encryption |
| key exchange | X25519 ECDH | Shared secret derivation |
| signing | Ed25519 | Message authentication |
| kdf | HKDF-SHA256 | Key derivation |
| hashing | BLAKE3 | Content addressing |
Each trade invitation generates a fresh ephemeral key pair. The shared secret is derived via X25519, and AES-256-GCM encrypts the payload. Forward secrecy means past trades stay private even if your wallet is later compromised.
Non-custodial by design
The most important property of Middn is what we don't do: we never hold user funds. Not for a millisecond. Not in a hot wallet. Not in cold storage. Never.
How it's enforced
- No admin functions on contracts. No "pause" button, no "rescue" function, no upgrade proxy.
- No multi-sig holding fees — protocol fees are routed to a separate immutable contract.
- No backend custody — our servers never receive private keys or signed transactions.
- Verifiable on-chain — every escrow address is publicly visible. You can watch your own.
Don't trust us — verify. Every contract address and source code is published on Etherscan with matching bytecode hashes. Run our circuits locally and you'll get the same proofs.
Multi-chain deployment
Middn contracts are deployed on EVM-compatible chains and Solana. Cross-chain trades are supported via atomic HTLC bridging — funds never leave the source chain prematurely.
More chains are added based on community demand. The contract logic is identical across EVM chains — only the deployment address differs.
Security audits
Middn contracts and circuits have been independently audited by two firms with deep cryptography and smart contract expertise.
| Auditor | Scope | Date | Status |
|---|---|---|---|
| Trail of Bits | Escrow contracts | Mar 2026 | Passed · 0 critical |
| Halborn | ZK circuits + crypto | Apr 2026 | Passed · 0 critical |
| Code4rena | Public contest | Ongoing | Open · $250k pool |
Full audit reports are linked in the project repository. We publish all findings — including informational notes — and every fix is verifiable in the commit history.
Read the whitepaper
The full whitepaper covers everything above in detail — circuit specifications, threat models, formal verification results, and economic security analysis.
Middn Whitepaper v0.1
PDF · 48 pages · 1.2 MB · May 2026
Source code, circuits, and contracts are all open-source under MIT. Pull requests welcome.