plugins/midnight-core-concepts/skills/protocols/SKILL.md
Use when asking about Kachina smart contract protocol, Zswap token transfers, atomic swaps, shielded transfers, offers, coins, or private transaction mechanisms in Midnight.
npx skillsauth add aaronbassett/midnight-knowledgebase midnight-core-concepts:protocolsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Midnight uses two foundational protocols: Kachina for privacy-preserving 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 | | Reordering | Conflicting transactions optimally reordered |
Zswap is a shielded token mechanism for confidential atomic swaps, based on Zerocash.
Zswap Offer = Inputs + Outputs + Transient + Balance
| Hidden | Visible | |--------|---------| | Sender | Transaction occurred | | Receiver | Proof validity | | Amount | Fee payment | | Token type (can be) | Nullifiers (unlinkable) |
Offer {
inputs: [
{ nullifier, type_value_commit, merkle_proof, zk_proof }
],
outputs: [
{ commitment, type_value_commit, optional_contract, optional_ciphertext, zk_proof }
],
transient: [...],
balance: { token_type → value }
}
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. Merged transaction combines:
Contracts issue custom tokens via Zswap:
// Token type = Hash(contractAddress, domainSeparator)
// Contract can mint/burn tokens through Zswap operations
Creating new coins:
Output = {
commitment: Pedersen(type, value, owner, randomness),
type_value_commit: Pedersen(type, value),
contract_address: optional, // For contract-targeted coins
ciphertext: optional, // Encrypted for recipient
zk_proof: validity_proof
}
Spending existing coins:
Input = {
nullifier: Hash(commitment, owner_secret),
type_value_commit: Pedersen(type, value),
contract_address: optional,
merkle_proof: path_to_commitment,
zk_proof: validity_proof
}
Critical: Nullifier is unlinkable to original commitment.
┌──────────────────────────────────────────┐
│ 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).
1. Create Zswap offer with:
- Input: Your coin (nullifier + proof)
- Output: Recipient's new coin (commitment)
- Balance: Must net to zero (minus fees)
2. Submit transaction
1. Party A creates partial offer: -10 TokenX
2. Party B creates partial offer: -5 TokenY, +10 TokenX
3. Merge offers (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 - Pedersen commitments, offer constructionWorking patterns:
examples/basic-transfer.md - Simple shielded transferexamples/atomic-swap.md - Multi-party atomic exchangetools
Use when setting up Midnight development environment, installing Compact compiler and developer tools, configuring proof server, verifying prerequisites, or getting started with Midnight development.
tools
--- name: midnight-tooling:midnight-debugging description: Use when encountering Midnight errors like "compact: command not found", "ERR_UNSUPPORTED_DIR_IMPORT", version mismatches, proof server failures, "@midnight-ntwrk" package errors, or compilation failures. --- # Midnight Environment Debugging Expert knowledge for identifying and resolving common Midnight development toolchain issues. ## Diagnostic Approach When encountering Midnight-related errors, follow this systematic approach: 1.
tools
Use when checking Midnight version compatibility, understanding pragma language_version, verifying compiler and runtime version relationships, or troubleshooting version mismatch errors between Midnight components.
tools
Use when setting up CI/CD for Midnight projects, configuring GitHub Actions for Compact contract compilation, running TypeScript tests in CI, validating version consistency, or automating contract builds.