Implement privacy-preserving patterns using zero-knowledge proofs on Midnight Network. Use when designing private data handling, commitment schemes, nullifiers, or selective disclosure...
Design and implement privacy-preserving applications using zero-knowledge proofs.
| Concept | Description | Visibility |
|---|---|---|
| Public | Ledger state | Everyone |
| Private | Circuit inputs | Only prover |
| Witness | Prover-provided data | Only prover |
| Disclosed | Explicitly revealed | Everyone |
| Topic | Resource |
|---|---|
| Zero-Knowledge Basics | references/zk-fundamentals.md |
| Commitment Schemes | references/commitments.md |
| Nullifier Patterns | references/nullifiers.md |
| Selective Disclosure | references/selective-disclosure.md |
Hide a value while binding to it:
commitment = persistentCommit(value, randomness);
// Later: prove you know the opening
Prevent double-use without revealing identity:
nullifier = transientHash(secret, commitment);
// Can only be generated once per commitment
Prove properties without revealing data:
// Prove over 18 without revealing actual age
disclose(age >= 18); // Only boolean is public
Prove membership in a set without revealing position:
// Verify path from leaf to root
assert verifyMerklePath(leaf, proof, root);
// Only reveal if balance is sufficient, not actual amount
export circuit checkFunds(balance: Uint<64>, required: Uint<64>): Boolean {
return disclose(balance >= required);
}
export circuit vote(voter: Bytes<32>, choice: Boolean): [] {
// Voter identity disclosed (prevents double voting)
hasVoted.insert(voter);
// Choice remains private, only totals change
if (choice) { yesCount = yesCount + 1; }
}
witness randomness: Field;
// Phase 1: Commit
export circuit commit(value: Uint<64>): Field {
return persistentCommit(value, randomness);
}
// Phase 2: Reveal
export circuit reveal(value: Uint<64>, commitment: Field): [] {
assert persistentCommit(value, randomness) == commitment;
disclose(value);
}
witness for data that should never appear on-chainpersistentCommit (with randomness) to hide valuesāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Level 0: Fully Public ā
ā - All data visible on-chain ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Level 1: Hidden Values ā
ā - Commitments on-chain, values private ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Level 2: Unlinkable Actions ā
ā - Nullifiers prevent linking actions ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Level 3: Anonymous Membership ā
ā - Merkle proofs hide set position ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
| Pattern | Use Case |
|---|---|
| Commitment | Sealed bids, hidden votes before reveal |
| Nullifier | Preventing double-spend, one-time tokens |
| Merkle Proof | Membership in allowlist without revealing identity |
| Selective Disclosure | Age verification, credential proofs |