Skip to content

docs: add ZK Loan DApp tutorial (Parts 1-3)#756

Open
Olanetsoft wants to merge 19 commits intomainfrom
tutorials/zk-loan-part-1
Open

docs: add ZK Loan DApp tutorial (Parts 1-3)#756
Olanetsoft wants to merge 19 commits intomainfrom
tutorials/zk-loan-part-1

Conversation

@Olanetsoft
Copy link
Copy Markdown
Contributor

@Olanetsoft Olanetsoft commented Mar 26, 2026

Summary

  • Adds the complete 3-part ZK Loan DApp tutorial under docs/tutorials/zk-loan/
  • Part 1 — Smart contract: Project setup, Schnorr signature module, loan smart contract (Compact), witness implementation, TypeScript exports, and compilation
  • Part 2 — Attestation API: Schnorr signing implementation, REST server, attestation flow walkthrough, and Docker proof server setup
  • Part 3 — CLI and end-to-end testing: Interactive CLI (wallet management, contract deployment, loan requests, admin operations), and full end-to-end walkthrough with Midnight Local Dev
  • Creates a new zk-loan/ tutorial folder with _category_.yaml following the existing counter/bboard pattern
  • Updates the _advanced/zk-loan-dapp.mdx placeholder to link to the new tutorial

Test plan

  • Verify all three tutorial pages render correctly in the Docusaurus dev server
  • Confirm sidebar navigation shows the ZK Loan category under Tutorials with correct ordering
  • Check all code blocks render with proper syntax highlighting
  • Verify internal links resolve correctly
  • Confirm tables (eligibility tiers, privacy summary) render properly

@Olanetsoft Olanetsoft requested review from a team as code owners March 26, 2026 10:54
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
midnight-wiki Ready Ready Preview, Comment Apr 5, 2026 2:01am

Request Review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

Summary

Status Count
🔍 Total 10
✅ Successful 5
⏳ Timeouts 0
🔀 Redirected 0
👻 Excluded 0
❓ Unknown 0
🚫 Errors 5
⛔ Unsupported 0

Errors per input

Errors in docs/tutorials/zk-loan/attestation-api.mdx

  • [ERROR] file:///home/runner/work/midnight-docs/midnight-docs/docs/tutorials/zk-loan/cli | Cannot find file
  • [ERROR] file:///home/runner/work/midnight-docs/midnight-docs/docs/tutorials/zk-loan/smart-contract | Cannot find file

Errors in docs/tutorials/zk-loan/cli.mdx

  • [ERROR] file:///home/runner/work/midnight-docs/midnight-docs/docs/tutorials/zk-loan/attestation-api | Cannot find file
  • [ERROR] file:///home/runner/work/midnight-docs/midnight-docs/docs/tutorials/zk-loan/smart-contract | Cannot find file

Errors in docs/tutorials/zk-loan/smart-contract.mdx

  • [ERROR] file:///home/runner/work/midnight-docs/midnight-docs/docs/tutorials/zk-loan/attestation-api | Cannot find file
    Full Github Actions output

Add the first part of the ZK Loan DApp tutorial covering the smart
contract, Schnorr signature module, witness implementation, and
compilation steps. Update the advanced placeholder to link to the
new tutorial location.
@Olanetsoft Olanetsoft force-pushed the tutorials/zk-loan-part-1 branch from 3a231fe to e876738 Compare March 26, 2026 10:55
Add the second part of the ZK Loan DApp tutorial covering the
attestation API, Schnorr signing implementation, REST server,
attestation flow walkthrough, and Docker proof server setup.
Add the final part of the ZK Loan DApp tutorial covering the CLI
implementation, wallet management, smart contract deployment, and
end-to-end testing walkthrough with Midnight Local Dev.
@Olanetsoft Olanetsoft changed the title docs: add ZK Loan smart contract tutorial (Part 1) docs: add ZK Loan DApp tutorial (Parts 1-3) Mar 26, 2026
Link Part 1/2/3 references to their respective pages and replace
the external installation docs link with an internal one.
Link to concepts (zero-knowledge proofs, ledgers, data protection,
explicit disclosure), Compact language reference, Standard Library,
proof server guide, Midnight Local Dev guide, and release notes.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

🚀 Preview Deployment

Deployment Ready

🔗 Preview URL: https://pr-756-midnight-docs.vercel.app

📝 Latest commit: 0534449
Updated: Apr 5, 2026, 2:00 AM UTC


This preview updates automatically when you push new commits to this PR.

@DianaHackmamba
Copy link
Copy Markdown
Contributor

@gyrationtechs - Please review. LMK if I need to take a look.

Copy link
Copy Markdown
Contributor

@gyrationtechs gyrationtechs left a comment

Choose a reason for hiding this comment

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

Hi @Olanetsoft, very detailed and 'long' tutorial. I have a couple of comments and suggestions for improvement.

Please take a look and let me know if you have any questions or concerns🙂

- Use active voice for headings (Write/Create/Compile instead of Writing/Creating/Compiling)
- Change Compact code blocks from typescript to compact syntax highlighting
- Replace bold with italics for emphasis throughout
- Convert sequential ordered lists to unordered lists, remove blank lines between items
- Move explanations after code snippets for better readability
- Wrap evaluateApplicant note in :::important admonition
- Update compactc references to Compact toolchain / compact compile
- Update proof server image to midnightntwrk/proof-server:8.0.0 and remove --network testnet flag
- Add explanatory comments for JUBJUB_ORDER and TWO_248 constants
- Split large cli.ts code block into smaller annotated sections
- Rename final heading to "Next steps" for consistency
- Rewrite passive intro paragraphs to active voice
- Remove "What you built in Part 2" summary section (redundant with intro)
- Rename "Coming up in Part 3" to "Next steps" with rewritten intro
- Convert prerequisites to heading with bullet list
- Rename "Building the CLI" to "Build the CLI"
- Replace compactc reference with "Compact compiler"
- Use tNIGHT/tDUST for testnet token names
- Add context paragraphs before code sections that lacked them

2. **Proof server**: A Docker container running Midnight's proof generation service locally. Every transaction that touches the smart contract requires a zero-knowledge proof, and this service produces them.

You also walk through the **attestation flow** end-to-end — how credit data moves from the attestation API into the zero-knowledge proof without ever appearing on-chain.
Copy link
Copy Markdown
Contributor

@gyrationtechs gyrationtechs Apr 2, 2026

Choose a reason for hiding this comment

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

Suggestion for improvement:

This section walks through the attestation flow end-to-end, showing how credit data flows from the attestation API to the zero-knowledge proof without ever appearing on-chain.

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.

Agreed

Copy link
Copy Markdown
Contributor

@gyrationtechs gyrationtechs left a comment

Choose a reason for hiding this comment

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

Hey @Olanetsoft, thanks for making the changes. Looking good. Minor edits then g2g.

3. *CLI*: A command-line tool to deploy the smart contract, register the attestation provider, request loans, and interact with the system — all pointing at Midnight's local network.

## Project setup

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.

We should avoid stacking headings together. A brief context paragraph would be handy!


The next part builds the off-chain infrastructure that makes the smart contract functional:

* *[Attestation API](./attestation-api)*: A REST server that signs credit data with Schnorr signatures, acting as the trusted data provider that the smart contract verifies against.
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.

I think this is supposed to be bolded. Single asterisk (*) applies italics. A few sections are impacted by this. Review and update each to use bolded 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.

Actually, I wouldn't format the link text at all. The non-link text before the colon certainly should be bold.


[Midnight Network](/concepts/network-architecture/onchain-logic) makes this practical. It is a blockchain purpose-built for [data protection](/concepts/how-midnight-works/keeping-data-private), where smart contracts can process private inputs and commit only the results on-chain. The sensitive data never leaves the user's machine.

In this tutorial, you build a zero-knowledge loan application from scratch on Midnight Network. The app privately evaluates a user's credit data (credit score, income, and employment tenure) using zero-knowledge proofs and records only the loan outcome on-chain. The sensitive financial data never leaves your machine.
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.

