Skip to content

Shielded Concentrated Liquidity Market Maker (CLMM) for Bitcoin on Starknet

License

Notifications You must be signed in to change notification settings

salazarsebas/Zylith

Repository files navigation

Zylith Logo

Zylith

Shielded Concentrated Liquidity Market Maker for Bitcoin on Starknet

Cairo Starknet License Hackathon

OverviewFeaturesArchitectureGetting StartedDocs


Overview

Zylith is the first privacy-native Concentrated Liquidity Market Maker (CLMM) built for Bitcoin DeFi on Starknet. Every swap, mint, and burn is shielded by default through zero-knowledge proofs — no opt-in required, no metadata leaks.

Zylith delivers the capital efficiency of concentrated liquidity with a privacy layer that existing DEXs cannot offer: positions are hidden behind commitments, trade amounts are verified without being revealed, and LP ownership is decoupled from on-chain addresses.

Why Zylith?

Existing DEXs Zylith
Public positions visible to everyone Shielded positions via Poseidon commitments
Swap amounts leaked on-chain Private swap verification with ZK proofs
LP ownership tied to addresses Commitment-based ownership (unlinkable)
Privacy as afterthought Privacy by default
No native Bitcoin focus First-class Bitcoin pools (tBTC, WBTC, LBTC)

Built for the RE{DEFINE} Hackathon - Starknet's Bitcoin & Privacy Hackathon 2026


Key Features

Privacy Layer

  • Shielded Notes: Commitments using Poseidon(Poseidon(secret, nullifier), amount)
  • Merkle Tree: On-chain commitment storage with historical root tracking
  • Nullifier Registry: Double-spend prevention
  • ZK Verification: Groth16 proofs via Garaga

CLMM Engine

  • Concentrated Liquidity: Full-range and narrow tick positions with Q128.128 precision
  • Tick Management: Bitmap-based tick navigation for gas-efficient traversal
  • Fee Accounting: Per-position fee growth tracking with protocol fee capture
  • Precise Arithmetic: u128/u256 wide arithmetic — no precision loss at any scale

Bitcoin Integration

  • Multi-Token Support: tBTC, WBTC, LBTC
  • Bridge Agnostic: Compatible with Garden Finance, StarkGate
  • BTC-Native Pools: First-class Bitcoin trading pairs

Architecture

flowchart TB
    subgraph User["User Layer"]
        W[Wallet]
        SDK[Zylith SDK]
    end

    subgraph Privacy["Privacy Layer"]
        SN[Shielded Notes]
        MT[Merkle Tree]
        NR[Nullifier Registry]
    end

    subgraph CLMM["CLMM Engine"]
        PS[Pool State]
        TM[Tick Manager]
        SE[Swap Engine]
        LM[Liquidity Manager]
    end

    subgraph Verification["Verification Layer"]
        CC[Circom Circuits]
        GV[Garaga Verifier]
    end

    subgraph External["External"]
        ASP[ASP Server]
        BTC[Bitcoin Bridges]
    end

    W --> SDK
    SDK --> SN
    SN --> MT
    MT --> NR

    SDK --> SE
    SE --> PS
    SE --> TM
    LM --> PS
    LM --> TM

    SN --> CC
    CC --> GV
    GV --> SE
    GV --> LM

    ASP --> MT
    BTC --> PS
Loading

System Flow

┌─────────────────────────────────────────────────────────────────┐
│                        PRIVATE SWAP FLOW                        │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  1. User creates commitment: C = H(H(secret, nullifier), amt)   │
│                              │                                  │
│  2. Deposit tokens ──────────┼──► Commitment added to Merkle    │
│                              │                                  │
│  3. Generate ZK proof:       │                                  │
│     • Membership proof       │                                  │
│     • Nullifier uniqueness   │                                  │
│     • Swap math correctness  │                                  │
│                              │                                  │
│  4. Submit to Zylith ────────┼──► Garaga verifies proof         │
│                              │                                  │
│  5. CLMM executes swap ──────┼──► New commitment created        │
│                              │                                  │
│  6. Nullifier recorded ──────┴──► Prevents double-spend         │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Technical Stack

Core Development

Tool Version Purpose
Cairo 2.9.1 Smart contract language
Scarb 2.15.1 Package manager & build tool
Starknet Foundry 0.55.0 Testing framework
Starkli 0.4.x CLI for Starknet

ZK/Privacy Stack

Tool Version Purpose
Garaga 1.0.1 Groth16 verification on Starknet
Circom 2.x ZK circuit development
snarkjs 0.7.x Proof generation
Python 3.10+ Garaga CLI requirement

Backend & SDK

Tool Version Purpose
Rust 1.75+ ASP server runtime
Bun / Node.js 18+ Proof worker, SDK, frontend
TypeScript 5.6+ SDK & frontend

Libraries

Library Version Purpose
OpenZeppelin Cairo 1.0.0 ERC20, security patterns
Alexandria 0.9.0 Math utilities

Getting Started

Prerequisites

  • Unix-based OS (Linux/macOS)
  • Git
  • Python 3.10
  • Rust (for ASP server)
  • Node.js 18+ (for Circom/snarkjs)

Installation

  1. Install Starknet development tools
curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.sh | sh
  1. Clone the repository
git clone https://github.com/salazarsebas/Zylith.git
cd Zylith
  1. Install dependencies
scarb build
  1. Install Garaga
pip install garaga
  1. Install Circom
npm install -g circom snarkjs

Quick Start

# Build contracts
scarb build

# Run tests
scarb test

# Format code
scarb fmt

Project Structure

zylith/
├── src/                              # Cairo smart contracts
│   ├── pool/
│   │   └── contract.cairo            # ZylithPool singleton (CLMM + shielded ops)
│   ├── clmm/
│   │   ├── math/
│   │   │   ├── sqrt_price.cairo      # Q128.128 sqrt price math
│   │   │   ├── tick_math.cairo       # Tick ↔ price conversions
│   │   │   └── liquidity.cairo       # Liquidity delta math
│   │   ├── swap.cairo                # Swap engine (compute_swap_step)
│   │   ├── positions.cairo           # LP position management
│   │   ├── tick_bitmap.cairo         # Bitmap-based tick navigation
│   │   └── fees.cairo                # Fee growth accounting
│   ├── privacy/
│   │   ├── notes.cairo               # Shielded note structures
│   │   ├── merkle.cairo              # Incremental Merkle tree (height 20)
│   │   ├── nullifier.cairo           # Nullifier registry
│   │   └── commitment.cairo          # Commitment utilities
│   ├── verifier/
│   │   ├── coordinator.cairo         # VerifierCoordinator contract (ZK proofs + Merkle)
│   │   └── types.cairo               # Proof structs and public input extraction
│   ├── interfaces/                   # Trait definitions (IZylithPool, IVerifierCoordinator, etc.)
│   ├── types.cairo                   # Shared types (PoolKey, PoolState, TickInfo, etc.)
│   └── tests/                        # Integration tests (mock_erc20, mock_coordinator, test_pool)
│
├── circuits/                         # Circom ZK circuits
│   ├── membership.circom             # Merkle membership proof
│   ├── swap.circom                   # Private swap verification
│   ├── liquidity.circom              # PrivateMint / PrivateBurn templates
│   ├── mint.circom / burn.circom     # Entry points
│   ├── common/                       # Shared templates (commitment, merkle, poseidon)
│   └── scripts/                      # Compilation, setup, proof generation
│
├── garaga_verifiers/                 # Auto-generated Groth16 BN254 verifiers (scarb 2.14.0)
│   ├── membership_verifier/
│   ├── swap_verifier/
│   ├── mint_verifier/
│   └── burn_verifier/
│
├── asp/                              # Anonymous Service Provider (Rust + Bun worker)
│   ├── src/                          # Axum server, SQLite, Starknet relayer
│   └── worker/                       # Node.js proof generation worker
│
├── sdk/                              # @zylith/sdk TypeScript client SDK
│   └── src/                          # Client, ASP HTTP client, crypto, prover, Starknet readers
│
├── frontend/                         # React web application
│   └── src/                          # Vite + React + TailwindCSS
│
├── scripts/
│   ├── deploy.sh                     # Starknet Sepolia deployment
│   └── validate_testnet.mjs          # End-to-end testnet validation
│
├── Scarb.toml                        # Cairo package config (starknet 2.9.1, scarb 2.15.1)
└── README.md

Core Components

CLMM Engine

The CLMM engine implements full concentrated liquidity mechanics with Q128.128 fixed-point precision:

Pool State

#[derive(Drop, Serde, starknet::Store)]
struct PoolState {
    sqrt_price: u256,        // 128.128 fixed point
    tick: i32,               // Current tick
    liquidity: u128,         // Active liquidity
    fee_growth_global_0: u256,
    fee_growth_global_1: u256,
    protocol_fees_0: u128,
    protocol_fees_1: u128,
}

Tick Structure

#[derive(Drop, Serde, starknet::Store)]
struct TickInfo {
    liquidity_gross: u128,
    liquidity_net: i128,
    fee_growth_outside_0: u256,
    fee_growth_outside_1: u256,
    initialized: bool,
}

Privacy Layer

Commitment Structure

commitment = Poseidon(
    Poseidon(secret, nullifier),
    amount
)

Merkle Tree

  • Height: 20 (~1M leaves)
  • Hash: BN128 Poseidon (off-chain) / admin root submission (on-chain)
  • Incremental updates via ASP
  • Historical root storage

Verifier Integration

Garaga-generated Groth16 verifier for:

  • Membership proofs
  • Swap transition proofs
  • LP operation proofs

Bitcoin Integration

Supported Tokens

Token Bridge Contract
tBTC Threshold Network TBD
WBTC StarkGate TBD
LBTC Lombard TBD

Creating a BTC Pool

// Initialize a tBTC/USDC pool
fn create_btc_pool(
    tbtc_address: ContractAddress,
    usdc_address: ContractAddress,
    fee_tier: u32,
    initial_sqrt_price: u256
) -> ContractAddress;

Bridging Bitcoin

  1. Via Garden Finance (recommended for direct BTC)

  2. Via StarkGate (for WBTC holders)

    • Bridge WBTC from Ethereum
    • Mint native WBTC on Starknet

Circuits

Membership Circuit

template Membership(levels) {
    signal input root;
    signal input leaf;
    signal input pathElements[levels];
    signal input pathIndices[levels];

    // Verify Merkle path
    component hasher[levels];
    // ... implementation

    root === computedRoot;
}

Swap Circuit

template PrivateSwap() {
    // Private inputs
    signal input secret;
    signal input nullifier;
    signal input amount_in;
    signal input pathElements[20];
    signal input pathIndices[20];

    // Public inputs
    signal input root;
    signal input nullifier_hash;
    signal input amount_out_commitment;
    signal input sqrt_price_after;

    // Verify note ownership
    component membership = Membership(20);

    // Verify swap math
    component swap = SwapMath();

    // Output new commitment
    // ...
}

Testing

Run All Tests

scarb test

Run Specific Tests

snforge test test_swap
snforge test test_privacy --exact

Coverage Report

snforge test --coverage

Integration Tests

# Start local Starknet node
katana --accounts 3 --seed 0

# Run integration tests
snforge test --filter integration

Deployment

Testnet (Sepolia)

  1. Configure environment
cp .env.example .env.local
# Edit .env.local with your RPC URL, account, keystore, and password
  1. Build & deploy
# Build contracts (release profile for smaller Sierra)
SCARB_PROFILE=release scarb build

# Deploy all contracts (verifiers, coordinator, pool)
bash scripts/deploy.sh

Deployed addresses are written to scripts/deployed_addresses.json.


Roadmap

MVP (Hackathon - Feb 2026)

  • Project setup & architecture
  • CLMM core (swap, liquidity, fees)
  • Privacy layer (notes, Merkle tree, nullifiers)
  • Circom circuits (membership, swap, mint, burn)
  • Garaga verifier integration
  • ASP server (Rust + Bun worker)
  • TypeScript SDK (@zylith/sdk)
  • Frontend web application
  • Test suite (70 Cairo tests + 42 ASP E2E tests + SDK unit tests)
  • Testnet deployment (Starknet Sepolia)
  • End-to-end proof verification on-chain

Post-Hackathon

  • Private multi-hop routing
  • Private tick range selection
  • Private limit orders
  • Proof aggregation
  • Full audit
  • Mainnet launch

Contributing

We welcome contributions! Please see our Contributing Guide for details.

# Fork and clone
git clone https://github.com/salazarsebas/Zylith.git

# Create branch
git checkout -b feature/your-feature

# Make changes and test
scarb test

# Format code
scarb fmt

# Submit PR

Security

This project is under active development for a hackathon. Do not use in production.

Found a vulnerability? Please report it responsibly:


License

This project is licensed under the MIT License - see the LICENSE file for details.


Team

Kevin Membreno
Core Developer
Josue Araya
Core Developer
Sebastian Salazar
Core Developer
Sandeep Chauhan
Core Developer

Acknowledgments


Built with STARK proofs on Starknet

About

Shielded Concentrated Liquidity Market Maker (CLMM) for Bitcoin on Starknet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published