Agent skill
compact
Write privacy-preserving smart contracts in Compact (Minokawa) for Midnight Network. Use when creating contracts, defining types, using standard library functions, or implementing ZK patterns. Triggers on Compact language, circuits, ledger state, hashing, or zero-knowledge contract questions.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/design/compact-fractionestate-midnight-dev-skills
Metadata
Additional technical details for this skill
- author
- FractionEstate
- version
- 0.18
SKILL.md
Compact Smart Contracts
Compact (being renamed to Minokawa) is Midnight's domain-specific language for privacy-preserving smart contracts. Contracts compile to ZK-SNARKs, enabling selective disclosure of data.
Note: As of compiler v0.26.0, the language is being renamed from "Compact" to "Minokawa" under the Linux Foundation Decentralized Trust. The toolchain commands still use
compact.
Quick Start
pragma language_version 0.18;
export ledger message: Opaque<"string">;
export circuit setMessage(input: Opaque<"string">): [] {
message = disclose(input); // Makes private input public
}
Contract Structure
Every Compact contract has three parts:
- Pragma - Language version (
pragma language_version 0.18;) - Ledger - On-chain state declarations
- Circuits - ZK-proven functions
Core Concepts
Privacy Model
| Level | Syntax | Visibility |
|---|---|---|
| Private | const x = input; |
Only prover |
| Disclosed | disclose(value) |
Allowed to become public |
| Proven | disclose(a >= b) |
Public boolean only |
| Witness | witness f(...): T; |
Private, DApp-provided |
Notes:
- Circuit arguments and witness returns are treated as potentially private (“witness data”).
disclose(...)is a compiler acknowledgement: it does not itself publish anything, it just permits an expression to flow into public outputs (ledger writes / exported circuit returns / cross-contract comms).- Only
Opaque<"string">andOpaque<"Uint8Array">are currently supported.
Ledger Types
ledger counter: Counter; // Auto-incrementing
ledger balances: Map<Bytes<32>, Uint<64>>; // Key-value
ledger members: Set<Field>; // Membership tracking
ledger tree: MerkleTree<20, Field>; // Cryptographic proofs
Reference Files
| Topic | Resource |
|---|---|
| Type System | references/types.md - Full type reference |
| Standard Library | references/stdlib.md - Hashing, coins, EC ops |
| VS Code extension | references/vscode-extension.md - Editor setup and tasks |
| Ledger Patterns | references/ledger-patterns.md - State management |
| Advanced Patterns | references/advanced-patterns.md - Access control, state machines |
| Detailed API Patterns | references/detailed-api-patterns.md - API, code |
Templates
| Template | Description |
|---|---|
| assets/basic-contract.compact | Simple ledger + circuit |
| assets/token-contract.compact | Token with transfers |
| assets/private-voting.compact | Anonymous voting |
| assets/commitment-reveal.compact | Commit-reveal pattern |
Compilation
# Compile contract
compact compile contracts/my-contract.compact contracts/managed/my-contract
# Output structure
contracts/managed/my-contract/
├── contract/ # JSON artifacts
├── keys/ # ZK proving/verifying keys
└── zkir/ # ZK Intermediate Representation
Common Errors
| Error | Cause | Fix |
|---|---|---|
Type mismatch |
Wrong bit width | Use correct Uint<N> size |
Cannot assign private to public |
Missing disclose | Add disclose() wrapper |
Undefined symbol |
Import missing | Check pragma and imports |
Best Practices
- ✅ Start with
pragma language_version 0.18; - ✅ Use
witnessfor private inputs that need proofs - ✅ Choose smallest
Uint<N>that fits your data - ✅ Use
persistentHashfor on-chain data,transientHashfor temp - ❌ Don't expose secrets via
disclose()unnecessarily - ❌ Avoid large state (increases gas costs)
Resources
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?