Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Events/eclipse/witnesses-in-depth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
type: tutorial
team_slug: witnesses-in-depth
team_name: Midnight Contributors
project_title: "Witnesses in Depth: Patterns, Types, and Real Use Cases"
repo_url: https://github.com/midnightntwrk/contributor-hub
demo_url: https://github.com/midnightntwrk/contributor-hub/blob/main/tutorials/witnesses-in-depth.md
link:
members:
- name: Midnight Contributor
github: midnightntwrk
tech_stack: [Compact, TypeScript, ZK, Midnight]
tracks: [dapp, privacy, tutorial]
---

A comprehensive deep-dive tutorial on Midnight witness functions: what they are, how they differ from circuit logic, and the four core patterns every Midnight dApp developer needs — secret key verification, witness-verified division, external data ingestion, and Merkle-based access control.

The tutorial covers 2,500+ words with fully working Compact and TypeScript code examples for each pattern, a testing section with mock providers, and a survey of real use cases in existing Midnight dApps (token contracts, private voting, confidential NFTs, and sealed-bid auctions).

Full content: [tutorials/witnesses-in-depth.md](../../tutorials/witnesses-in-depth.md)
14 changes: 14 additions & 0 deletions tutorials/witnesses-in-depth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Witnesses in Depth: Patterns, Types, and Real Use Cases

Zero-knowledge proofs are powerful — but only if you can feed them the right inputs. In Midnight's Compact language, **witnesses** are the mechanism that lets off-chain computation hand private data into an on-chain ZK circuit without ever exposing the underlying secrets. This tutorial takes a deep dive into what witnesses are, how they differ from circuit logic, and the patterns you will reach for repeatedly when building real dApps.

---

## What Is a Witness?

A witness is a function that executes **off-chain**, on the user's device, and whose output is provided as a private input to the ZK circuit at proof-generation time. The circuit does not run the witness; it only sees the return value and uses that value inside assertions.

Think of the circuit as the verifier and the witness as the prover. The witness says "here is the answer"; the circuit says "I will not accept this proof unless the answer satisfies these constraints."

In Compact, a witness is declared with the `witness` keyword: