Skip to content

docs: add leaderboard runnable example (closes #1039)#1041

Open
mzf11125 wants to merge 8 commits into
midnightntwrk:mainfrom
mzf11125:feat/leaderboard-dapp-example
Open

docs: add leaderboard runnable example (closes #1039)#1041
mzf11125 wants to merge 8 commits into
midnightntwrk:mainfrom
mzf11125:feat/leaderboard-dapp-example

Conversation

@mzf11125

Copy link
Copy Markdown
Contributor

Summary

Adds docs/examples/dapps/leaderboard.mdx as a self-contained runnable-example page for the leaderboard DApp. The page gives developers everything they need to understand the contract, build the project, and run the browser DApp against Preprod.

The page follows the exact structure of the existing bboard.mdx example page:

  • Intro paragraph and scenario description
  • DApp architecture directory tree
  • Complete Compact contract with annotated explanations for ledger state, circuits, and witnesses
  • Compatibility table with component versions
  • Step-by-step setup, proof server, compile, and wallet instructions
  • Full browser DApp walkthrough covering score submission in all three privacy modes, leaderboard viewing, and ownership verification
  • Next steps cross-linking to the full tutorial and the bulletin board example

Type of Change

  • Documentation update (content fixes, new pages)
  • Site improvement (UI/UX, infrastructure)
  • New blog post
  • Other (please specify)

Related Links

Issue Reference

Closes #1039

Checklist

  • Followed the Midnight Style Guide.
  • Previewed changes locally (npm run start).
  • Updated navigation metadata if needed (sidebar position set to 30 in frontmatter).

Notes (Optional)

The leaderboard tutorial already exists at docs/tutorials/leaderboard/ across six pages. This PR adds the companion example page in docs/examples/dapps/ that issue #1039 requested. The example page links to the tutorial for the full build walkthrough, since the tutorial builds the project from scratch step by step.

The page targets the following component versions matching the existing tutorial:

Component Version
Compact compiler 0.31.0
Compact runtime 0.16.0
Ledger 8.0.3
midnight-js 4.0.4

A standalone example-leaderboard repository (similar to example-bboard) does not exist yet. Once the Midnight Foundation publishes that repo, the clone instructions in this page can be updated to point directly to it.

@mzf11125 mzf11125 requested review from a team as code owners June 12, 2026 15:25
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

@mzf11125 is attempting to deploy a commit to the Midnight Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@nstanford5 nstanford5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leaderboard repo (midnightntwrk/midnight-leaderboard) already exists.
Replace the placeholder 'follow tutorial to create from scratch' with
actual clone + install commands. Remove redundant npm install from
compile section.

@mzf11125 mzf11125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link. The clone instructions now point directly to https://github.com/midnightntwrk/midnight-leaderboard and the redundant install step has been removed.

Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
mzf11125 and others added 2 commits June 16, 2026 23:35
- Proof server only needed for transactions not compilation
- Removed Command-line familiarity prerequisite
- Removed compatibility version table
- Removed inline dev script commands
@mzf11125

Copy link
Copy Markdown
Contributor Author

Addressed all review comments

  • Fixed proof server text (not needed for compilation only for transactions)
  • Removed Command-line familiarity from prerequisites
  • Removed compatibility version table
  • Removed inline dev script commands

@nstanford5 nstanford5 self-requested a review June 16, 2026 18:06
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx Outdated
Comment thread docs/examples/dapps/leaderboard.mdx
Co-authored-by: nstanford5 <67871053+nstanford5@users.noreply.github.com>
Signed-off-by: nstanford5 <67871053+nstanford5@users.noreply.github.com>
@nstanford5 nstanford5 requested a review from oduameh June 17, 2026 14:18
@nstanford5 nstanford5 dismissed their stale review June 17, 2026 14:18

Changes implemented

@oduameh oduameh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution. The leaderboard example page is a great addition to the docs! I have left several inline suggestions to bring it into alignment with the existing example pages and the Midnight style guide. You can batch-commit the suggestions directly from the GitHub UI.

The main themes are:

  • Frontmatter format: Align the SPDX header and sidebar position with bboard.mdx and zkloan.mdx
  • Terminology: "zero-knowledge" (hyphenated, lowercase) per the style guide
  • Active voice and second person: Replace passive constructions and "the user's" with "your"
  • Missing sections: The page needs "Set up the example" and "Start the proof server" sections to be a complete, runnable example
  • Admonition titles: Add descriptive titles using bracket syntax

Comment on lines +1 to +16
{/* SPDX-License-Identifier: Apache-2.0
copyright: This file is part of midnight-docs. Copyright (C) Midnight Foundation. Licensed
under the Apache License, Version 2.0 (the "License"); You may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. */}

---
sidebar_label: "Leaderboard DApp"
sidebar_position: 30
title: Leaderboard DApp
description: Learn how the leaderboard DApp demonstrates privacy-preserving score submission and ownership verification with Zero Knowledge proofs on Midnight Network.
toc_max_heading_level: 2
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{/* SPDX-License-Identifier: Apache-2.0
copyright: This file is part of midnight-docs. Copyright (C) Midnight Foundation. Licensed
under the Apache License, Version 2.0 (the "License"); You may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. */}
---
sidebar_label: "Leaderboard DApp"
sidebar_position: 30
title: Leaderboard DApp
description: Learn how the leaderboard DApp demonstrates privacy-preserving score submission and ownership verification with Zero Knowledge proofs on Midnight Network.
toc_max_heading_level: 2
---
---
SPDX-License-Identifier: Apache-2.0
copyright: This file is part of midnight-docs. Copyright (C) Midnight Foundation. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
sidebar_label: "Leaderboard DApp"
sidebar_position: 25
title: Leaderboard DApp
description: Learn how the leaderboard DApp demonstrates privacy-preserving score submission and ownership verification with zero-knowledge proofs on Midnight Network.
toc_max_heading_level: 2
---


# Leaderboard DApp

The leaderboard contract demonstrates privacy-preserving smart contracts on Midnight using the Compact language. This example shows how to create a DApp that lets players submit scores with configurable privacy modes while protecting player identity through Zero Knowledge (ZK) proofs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The leaderboard contract demonstrates privacy-preserving smart contracts on Midnight using the Compact language. This example shows how to create a DApp that lets players submit scores with configurable privacy modes while protecting player identity through Zero Knowledge (ZK) proofs.
The leaderboard smart contract demonstrates privacy-preserving score tracking on Midnight using the Compact language. This example shows how to create a DApp that lets players submit scores with configurable privacy modes while protecting player identity through zero-knowledge (ZK) proofs.


The leaderboard contract demonstrates privacy-preserving smart contracts on Midnight using the Compact language. This example shows how to create a DApp that lets players submit scores with configurable privacy modes while protecting player identity through Zero Knowledge (ZK) proofs.

The leaderboard example is a privacy-focused DApp that introduces key Midnight concepts:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The leaderboard example is a privacy-focused DApp that introduces key Midnight concepts:
The leaderboard example introduces key Midnight concepts:


Two public fields track the leaderboard state on-chain:

- `scores`: A `Map<Uint<64>, ScoreEntry>` that stores all submitted entries, keyed by an auto-incrementing ID. Each `ScoreEntry` holds a score, a display name, and an ownership commitment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `scores`: A `Map<Uint<64>, ScoreEntry>` that stores all submitted entries, keyed by an auto-incrementing ID. Each `ScoreEntry` holds a score, a display name, and an ownership commitment.
- `ownerCommitment(sk)`: A helper circuit that derives an on-chain identity from your secret key using `persistentHash`. It produces a deterministic commitment that you can store and verify later without revealing the secret.

Two public fields track the leaderboard state on-chain:

- `scores`: A `Map<Uint<64>, ScoreEntry>` that stores all submitted entries, keyed by an auto-incrementing ID. Each `ScoreEntry` holds a score, a display name, and an ownership commitment.
- `nextId`: A `Counter` that auto-increments to assign a unique ID to each new entry.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `nextId`: A `Counter` that auto-increments to assign a unique ID to each new entry.
- `submitScore(score, useCustomName)`: Creates a new leaderboard entry. It retrieves your secret key via the `localSecretKey` witness, computes the owner commitment, and inserts a new `ScoreEntry` into `scores`. The `useCustomName` flag controls whether the display name comes from the `getCustomName` witness or derives directly from the secret key hash.


Click **Verify Ownership** next to any of your entries. The UI calls `verifyOwnership(entryId)`, which generates a ZK proof that your secret key matches the `ownerHash` stored in the entry. The circuit asserts the match on-chain without writing anything to the ledger.

A success message confirms ownership. If your wallet does not hold the correct secret key for that entry, the assertion fails and the transaction is rejected locally before reaching the network.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A success message confirms ownership. If your wallet does not hold the correct secret key for that entry, the assertion fails and the transaction is rejected locally before reaching the network.
A success message confirms ownership. If your wallet does not hold the correct secret key for that entry, the assertion fails and the proof server rejects the transaction locally before it reaches the network.

Comment on lines +258 to +260
:::caution
Ownership verification only works from the same browser and wallet instance that submitted the entry, because the secret key lives in the local private state store.
:::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:::caution
Ownership verification only works from the same browser and wallet instance that submitted the entry, because the secret key lives in the local private state store.
:::
:::caution[Same browser required]
Ownership verification only works from the same browser and wallet instance that submitted the entry, because the secret key lives in the local private state store.
:::

- Lace wallet browser extension installed

For more information, refer to [install the toolchain](../../getting-started/installation).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page would benefit from two additional sections before "Compile the contract" to match the structure of the existing bboard.mdx example page:

1. "Set up the example" section with:

  • A note that no standalone example-leaderboard repository exists yet, directing readers to the tutorial
  • An "Install dependencies" subsection with npm install from the project root

2. "Start the proof server" section with:

  • The Docker command: docker run -p 6300:6300 midnightntwrk/proof-server:8.0.3 -- midnight-proof-server -v
  • A :::tip[Keep the proof server running] admonition

These sections are present in bboard.mdx and are essential for a "runnable example" page -- without them, readers have no way to obtain the code or start the proof server before compiling.


The leaderboard example uses a monorepo structure with three workspace packages and a Docker configuration for the proof server.

```text

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with bboard.mdx, which uses bare fenced code blocks (without a language tag) for directory trees and command output, consider removing the text language tag here. The same applies to the compiler output block further down (line 176).

npm run compact
```


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra blank line here (two consecutive blank lines). One blank line between the code block and the following paragraph is sufficient.

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.

Leaderboard Example

3 participants