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 (seedocs/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)
bitcoin-spv (49), zk-verifier (25), commitment-tree (32), and private-lend (85).
Bitcoin script toolkit (TypeScript, Bun)
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 - plainbun test selects Bun’s own runner and
fails. It also imports the local @writz/* packages via their built dist/
output, so build those first.
ZK circuits (Circom + snarkjs, npm)
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
contracts/target/wasm32v1-none/release/:
bitcoin_spv.wasm- 28.4 KBzk_verifier.wasm- 11.8 KBcommitment_tree.wasm- ~38 KBprivate_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.- Initializes the commitment-tree contract with a USDC pool
- Supplies 1,000 USDC to the pool
- Generates a Groth16 deposit proof (circom WASM)
- Submits the SPV proof + ZK proof → commitment created on-chain
- Inserts the commitment into the Merkle tree (Poseidon root updated)
- Generates a Groth16 borrow proof (150% collateral ratio enforced)
- Submits the borrow → 200 XLM transferred from pool
- Generates a Groth16 repay proof (field-negation amount recovery)
- Submits the repay → debt cleared
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.- Generate a unique P2WSH address
- Send Signet BTC to the address
- Build the Path A co-signed release transaction
- Sign with both user and protocol keys (PSBT round-trip)
- Broadcast to Bitcoin Signet
Deploy Your Own Contracts
If you want to deploy fresh contract instances to testnet:contracts/deployments/testnet.md for the full init sequence and verified transaction hashes.
Repository Layout for Developers
Next: Bitcoin SPV SDK →