Skip to content

[Tutorial] Managing Private State (#232)#511

Open
richard202605 wants to merge 1 commit into
midnightntwrk:mainfrom
richard202605:richard232-managing-private-state
Open

[Tutorial] Managing Private State (#232)#511
richard202605 wants to merge 1 commit into
midnightntwrk:mainfrom
richard202605:richard232-managing-private-state

Conversation

@richard202605
Copy link
Copy Markdown

Bounty Submission: Issue #232

This tutorial covers private state management in Midnight Compact:

  • Ledger vs. Transient State — Understanding persistent and temporary state types
  • Private State Declaration — Using ledger for hidden data with cryptographic commitments
  • The disclose() Function — Selective disclosure and its privacy implications
  • Best Practices — Nonces, minimal disclosure, separation of concerns
  • Design Patterns — State machines, commitment-reveal, encrypted off-chain storage
  • Testing Guidance — Unit testing private state with the Compact simulator

Deliverables

Deliverable Status
Written tutorial (2,500+ words) ✅ ~2,600 words
TUTORIAL.md with full content
Working Compact code examples
State machine pattern example
Commitment-reveal pattern example
Testing guidance with simulator

Files

  • TUTORIAL.md — Complete tutorial covering private state management in Compact
  • private-voting.compact — Full-featured private voting contract (commitment-reveal, nullifiers, Merkle trees, selective disclosure, nonce protection)
  • private-vault.compact — Private balance vault (deposit/withdraw/transfer, state machine, conditional disclosure, off-chain metadata)
  • README.md — Submission summary and file descriptions

Key Takeaways for Developers

  1. Private state uses cryptographic commitments, not encryption
  2. Use circuit functions to prove properties without revealing values
  3. Always include nonces to prevent replay attacks
  4. Prefer proving over disclosing — reveal only what's strictly necessary
  5. Test privacy guarantees with the Compact simulator before deploying

Ready for review.

Bounty submission for issue midnightntwrk#232 - [Tutorial] Managing private state.

Deliverables:
- TUTORIAL.md: 2,600+ word tutorial covering private state in Compact
- private-voting.compact: Full private voting contract with commitment-reveal
- private-vault.compact: Private balance vault with state machine pattern
- README.md: Submission summary and file descriptions

Covers:
1. Ledger state vs transient state
2. Declaring and using private state variables
3. The disclose() function and privacy implications
4. Best practices: nonces, minimal disclosure, separation of concerns
5. Design patterns: state machines, commitment-reveal, off-chain storage
6. Testing private state with the Compact simulator
@richard202605 richard202605 requested a review from a team as a code owner May 16, 2026 18:36
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants