Superseded values notice: This document predates several Phase 0/1 decisions and is kept for historical architecture context only. Where it conflicts withdocs/research/circom-circuit-design.md,docs/research/interest-rate-model.md,docs/research/oracle-design.md, or the contract source (contracts/contracts/writz-lend/src/), those are the sources of truth, not this file. Known stale values below have been corrected inline; treat any other specific number in this document as unverified until cross-checked against the docs above.
System Architecture
Writz Protocol operates across two blockchains: Bitcoin and Stellar. The architecture is designed to be trustless on the verification layer. Positions are plaintext: amounts, collateral and addresses are public on chain. Privacy is not part of the protocol; it is being designed as a separate, opt-in edition, in progress (seedocs/how-it-works/privacy-edition.md).
Component Breakdown
1. P2WSH Locking Script (Bitcoin)
The BTC locking mechanism lives entirely on Bitcoin. It is a Pay-to-Witness-Script-Hash (P2WSH) address whose redeem script encodes two spending conditions using Bitcoin Script. Script design (simplified):- Both the protocol and the user sign the release transaction
- This is triggered when the user repays their USDC loan
- The Soroban contract generates the co-signature upon verifying repayment
- After a predefined locktime (e.g., loan maturity + 30 days), the user can spend without the protocol’s signature
- Protects users if the protocol becomes unavailable
2. Bitcoin SPV Contract (Soroban)
The core of Writz’s technical innovation. A Soroban smart contract that verifies Bitcoin transactions cryptographically. Approach: an on-chain header light clientbitcoin-spv keeps a compact chain of Bitcoin block headers on Stellar, anchored at a checkpoint block that is set once and never changed. Relayers submit new headers with submit_headers; each one must descend from a stored header, carry valid proof of work at exactly the difficulty Bitcoin’s retarget rules require, and accumulate chainwork, and the contract tracks the most-work chain. A transaction is then proven against a header the contract already stored, so a caller cannot present a header chain it mined privately. An earlier stateless design, in which the caller supplied the headers at verification time, was replaced for that reason. See How SPV Verification Works and SPV vs Wrapped Bitcoin.
Core functions:
writz-lend::deposit rebuilds the expected Writz P2WSH script from the protocol key, the depositor’s key and the timelock, and requires the deposit output to match it.
Cryptographic operations required:
SHA256d(double-SHA256): Bitcoin’s primary hash function - used for block hashes, txids, Merkle tree nodes- Merkle proof verification: O(log n) SHA256d operations for n transactions in the block
- Block header PoW verification: check that
SHA256d(header) < target - Header chain continuity: verify each header’s
prev_block_hashmatches a stored header - Difficulty retargeting and cumulative chainwork, to follow the most-work chain
3. Privacy (not part of the protocol)
Writz v1 has no privacy layer. Positions, amounts and collateral are public on chain. An opt-in privacy edition with its own contracts (commitment-tree, zk-verifier, Circom circuits verified with Groth16 on Soroban), its own pool, audit and trusted-setup ceremony is in progress on testnet and planned for after v1 is live on mainnet, with no date. See docs/how-it-works/privacy-edition.md.
4. Writz Lend Contract (Soroban)
The lending logic that sits above the SPV layer. Key parameters (to be finalized in Phase 0):- Collateralization ratio: 150% minimum (BTC value must be 1.5x the USDC borrowed)
- Liquidation threshold: 120% (position liquidated if BTC/USDC ratio drops below this)
- Liquidation bonus: 10% of debt, paid in USDC from the protocol reserve (funded by 15% of interest), capped at the reserve balance
- Borrow rate: variable, determined by utilization ratio (similar to Blend/Aave)
- Supply rate: borrow rate × utilization × (1 - protocol fee percentage)
- Protocol fee: 15% of interest spread (finalized; see
PROTOCOL_FEE_BPincontracts/contracts/writz-lend/src/rates.rsanddocs/research/interest-rate-model.md)
docs/research/interest-rate-model.md.)
Liquidation flow:
- A designated keeper monitors positions, which are public on chain
- When a position drops below 120% collateralization at the oracle price, the keeper calls
liquidate; the contract re-checks the ratio itself - If the keeper has been inactive for 24 hours (no liquidation and no heartbeat), any caller may liquidate an undercollateralized position
- Liquidator pays USDC and receives a USDC bonus from the protocol reserve; no BTC is released (GHSA-5rxp-7f9g-r66x)
5. USDC Liquidity Pools (Stellar native)
The supply side of Writz Lend, and what Earn means on Writz. USDC lenders supply the pool withsupply_usdc and earn the interest borrowers pay. This is standard Stellar asset mechanics - no novel engineering required.
- Lenders supply USDC → the contract records a scaled balance that grows with the supply index (no receipt token)
- Borrowers draw from the pool against their BTC collateral
- Interest accrues continuously;
withdraw_supplyreturns principal plus interest at any time, up to the USDC not lent out
6. Open SDK
A Rust crate that wraps the SPV verification logic, making it consumable by any other Soroban developer.Data Flow - Full User Journey
Deposit + Borrow
Repay + Withdraw
Liquidation
Security Considerations
Bitcoin-side risks
Soroban-side risks
Economic risks
Technology Stack
Last updated: 2026-06-22 - This document is preliminary. Architecture will be updated after Phase 0 benchmarks confirm feasibility of SPV in Soroban.