ClearLend

Inspiration

Getting a loan today means handing over your entire financial history - income statements, tax returns, every debt detail. But honestly, lenders only really need to know one thing: Can you actually afford this?

We wanted to fix that. ClearLend uses zero-knowledge proofs to let borrowers prove they're creditworthy without exposing their actual numbers. Your income stays private. Your debt details stay private. The lender just gets proof that you meet the threshold, and it's cryptographically verified.

What it does

ClearLend is a privacy-first lending platform built on Midnight Network. Here's how it works:

  • Borrowers prove their collateral ratio meets the requirement (income x 2 >= (debt + loan amount) x 3) using ZK proofs. The actual numbers never leave their device.
  • Lenders see only the loan amount and whether the proof checked out. They approve based on that verification.
  • Auditors can request more details if needed. The borrower can voluntarily decrypt their financial data (encrypted with NaCl), and the auditor verifies it matches the on-chain ZK commitment. If the numbers don't match, fraud gets caught immediately.

Why Midnight

Traditional blockchains expose all data or require users to trust centralized third parties. ClearLend needed something different: a blockchain that's built for privacy and can verify proofs directly on-chain without exposing witness data.

That's Midnight's core purpose. Unlike other chains that bolt on privacy as an afterthought, Midnight's architecture is privacy-native. Here's why that matters for ClearLend:

  1. Private State, Public Verification — Midnight lets you keep financial data encrypted on-chain while still allowing anyone to verify it was used in a valid proof. Other chains either expose the data or require off-chain verification, which defeats the purpose of immutability and auditability.

  2. Zk Proofs as a First-Class Citizen — Midnight's Compact language and native proof system mean ZK verification isn't a smart contract doing expensive cryptography—it's how the chain fundamentally works. Our lender never has to worry about the proof being faked or the verification being wrong. Proofs are verified at the protocol level.

  3. No Compromise Between Privacy and Auditability — A core requirement was that auditors could verify a borrower's disclosed data against the on-chain commitment without the borrower being able to change their story afterward. Midnight's commitment model makes this cryptographically guaranteed. You can't achieve this on a transparent chain without some off-chain magic or centralized coordinator.

  4. Developer Experience for Local Proof Generation — Midnight's local proof server and Midnight.js mean we could generate sensitive proofs client-side without relying on APIs that might leak data. Other privacy solutions often require trusting the proof server or using circuits that are less flexible. We could iterate locally and never expose borrower data outside their browser.

How we built it

We wrote a Compact smart contract with 3 circuits to handle the collateral check and store the ZK commitments along with encrypted audit data. On the frontend, we connected Midnight.js to handle wallet stuff (using Lace), generate proofs locally, and send transactions on-chain. The UI lets you switch between borrower, lender, and auditor roles without needing multiple wallets.

Challenges we ran into

1. Local Proof Server Setup

Midnight proofs need to run against a local proof server instead of in the browser. Getting Docker running, configuring it correctly, and ensuring the proof server was accessible took longer than we expected. We hit dependency conflicts, port issues, and spent time troubleshooting the connection. The setup worked once we figured it out, but it's something first-time users will need to work through. It's an area where more streamlined tooling could help the developer experience.

2. Test Network Funding

We started testing on Preprod, but the testnet faucet had rate limits and funding delays. The Preprod RPC connection also had stability issues that made it hard to track transaction status. We switched to Preview for more reliable test funds and consistent network performance. It wasn't ideal, but the switch worked and gave us what we needed to keep building.

3. Browser Environment Setup

Midnight's JavaScript dependencies expect Node.js's Buffer object, which doesn't exist in the browser. We needed to add a polyfill to make it work. Finding the right solution took some digging through bundler configuration and wasn't immediately obvious from the documentation. Once we figured it out, it was solid.

4. Managing Private State Across Flows

Keeping witness data (income, debt) on-device while moving it through proof generation and later auditor verification was complex. We had to design the state flow carefully to keep financial data encrypted and ensure the auditor could verify authenticity without the borrower being able to change their story after the fact. It required thoughtful architecture, but it's exactly the kind of privacy problem Midnight is built to solve.

Accomplishments we're proud of

  • End-to-end flow that works - Wallet connection, proof generation, on-chain verification, auditor disclosure. All of it functions from start to finish.
  • Privacy that holds up - Financial data genuinely never leaves the borrower's device unencrypted. Only the proof and commitment go on-chain. This is only possible because Midnight verifies proofs natively rather than treating them as data.
  • Fraud detection built in - The audit package is cryptographically tied to the proof. If a borrower tries to cheat, it's provably detectable. The immutable on-chain commitment ensures the borrower can't rewrite history.

What we learned

  • Privacy-native blockchains unlock use cases that are impossible on transparent chains. We couldn't have built ClearLend on Ethereum, Solana, or most L1s without either exposing financial data or relying on centralized coordinators. Midnight's architecture made privacy-preserving lending genuinely decentralized.
  • ZK proofs are infrastructure-heavy. Proof servers and WASM bundles require real upfront setup. The barrier to entry is higher than typical Web3 development, but once you get past it, the cryptography is solid. Midnight's local proof server approach is better than alternatives that push verification to APIs.
  • Privacy and usability are genuinely in tension. We had to make real tradeoffs between what's secure and what's simple. Some features that would've been nice had to go because they'd have complicated the flow too much.

What's next for ClearLend

  • Real collateral ratios - Work with actual lenders to figure out what thresholds make sense for different loan types.
  • Batch proofs - Support multiple loans in one transaction to reduce fees.
  • Mobile wallet support - Right now it's browser-only with Lace. Extending to mobile wallets would make it more accessible.

Built With

  • docker
  • lace-wallet
  • midnight
  • midnight.js
  • naci(encryption)
  • node.js
  • react-19
  • tailwind-css
  • tanstack
  • typescript
  • vite
  • zero-knowledge-proofs
Share this project:

Updates

Submission history