---
name: compact-core-privacy-disclosure-d5e8a7454657
description: Use when encountering "potential witness-value disclosure" compiler errors, implementing commit-reveal patterns, working with persistentCommit/transientCommit vs persistentHash/transientHash, or designing privacy-preserving circuits with proper witness protection.
---

# Privacy & Disclosure

Essential guidance for Midnight's privacy model: when disclosure is required, commitment patterns, and witness protection.

## The Disclosure Rule

**Witness values cannot flow to public outputs without explicit `disclose()`.**

The compiler tracks all witness-derived values through your code. If a value touches any of these "disclosure triggers", you must wrap it with `disclose()`:

| Trigger | Why Disclosure Required |
|---------|------------------------|
| Ledger storage | Data on-chain is public |
| Circuit return | Return values go to TypeScript |
| External contract | Data leaves your contract boundary |
| Comparison operations | Comparisons can leak information |

## Quick Decision Tree

```
Is the value derived from a witness?
├── No → No disclosure needed
└── Yes → Does it flow to:
    ├── Ledger write → disclose() required
    ├── Circuit return → disclose() required
    ├── Comparison (==, <, >) → disclose() required
    └── Commitment (transientCommit/persistentCommit) → Safe, no disclosure
```

## Safe vs Unsafe Operations

| Operation | Safe? | Why |
|-----------|-------|-----|
| `persistentCommit(x)` | ✅ Safe | Hides value with nonce |
| `transientCommit(x)` | ✅ Safe | Hides value with nonce |
| `persistentHash(x)` | ❌ Unsafe | No nonce, can be brute-forced |
| `transientHash(x)` | ❌ Unsafe | No nonce, can be brute-forced |

## Common Patterns

### Commit-Reveal

```compact
witness get_secret(): Field;

// Phase 1: Commit
export circuit commit(): Bytes<32> {
    const secret = get_secret();
    return persistentCommit(secret);  // Safe: commitment hides secret
}

// Phase 2: Reveal (requires disclosure)
export circuit reveal(): Field {
    const secret = get_secret();
    return disclose(secret);  // Explicit: user knows this reveals
}
```

### Nullifier Pattern

```compact
witness get_secret(): Field;

export circuit spend(commitment: Bytes<32>): Bytes<32> {
    const secret = get_secret();

    // Verify knowledge of secret
    assert persistentCommit(secret) == commitment, "Invalid commitment";

    // Generate nullifier (unique per secret, reveals nothing)
    const nullifier = persistentHash("nullifier", secret);
    return nullifier;
}
```

## References

- [Disclosure Rules](./references/disclosure-rules.md) - Complete decision tree
- [Witness Protection](./references/witness-protection.md) - How the compiler tracks values
- [Safe Operations](./references/safe-operations.md) - Safe vs unsafe stdlib functions


---
Source attribution: aaronbassett
Original project: https://github.com/aaronbassett/midnight-knowledgebase/blob/8d873d378dc993f3b80e611d44605ea29f411aaf/plugins/compact-core/skills/privacy-disclosure/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Aaron Bassett

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: aaronbassett
Original project: https://github.com/aaronbassett/midnight-knowledgebase/blob/8d873d378dc993f3b80e611d44605ea29f411aaf/plugins/compact-core/skills/privacy-disclosure/SKILL.md
Attribution basis: Source repository record

Fields of work: Data & Analytics, Development & Engineering
Roles: Backend Developer, Data Scientist, ML / AI Engineer
Specialties: Backend
Tools: Midnight
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 2afb4c8329f919ebf19d1f6d26c178717e5c9c4b27881c9a61b0e2d03cea2d02