Let's rewrite this section to use an active voice. Here is a suggestion. Feel free to reword and use as you see fit.

This tutorial builds a ...

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.

Agreed.


In this tutorial, you build a zero-knowledge loan application from scratch on Midnight Network. The app privately evaluates a user's credit data (credit score, income, and employment tenure) using zero-knowledge proofs and records only the loan outcome on-chain. The sensitive financial data never leaves your machine.

You build three things:
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.

Maybe it's just me. But this reads somehow. Here's another version:

The tutorial is split into three parts:

@gyrationtechs gyrationtechs self-requested a review April 2, 2026 19:52
@gyrationtechs
Copy link
Copy Markdown
Contributor

@DianaHackmamba, please review when you have a moment.


But right now, that smart contract has no way to receive signed credit data or generate zero-knowledge proofs. This part builds the two pieces of off-chain infrastructure that make the smart contract functional:

1. **Attestation API**: A REST server that signs credit data with Schnorr signatures on the Jubjub curve. It acts as the trusted data provider (a stand-in for a bank or credit bureau) whose signatures the smart contract verifies inside the zero-knowledge circuit.
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.

Why is this list numbered?


2. **Proof server**: A Docker container running Midnight's proof generation service locally. Every transaction that touches the smart contract requires a zero-knowledge proof, and this service produces them.

You also walk through the **attestation flow** end-to-end — how credit data moves from the attestation API into the zero-knowledge proof without ever appearing on-chain.
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.

Agreed


#### How the signing works

The signing uses the **Jubjub elliptic curve** (Midnight's native internal curve). Here is the Schnorr signing flow, step by step:
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.

Why is this text bold? I do not see a reason it should be.


The signing uses the **Jubjub elliptic curve** (Midnight's native internal curve). Here is the Schnorr signing flow, step by step:

1. Generate a random nonce `k`
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 list is sentences. Add periods.

| Rejected | < 580 | any | any | $0 |

`createLoan` handles the status logic. Three outcomes are possible:
- *Approved*: The user asked for less than or equal to their max eligible amount. They get exactly what they asked for.
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 text before the colon should be bold, not italic.


`changePin` is the most complex circuit. When a user changes their PIN, they get a new on-chain identity. But their existing loans are tied to the old identity. All loans need to migrate from the old public key to the new one.

The catch: *zero-knowledge circuits cannot loop over variable-length data*. If a user has 12 loans, you cannot write `for i in 0..loans.size()`. The loop bound must be known at compile time. The solution is *batched migration*:
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.

Beware of overusing italics. If you use it too much, then it becomes meaningless.


| **Data** | **Visibility** | **Why** |
| --- | --- | --- |
| Credit score, income, and tenure | *Private* (witness only) | Never leaves the user's machine |
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.

Remove italics in this table. Overused.


This part covered the foundation of the zero-knowledge loan application:

* *Schnorr signature module*: A Compact module that verifies cryptographic signatures inside a zero-knowledge circuit, ensuring credit data comes from a trusted source.
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.

Text before colon should be bold, not italic.


The next part builds the off-chain infrastructure that makes the smart contract functional:

* *[Attestation API](./attestation-api)*: A REST server that signs credit data with Schnorr signatures, acting as the trusted data provider that the smart contract verifies against.
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.

Actually, I wouldn't format the link text at all. The non-link text before the colon certainly should be bold.

Co-authored-by: David Ozokoye <david.ozokoye@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Olanetsoft and others added 8 commits April 5, 2026 02:49
Co-authored-by: David Ozokoye <david.ozokoye@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Co-authored-by: David Ozokoye <david.ozokoye@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Co-authored-by: DianaHackmamba <diana@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Co-authored-by: DianaHackmamba <diana@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Co-authored-by: DianaHackmamba <diana@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Co-authored-by: DianaHackmamba <diana@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
Co-authored-by: DianaHackmamba <diana@hackmamba.io>
Signed-off-by: Idris Olubisi <heedris2olubisi@gmail.com>
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.

3 participants