Skip to main content

Quick Start

Everything in this repository is working code. There are no placeholders, no “coming soon” sections, no hand-waving. The contracts are deployed on Soroban testnet. The tests pass. 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: 146 tests pass across bitcoin-spv (47), zk-verifier (18), commitment-tree (18), and private-lend (63).

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: 48 tests pass.

ZK circuits (Circom + snarkjs, npm)

Expected output: 20 tests pass (proof generation, commitment correctness, ratio enforcement, nullifiers).

All together: 274 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 →