midnight-concepts
Midnight Concepts
Comprehensive guide to Midnight Network's foundational concepts, privacy technology, and architecture.
What is Midnight?
Midnight is a zero-knowledge partner chain to Cardano that enables privacy-preserving blockchain applications. It solves the fundamental tension between transparency and privacy in blockchain technology through advanced zero-knowledge cryptography.
Key Innovation: Selective disclosure - applications can choose exactly what information to make public and what to keep private, while maintaining verifiability.
Core Features:
- Privacy-preserving smart contracts
- Selective disclosure
- UTXO + Account hybrid model
- Zswap for private token transfers
- Integration with Cardano security
Architecture Overview
Three-Part Contract Structure
Each Compact smart contract has three components:
-
Replicated Component (Public Ledger)
- Stored on-chain
- Verifiable by anyone
- Contains public state
-
Zero-Knowledge Circuit
- Proves correct execution
- Keeps inputs private
- Generates proofs
-
Local Component (Off-chain)
- Runs in DApp
- Arbitrary computation
- Witness functions
Core Concepts
1. Kachina Protocol
THE foundational smart contract architecture that enables private state management.
How It Works:
- User has private state (witness)
- Circuit proves valid transition
- Public state updates on-chain
- Both states stay consistent
Key Properties:
- Public state + Private state model
- Zero-knowledge proof bridge
- Transcript-based concurrency
- Universally Composable (UC) security
From the whitepaper: Kachina uses a novel combination of a public ledger and private witnesses, with circuits proving correct state transitions.
2. Privacy Mechanisms
Zswap Protocol
Privacy-preserving token system hiding:
- Transaction amounts
- Sender/recipient identities
- Token types
Features:
- Shielded tokens (hidden)
- Unshielded tokens (public)
- Conversion between both
- Zero-knowledge proofs for validity
// Shielded transfer flow
1. Create input from owned shielded coin
2. Create output for recipient
3. Generate ZK proof
4. Submit to network
5. Recipient can receive and spend
Selective Disclosure
Applications control exactly what data is public vs private:
// Private comparison
export circuit verifyAge(age: Uint<32>): Boolean {
const secretAge = witness Age(); // Private
return disclose(secretAge >= 18); // Only reveal boolean
}
3. Ledger Models
Midnight uses a hybrid UTXO + Account model:
UTXO Model (Ledger Tokens)
- Like Bitcoin
- Each coin spent exactly once
- Good for: privacy, parallelism
Account Model (Contract Tokens)
- Like Ethereum
- Mutable stored state
- Good for: complex contracts
Decision Matrix:
| Use Case | Recommended Model |
|---|---|
| Simple transfers | UTXO |
| Token balances | Account |
| Complex state | Account |
| High privacy | UTXO |
| High throughput | UTXO |
| Smart contracts | Account |
4. Zero-Knowledge Proofs
Mathematical techniques proving computations are correct without revealing inputs.
Key Concepts:
- Circuit: Compiled from Compact code
- Witness: Private inputs
- Public inputs: Transparent arguments
- Proof: Succinct verification
Use in Midnight:
- Valid state transitions
- Transaction validity
- Credential verification
5. Partner Chain Architecture
Midnight is a partner chain to Cardano:
Benefits:
- Inherits Cardano security
- EUTxO model
- proven consensus
- Decentralized infrastructure
Integration:
- Consensus via Cardano
- State checkpointing
- Token bridging
Privacy Model
What Can Be Private
| Data | Privacy Level | Disclosure |
|---|---|---|
| Account balances | Optional | User choice |
| Transaction amounts | Optional | Hidden in Zswap |
| Identities | Optional | Hidden in Zswap |
| Business logic | Automatic | Circuit keeps secret |
| Credentials | Selective | Only proven facts |
What Is Always Public
- Transaction existence
- Block order
- State updates (not values)
- Contract code
Use Cases by Category
Finance & DeFi
-
Confidential Trading
- Hidden amounts
- Hidden positions
- See: LunarSwap
-
Private Lending
- Hidden collateral
- Hidden debt
- Credit scoring proof only
-
Liquid Staking
- Hydra Stake
- Privacy-preserving rewards
- LST functionality
-
Stablecoins
- Statera Protocol
- Over-collateralized
- Privacy features
Identity & Privacy
-
ZK Identity
- Midnames - ZK DID
- Selective attribute disclosure
-
KYC Attestations
- KYC Midnight
- Prove without revealing data
-
Private Credentials
- Midnight Cloak
- Age/residence verification
-
RWA Trading
- Real World Assets
- Privacy-first tokenization
Governance
-
Private Voting
- Secret ballots
- Verifiable counting
- No vote selling
-
Crowdfunding
- FundAGoal
- Anonymous contributions
Gaming
-
On-chain Gaming
- Midnight Starship
- ZK leaderboards
- Privacy-first gaming
-
Verifiable RNG
- Dice Roll
- Fair randomness
Tokenomics
Native Token: NIGHT
- Used for fees
- Staking rewards
- Governance
- Unit: 1 NIGHT = 10^6 Stars
DUST: Dynamic Gas System
DUST is NOT a static balance. It's a dynamic gas system where your DUST balance changes based on your NIGHT holdings and time.
Analogy:
- NIGHT = Solar Panel (valuable asset you hold)
- DUST = Electricity (generated from the Solar Panel)
- Usage = Consuming electricity to power operations
How DUST Works
- Registration: Link your NIGHT address to a DUST public key via the Registration Table
- Generation Phase: DUST grows linearly from creation until it hits a cap (ρ)
- Constant Phase: Stays at maximum value
- Decay Phase: Once NIGHT is spent, DUST decays to zero
- Zero Phase: No more gas available
Key Properties
| Property | Description |
|---|---|
| Shielded | DUST UTXOs are private |
| Non-transferable | Cannot send DUST to others |
| Dynamic | Value changes over time |
| Derived | Computed from NIGHT UTXO |
DUST Units
- DUST unit: 1 DUST = 10^15 Specks
- Initial ratio: ~5 DUST per NIGHT
- Grace period: ~3 hours (for transaction timestamp)
Spending Rules
- DUST can be spent multiple times
- New UTXO always created, even with zero value
- Decay continues even during spending
- Partial NIGHT spend creates fresh DUST generation
Full Architecture
The full technical specification is available in the DUST spec.
Programmatic DUST Generation (Preprod)
On Preprod network, DUST is no longer available from the faucet. DApps must programmatically generate DUST:
- Fund wallet: Get tNIGHT from Preprod faucet
- Designate dust address: Register your unshielded address to a dust address
- Generate DUST: Your tNIGHT holdings automatically generate DUST for gas fees
Reference: midnight-dust-generator - Official script for Preprod
Prerequisites:
- Node.js v18+
- Docker Desktop (for proof server on port 6300)
npm install
docker compose -f proof-server.yml up # terminal 1
npm start # terminal 2 - interactive walkthrough
The script handles: wallet creation/restoration, funding detection, address designation, and registration.
Dust: Anonymous Tokens (Legacy)
- Privacy coins
- Unlinkable
- Denominations (1, 10, 100, etc.)
Security Model
Consensus
- Inherited from Cardano
- Proof of Stake
- BFT-style finality
Privacy Guarantees
What Midnight provides:
- Computational privacy (ZK circuits)
- Transaction unlinkability (Zswap)
- Selective disclosure
What Midnight does NOT provide:
- Metadata privacy (timing, size)
- Network-level privacy
- Quantum resistance (future)
When to Use Midnight
✅ Best Fit For
- Private DeFi - Confidential trading, lending
- Identity - KYC, credentials, age proof
- Voting - Private ballots, governance
- RWA - Privacy-first asset tokenization
- Gaming - Verifiable RNG, ZK leaderboards
❌ Not Ideal For
- Fully public applications (use Cardano directly)
- High-throughput needs (consider Hydra)
- Simple transfers (Cardano tx is sufficient)
Technical Deep Dives
ZK Circuit Flow
pragma language_version >= 0.20;
// Public state
export ledger balance: Uint<64>;
// Private witness
witness secretAmount(): Uint<64>;
// Circuit enforces rules
export circuit deposit(amount: Uint<64>): [] {
// Verify private input
const secret = secretAmount();
// Only disclose commitment
const commitment = disclose(persistentCommit(balance.read(), secret));
// Update public
balance.write(balance.read() + amount);
}
Zswap Flow
- Shield coins exist locally
- Create input referencing coin
- Generate proof (ownership, sufficient amount)
- Create outputs (recipient + change)
- Submit to network
- Recipients can spend in future
State Consistency
Kachina Guarantees:
- If circuit proves valid → state updates
- If circuit fails → no state change
- Private state stays private
- Public verification always possible
Midnight Improvement Proposals (MIPs)
Formal process for proposing changes to Midnight: midnight-improvement-proposals
Process
- Idea → 2. Draft → 3. Submit PR → 4. Review → 5. Accepted → 6. Implemented → 7. Deployed
Categories
| Category | Description |
|---|---|
| Core | Protocol, consensus, VM changes |
| Standards | Smart contract interfaces, data formats |
| Networking | P2P communication |
| Governance | Decision-making processes |
| Informational | Guidelines, research (no change) |
Statuses
Proposed → Review → Accepted → Implemented → Superseded/Obsolete/Rejected/Withdrawn
MIP Template
---
MIP: <number>
Title: <title>
Authors: <name> <github>
Status: Proposed
Category: <Core|Standards|Networking|Governance|Informational>
Created: <date>
Requires: <other MIPs>
Replaces: <MIP number>
---
Reference: MIP-1: MIP Process
Glossary
| Term | Definition |
|---|---|
| Circuit | ZK program proving computation |
| Witness | Private input to circuit |
| Transcript | Ordered transaction history |
| Zswap | Private token system |
| Selective Disclosure | Explicit privacy control |
| Partner Chain | Secondary chain to Cardano |
| Compact | ZK smart contract language |
| Shielded | Privacy-preserving transaction |
| UTXO | Unspent Transaction Output |
| DUST | Privacy coin denominations |
Learn More
Official Resources
Awesome DApps (Reference Implementations)
Discord Community
Social
More from mzf11125/midnight_agent_skills
midnight-network
Guide to Midnight Network infrastructure, validators, indexers, and network operations. Use when users need to run Midnight validators and participate in consensus, set up and configure Midnight indexers for blockchain data, configure network nodes and infrastructure, monitor validator performance and network health, understand network parameters and configuration, deploy and manage network infrastructure, troubleshoot network issues, and access node release information and compatibility.
8midnight-compact
Comprehensive guide to the Compact programming language (v0.22+) for writing privacy-preserving smart contracts on Midnight Network. Use when users need to write Compact smart contracts with zero-knowledge proofs, understand Compact syntax and language features, implement ZK circuit patterns and optimizations, generate contract boilerplate and project scaffolding, learn best practices for secure contract development, access Compact standard library functions, and compile and test Compact contracts.
7midnight-api
Comprehensive guide to Midnight Network APIs (v8.0+) for building decentralized applications. Use when users need to integrate Midnight APIs including Compact Runtime, DApp Connector, ZSwap, Wallet, and Ledger APIs, connect DApps to Midnight wallets, generate and verify zero-knowledge proofs programmatically, manage transactions and blockchain state, deploy and interact with Compact smart contracts, query blockchain data via indexer, implement wallet functionality, handle Zswap private transactions, and build complete web3 applications on Midnight.
7