technical docs ↓

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.

v0.1 · May 2026 Open-source · MIT Audited · Trail of Bits + Halborn
01 ↘

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.

→ how a trade flows 01 · invite create deal share link 02 · lock deposit assets into contract 03 · verify ZK proves conditions 04 · settle ✓ atomic swap ~12 seconds no off-chain state · no middleman in between
↳ what makes it different

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.

02 ↘

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:

// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract MiddnEscrow { address public buyer; address public seller; uint256 public amount; bytes32 public conditionHash; function release(bytes calldata zkProof) external { require(verify(zkProof, conditionHash), "invalid proof"); // atomic settlement — both legs release together payable(seller).transfer(amount); emit Settled(buyer, seller, amount); } }

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.
03 ↘

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.

→ zk verification flow private inputs amount · identity · balance circuit Groth16 zk-SNARK prover runs client-side 192 bytes on-chain proof valid ✓ no data exposed the contract sees the proof — never the inputs.

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.
↳ why Groth16

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.

04 ↘

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

ComponentAlgorithmPurpose
symmetricAES-256-GCMPayload encryption
key exchangeX25519 ECDHShared secret derivation
signingEd25519Message authentication
kdfHKDF-SHA256Key derivation
hashingBLAKE3Content 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.

05 ↘

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.
↳ self-verifiable

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.

06 ↘

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.

Ethereum
Base
Arbitrum
Optimism
Polygon
Solana

More chains are added based on community demand. The contract logic is identical across EVM chains — only the deployment address differs.

07 ↘

Security audits

Middn contracts and circuits have been independently audited by two firms with deep cryptography and smart contract expertise.

AuditorScopeDateStatus
Trail of BitsEscrow contractsMar 2026Passed · 0 critical
HalbornZK circuits + cryptoApr 2026Passed · 0 critical
Code4renaPublic contestOngoingOpen · $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.

08 ↘

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

Download

Source code, circuits, and contracts are all open-source under MIT. Pull requests welcome.

GitHub → Etherscan → Discord →