Skip to main content

Quick Start

The core lending and verification logic in this repository is working code, not a mockup: the contracts are deployed on Soroban testnet, the tests pass, and the deposit → borrow → repay ZK flow has run end-to-end on-chain (see docs/developers/runbook.md). One known placeholder: get_btc_price_stroops in private-lend/src/oracle.rs returns a hardcoded price pending the real SEP-40/RedStone integration (tracked in docs/roadmap/phases.md) - it does not affect the SPV, ZK, or lending-mechanics logic below, but position pricing is not yet live-market-driven. Start here and have something running in under 5 minutes.

Prerequisites

Install the following before proceeding:

Clone the Repository


Run All Tests

Soroban contracts (Rust)

Expected output: 191 tests pass across bitcoin-spv (49), zk-verifier (25), commitment-tree (32), and private-lend (85).

Bitcoin script toolkit (TypeScript, Bun)

Expected output: 60 tests pass.

Relayer service (TypeScript, Bun install + Jest)

The relayer installs with Bun but its suite is Jest (ts-jest), so it must run through the package script - plain bun test selects Bun’s own runner and fails. It also imports the local @writz/* packages via their built dist/ output, so build those first.
Expected output: 122 tests pass.

ZK circuits (Circom + snarkjs, npm)

Expected output: 29 tests pass (proof generation, commitment correctness, ratio enforcement, nullifiers). If verify() assertions fail here while prove() succeeds, your local circuits/keys/*_final.zkey (gitignored, regenerated locally) is out of sync with the committed circuits/keys/*_vkey.json. Run bash scripts/compile_all.sh && bash scripts/setup_dev.sh to regenerate both together from a fresh dev trusted setup, then re-run npm test.

All together: 402 tests, all passing.


Build the Contracts

This produces Wasm artifacts in contracts/target/wasm32v1-none/release/:
  • bitcoin_spv.wasm - 28.4 KB
  • zk_verifier.wasm - 11.8 KB
  • commitment_tree.wasm - ~38 KB
  • private_lend.wasm - 23.7 KB

Use the Testnet Deployments

All four contracts are live on Soroban testnet. You can call them directly without deploying:

Run the Full ZK End-to-End Flow

This script runs the complete deposit → borrow → repay cycle on Soroban testnet using the deployed contracts. It generates real ZK proofs and submits them on-chain.
This script:
  1. Initializes the commitment-tree contract with a USDC pool
  2. Supplies 1,000 USDC to the pool
  3. Generates a Groth16 deposit proof (circom WASM)
  4. Submits the SPV proof + ZK proof → commitment created on-chain
  5. Inserts the commitment into the Merkle tree (Poseidon root updated)
  6. Generates a Groth16 borrow proof (150% collateral ratio enforced)
  7. Submits the borrow → 200 XLM transferred from pool
  8. Generates a Groth16 repay proof (field-negation amount recovery)
  9. Submits the repay → debt cleared
All 6 transactions land on testnet. You can verify them on Stellar Expert (testnet).

Run the Bitcoin P2WSH End-to-End

This script tests the Bitcoin locking and release flow on Bitcoin Signet. No funds required for a dry run.
The live broadcast will:
  1. Generate a unique P2WSH address
  2. Send Signet BTC to the address
  3. Build the Path A co-signed release transaction
  4. Sign with both user and protocol keys (PSBT round-trip)
  5. Broadcast to Bitcoin Signet
Reference transactions (already executed on Bitcoin Signet):

Deploy Your Own Contracts

If you want to deploy fresh contract instances to testnet:
See contracts/deployments/testnet.md for the full init sequence and verified transaction hashes.

Repository Layout for Developers


Next: Bitcoin SPV SDK →