/core-concepts:protocolsfrom core-concepts
Explains Midnight's Kachina protocol for confidential smart contracts and Zswap for shielded token transfers, including atomic swaps, nullifiers, commitments, and the two-state model.
Ships in core-concepts. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Midnight uses two foundational protocols: Kachina for data-protecting smart contracts and Zswap for shielded token transfers.
| Need | Protocol |
|---|---|
| Smart contract logic | Kachina |
| Token transfers | Zswap |
| Atomic multi-party swaps | Zswap |
| Private computation | Kachina |
| Shielded coins | Zswap |
Kachina enables confidential, general-purpose smart contracts while maintaining decentralization.
┌─────────────────────────────────────────┐
│ On-Chain (Public) │
│ - Contract code │
│ - Public state │
│ - Merkle roots │
└─────────────────────────────────────────┘
^ ZK Proofs ^
┌─────────────────────────────────────────┐
│ Off-Chain (Private) │
│ - User's private inputs │
│ - Local state │
│ - Witness data │
└─────────────────────────────────────────┘
| State Type | Location | Visibility |
|---|---|---|
| Public state | Blockchain | Everyone |
| Private state | User's machine | Owner only |
ZK proofs bridge these states: prove something about private state without revealing it.
| Property | Benefit |
|---|---|
| Concurrency | Multiple users act simultaneously without blocking |
| Privacy | Private state never leaves user's machine |
| Composability | Contracts interact via public state (cross-contract calls still under development) |
| Reordering | Conflicting transactions optimally reordered |
Zswap is a shielded token mechanism for confidential atomic swaps, based on Zerocash.
Zswap Offer = Inputs + Outputs + Transient + Deltas
| Hidden | Visible |
|---|---|
| Sender | Transaction occurred |
| Receiver | Proof validity |
| Amount | Fee payment |
| Token type (can be) | Nullifiers (unlinkable) |
An offer comprises inputs (coins being spent, each identified by a nullifier with a Merkle proof and ZK validity proof), outputs (new coins being created, each carrying a commitment and optional encrypted note), transient coins (created and destroyed within the same transaction), and a delta vector describing the net value change per token type. Each input and output also carries a separate Pedersen value commitment for balance verification.
Zswap enables multi-party atomic exchanges:
Party A: Offers 10 TokenX
Party B: Offers 5 TokenY
|
Merged off-chain
|
Single atomic transaction
(Either both happen or neither)
Two transactions can merge if at least one has an empty contract call section. Coin sets must be disjoint. Merged transaction combines:
Contracts issue custom tokens via Zswap:
Token type = Hash(domain_separator, contract_address)
Contract can mint/burn tokens through Zswap stdlib operations
New coins are created as hash-based commitments (Hash(CoinInfo, ZswapCoinPublicKey)), paired with a separate Pedersen value commitment for balance verification. See references/zswap-internals.md for details.
Important: The coin commitment is hash-based, not a Pedersen commitment. The Pedersen value commitment is a separate element used only for balance verification.
Coins are spent by publishing a nullifier (Hash(CoinInfo, ZswapCoinSecretKey)) with a Merkle proof of commitment existence and a ZK validity proof. The commitment itself is NOT an input to nullifier computation, making nullifiers unlinkable to the original commitment. See references/zswap-internals.md for the complete input structure.
Critical: The nullifier is computed from CoinInfo and the secret key -- the commitment itself is NOT an input to nullifier computation. This makes nullifiers unlinkable to the original commitment without knowledge of the secret key.
┌──────────────────────────────────────────┐
│ Transaction │
├──────────────────────────────────────────┤
│ Zswap Section | Contract Section │
│ - Guaranteed offer | - Contract calls │
│ - Fallible offer | - ZK proofs │
│ (Token transfers) | (State changes) │
└──────────────────────────────────────────┘
Transactions combine Zswap (value movement) with Kachina (computation).
See core-concepts:architecture for the full three-phase execution model.
1. Create Zswap offer with:
- Input: Your coin (nullifier + proof)
- Output: Recipient's new coin (commitment)
- Deltas: Must net to non-negative (excess becomes fees)
2. Submit transaction
1. Party A creates partial offer: NIGHT: +10, TokenX: -10
// Positive delta = inputs exceed outputs = giving that token type
2. Party B creates partial offer: TokenX: +10, NIGHT: -10
// Bob gives TokenX, wants NIGHT
3. Merge offers (deltas sum to zero — balanced)
4. Submit single transaction
5. Both transfers atomic
1. Zswap offer moves tokens
2. Contract call updates state
3. Both bound cryptographically
4. Atomic execution
For detailed technical information:
references/kachina-deep-dive.md - UC security model, transcript validationreferences/zswap-internals.md - Coin commitments, value commitments, offer constructionWorking patterns:
examples/basic-transfer.md - Simple shielded transferexamples/atomic-swap.md - Multi-party atomic exchangeWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub midnightntwrk/midnight-expert --plugin core-concepts6 skills in this plugin
/architecturecore-concepts:architectureThis skill should be used when the user asks about Midnight network architecture, transaction structure, guaranteed vs fallible sections, Zswap/Kachina integration, ledger and state management, cryptographic binding, balance verification, nullifiers, address derivation, transaction merging, atomic swaps, fee handling, or the privacy model separating private and public domains./data-modelscore-concepts:data-modelsThis skill should be used when the user asks about UTXO vs account models, ledger tokens, shielded/unshielded tokens, nullifiers, coin commitments, the Zswap commitment tree, double-spend prevention, token balances, parallel transaction processing, choosing between token paradigms in Midnight, minting tokens, token type identification, or the ledger structure./privacy-patternscore-concepts:privacy-patternsThis skill should be used when understanding privacy-preserving design patterns, including commitment schemes, nullifier patterns, Merkle tree membership proofs, anonymous authentication, commit-reveal protocols, selective disclosure, domain separation, and privacy boundaries in on-chain data.Other plugins' skills for the same job