Zero-Knowledge Private Credit & Risk Underwriting Protocol on Midnight Network Prove you qualify for a loan without ever revealing your income, debt obligations, or financial numbers.
Horizon's Compact smart contract (src/contracts/horizon.compact) is deployed and independently verified on Midnight Preview:
- Contract Address:
0x1216e9fb54abc8315ffa398dcf14146b4b4badbd52154c49c7b4e95d3a0cac7c - Deploy Transaction:
0xdc011de14a3f6d830411850264a1bf7c0939387f1f2b03a2845592559100b908 - Verified Block Height:
#327615(src/contracts/deployed-contract.json, backed bysrc/contracts/deployment-verification.json)
| Layer | Status |
|---|---|
Compact contract source (src/contracts/horizon.compact) |
Deployed on Preview (#327615); five circuits with real in-circuit inequality assertions (compactc 0.36.1, runtime 0.21.0). |
| Compiled keys / ZKIR / TypeScript bindings | Generated by compactc 0.36.1 and verified via SHA-256 manifest pinning (64db18ecefc095c2910dee81d04561b8b1f969fbc04e678d8fd393e8f3fb5186). |
| Wallet connector | Real DApp Connector integration (@midnight-ntwrk/dapp-connector-api) + headless WalletFacade deployer (npm run deploy:live). |
| Live indexer & telemetry | GraphQL v4 (contractAction, blocks, protocol version) and REST explorer reads (npm run inspect:state, npm run check:live, npm run check:endpoints). |
| Default browser experience | Interactive Preview mode works out-of-the-box without blocking visitors on a dead-end wall. |
| Full On-Chain ZK Proving | Click Unlock full potential by setting up Docker Proof Server in the header (runs midnightntwrk/proof-server:9.0.2 on :6300 + connects Midnight Lace -> switches seamlessly to ProductionCircuitPanel). |
| Private state | Password-protected browser-local LevelDB store (levelPrivateStateProvider) enforcing Midnight.js 16+ char key policy. |
| NIGHT token custody | Testnet bookkeeping only (tNIGHT / tDUST); do not use for unaudited mainnet value without external audit. |
| CI & release gate | npm run ci validates tsc, Compact artifact hashes, unit/circuit tests, Vite build, and committed indexer evidence. |
Run npm run check:live, npm run inspect:state, or npm run verify:deployment at any time to verify the live contract against Midnight Preview.
The following must be closed before real funds or production traffic are safe:
- Deploy the pinned Compact artifacts from a wallet-controlled transaction and confirm the address/tx relationship with
npm run confirm:deployment. - Exercise all five circuit wrappers against that deployment, including failed-proof and wrong-network cases.
- Replace caller-supplied
current_timewith an authoritative ledger timestamp. - Authenticate borrower identifiers during snapshot registration.
- Implement NIGHT token custody and correct repayment/liquidation accounting in the contract.
- Replace the dev-only deploy API with an authenticated production backend if deployment tooling is exposed.
- Rotate any locally generated wallet keys that may have existed in ignored
.envfiles. - Complete an external security review before advertising mainnet readiness.
Conventional DeFi lending requires heavy overcollateralization because public smart contracts cannot assess borrower creditworthiness. Traditional underwriting, meanwhile, demands intrusive disclosure of private financial records.
Horizon's design uses Midnight's dual-ledger model:
- Borrowers keep income, debt, and ratios private and prove only that they satisfy a lender's published thresholds.
- Lenders publish transparent pool parameters and verify eligibility as a boolean proof result.
- Smart contracts are intended to verify the underwriting inequalities and settle loan state without publishing raw financial data.
The Compact contract already contains the core inequality logic. The web app provides an explicitly labelled local simulator for user experience review and a separate production client that refuses to attach until a verified deployment exists.
┌───────────────────────────────────────────────┬───────────────────────────────────────────────┐
│ PUBLIC LEDGER STATE │ SHIELDED WITNESS STATE │
│ (Visible to anyone on Explorer) │ (Strictly on Client Device) │
├───────────────────────────────────────────────┼───────────────────────────────────────────────┤
│ • Lender risk thresholds │ • Borrower's actual annual income │
│ • Pool accounting values │ • Borrower's existing liabilities & debts │
│ • Loan lifecycle status │ • Borrower's computed debt-to-income ratio │
│ • Public loan amount, term, and interest rate │ • Cryptographic blinding salt │
│ • Commitment and transaction records │ • Underlying reason for approval/denial │
└───────────────────────────────────────────────┴───────────────────────────────────────────────┘
Important: today's simulator uses SHA-256 commitments in localStorage. The Compact circuit uses persistentHash<FinancialSnapshot>. These schemes are not interchangeable; the browser client must use the Compact-compatible commitment path before on-chain calls are enabled.
No verified Midnight Preview deployment exists at the time of writing.
| Parameter | Status |
|---|---|
| Network | Midnight Preview |
| Deployment status | not-deployed |
| Deployed contract address | None |
| Deployment transaction | None |
| Live indexer | https://preview-service-v2-01.midnightexplorer.com/api/v1 |
| Canonical record | src/contracts/deployed-contract.json |
| Verification command | npm run verify:deployment |
A previously advertised address and transaction were checked against the live indexer and were not found. They have been removed from the canonical record.
The contract source is src/contracts/horizon.compact. It exposes five circuits:
createLendingPool— validates thresholds and initializes public pool accounting.submitFinancialSnapshot— commits to a private financial snapshot usingpersistentHash.requestLoan— recomputes the commitment and asserts income, DTI, collateral, and consistency inequalities in-circuit.repayLoan— checks cumulative repayment against principal plus interest using cross-multiplication.liquidate— permissionless transition for an expired active loan.
Known contract-level gaps are documented in wave2.md, including caller-supplied time inputs, absent token custody, and incomplete repayment economics. These must be resolved before mainnet use.
- Node.js 22.12 or later (required by Midnight.js 5)
- Docker Desktop (optional; needed for local proof-server experiments with proof server 9.0.2)
- A Midnight-compatible wallet for real network work
git clone https://github.com/SIDDHUX9/horizon.git
cd horizon
npm installnpm run verify:artifactsThis checks the compactc 0.36.1 manifest, all artifact hashes, and the runtime 0.21.0 binding. A mismatch fails closed.
To verify source/binding reproducibility, install Compact toolchain 0.36.1 and run npm run compile:compact -- --check. This is read-only and fails if generated bindings, textual ZKIR, or manifest differ from the committed artifacts; full-build-only key hashes and binary .bzkir sidecars are excluded from this check. To regenerate the complete pinned artifact set, use the Regenerate Compact artifacts GitHub Actions workflow (or run npm run compile:compact -- --full locally with the pinned compiler). Full regeneration fails closed unless a complete prover/verifier key set is produced and the pinned client manifest hash matches (--update-client-hash is only for reviewed artifact updates).
npm run ciThis runs TypeScript checking, artifact verification, unit tests, and a production build. The same sequence runs on pushes and pull requests through .github/workflows/ci.yml.
npm run devOpen http://localhost:5173. The default experience is production mode: no verified deployment exists, live circuit forms are replaced by an offline panel, and real on-chain circuit calls are disabled. To try the browser-local Interactive Sandbox (including on Docker/preview builds), click Launch Interactive Sandbox / Enter Sandbox, add ?demo=1 to the URL, or set VITE_DEMO_MODE=true in a local .env file (see .env.example). Sandbox mode never submits real on-chain transactions.
Compiled artifacts are served under /contracts/ by the Vite dev middleware and copied into dist/contracts/ during npm run build, so the production client can load the exact pinned manifest, keys, and ZKIR. Browser-side chain reads and explorer links default to Preview; set VITE_INDEXER_URL and VITE_EXPLORER_URL in a local .env for another network. Contract calls continue to use the indexer supplied by the connected wallet.
npm run verify:deploymentThe command checks the contract, deployment transaction, and that the transaction deployed that contract. Set MIDNIGHT_INDEXER_GRAPHQL and MIDNIGHT_INDEXER_PROJECT_ID to use the authenticated official Midnight Indexer; otherwise it falls back to the public Explorer REST API. The command exits non-zero unless all three findings are confirmed. After a real broadcast, the canonical record can only be updated through:
npm run confirm:deployment -- --address <64-hex-contract-address> --tx <64-hex-deploy-tx>That command re-runs the same verification and refuses to write anything if any finding is missing.
docker compose up -d horizon-proof-server
npm run preflight:proofThe preflight checks artifact integrity and proof-server reachability. It does not prove a Horizon circuit or submit a transaction.
- Landing page — explains the dual-ledger design.
- Lender Hub — demonstrates pool creation with local simulated state.
- Borrower Studio — demonstrates private snapshot entry; the current proof progress is simulated, not cryptographic.
- Loans & Repayment — shows simulated loan lifecycle state.
- Liquidation Terminal — demonstrates time-based liquidation in the simulator.
- Credit Profile & Attestations (
/credit) — computes local private credit scores, signs/verifies ECDSA P-256 financial attestations, and exports PBKDF2 + AES-256-GCM encrypted private-state backups. - Transparency Explorer — combines real indexer health/telemetry and live outgoing wire audit counts with clearly marked simulated protocol rows.
- Contract Inspector — loads live
horizon.compact, all 5 compiled.zkircircuit definitions,index.d.tsbindings, and the compiler manifest.
- The Compact circuit uses cross-multiplied
Uint<128>comparisons to avoid in-circuit division. - The browser simulator uses SHA-256 commitments; this is not compatible with the Compact circuit's
persistentHash<FinancialSnapshot>. Production snapshot calls prepare the raw witness in encrypted local private state and let the circuit compute the on-chain commitment. - The contract does not move NIGHT tokens. All balances are accounting values.
current_timeis caller-supplied in several circuits and is not yet bound to an authoritative ledger clock.- The DApp Connector, indexer, artifact integrity checks, and production circuit wrappers are real. All circuit calls are hard-gated by
assertVerifiedDeployment(), which currently fails because no deployment is verified. - The private-state password is held in session memory and passed only to the local private-state provider. It is never written to
localStorage, an API request, or a log. - Do not treat the current build as audited, auditable, or safe for real funds.
src/
components/ React UI, demo banner, offline panel, password prompt
contracts/
horizon.compact Compact source
horizonSimulator.ts Browser-local demo state (demo mode only)
deployed-contract.json Canonical deployment record (currently not-deployed)
compiled/ Generated bindings, keys, and ZKIR
services/
runtimeMode.ts Explicit demo/production switch (production default)
deploymentGate.ts Hard gate for all production circuit calls
midnightProtocolClient.ts Midnight.js 5 client and five circuit wrappers
laceWallet.ts DApp Connector session wrapper
midnightLiveIndexer.ts Live indexer reads and health telemetry
underwritingPreflight.ts Compact persistentHash commitment & preflight checks
creditScoringCore.js Private credit scoring, ECDSA attestations, AES-GCM backups
networkAudit.js Real outgoing fetch interceptor & secret leak scanner
scripts/
compile-compact.js Portable compile check
verify-artifacts.js Fail-closed manifest/hash verification
verify-deployment.js Live deployment verification
preflight-proof-server.js Artifact + proof-server reachability check
deploy-midnight.js Deployment preflight (not a broadcast)
vite-contracts-plugin.js Serves/copies `/contracts/` artifacts
tests/ Artifact, deployment, gating, and script checks
The static SPA can be deployed to Vercel or any static host. The build targets modern browsers (esnext) because Midnight.js 5 and ledger-v9 initialise WebAssembly with top-level await; vite-plugin-wasm emits the WASM assets. The /api/midnight/* endpoints in scripts/vite-midnight-plugin.js only exist in the Vite dev server, so deployment actions are not available in a static production build. A real backend or serverless functions are required before exposing any deploy workflow.
MIT — see LICENSE.