Skip to content

AbdelStark/doko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Doko Logo

Doko

Bitcoin CTV & CSFS Proof-of-Concept Showcase

Rust Bitcoin MIT License

A comprehensive collection of Bitcoin use cases showcasingOP_CHECKTEMPLATEVERIFY (CTV) and OP_CHECKSIGFROMSTACK (CSFS).

Built for Mutinynet signet with CTV and CSFS activation

⚠️ Disclaimer: This is an experimental project for educational purposes.


🎯 Overview

Doko demonstrates Bitcoin smart contract capabilities through multiple proof-of-concept implementations. Each use case showcases different aspects of covenant-based Bitcoin programming using CTV for transaction templates and CSFS for signature delegation.

Available Use Cases

Use Case Description Key Features
Simple Vault Basic time-locked Bitcoin vault CTV covenant, CSV timelock, emergency recovery
Hybrid Vault Corporate treasury with delegation Multi-path Taproot, CTV + CSFS, role-based access
Nostr Vault Key delegation using Nostr CSFS + Nostr events, onchain signature verification
Prediction Market Nostr based Bitcoin prediction market Oracle integration, proportional payouts, real Bitcoin

πŸ“¦ Use Cases

πŸ”’ Simple Vault (CTV-Only)

Overview

A basic Bitcoin vault using CheckTemplateVerify (CTV) covenants for time-locked withdrawals with emergency recovery capabilities.

Key Features

  • CTV Covenant Protection: Funds locked by transaction template
  • CSV Timelock: Configurable delay for hot withdrawals
  • Emergency Recovery: Immediate cold storage clawback
  • NUMS Internal Key: Script-spend only security

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    CTV    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    IF/ELSE    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Vault     β”‚ ────────► β”‚   Trigger    β”‚ ────────────► β”‚  Final       β”‚
β”‚   (P2TR)     β”‚           β”‚   (P2TR)     β”‚               β”‚ Destination  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   Covenant                   Conditional                   Hot or Cold
   Protection                 Spending                        Wallet

Usage

# Cold recovery scenario
cargo run -- auto-demo --vault-type simple --scenario cold-recovery

# Hot withdrawal scenario
cargo run -- auto-demo --vault-type simple --scenario hot-withdrawal

# Interactive dashboard
cargo run -- dashboard --vault-type simple

Transaction Flow

  1. Deposit: Fund vault P2TR address with CTV script
  2. Trigger: Anyone can broadcast exact trigger transaction
  3. Withdraw: Either hot (after CSV delay) or cold (immediate)
πŸ”€ Hybrid Vault (CTV + CSFS)

Overview

Advanced corporate treasury vault combining CTV covenants with CSFS delegation for multi-path Taproot spending scenarios.

Key Features

  • Dual-Path Taproot: CTV covenant + CSFS delegation
  • Role-Based Access: Treasurer, operations, hot/cold wallets
  • Flexible Spending: Timelock OR delegation paths
  • Corporate Treasury: Real-world organizational structure

Architecture

                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚      Hybrid Vault UTXO (P2TR)    β”‚
                     β”‚        (NUMS Internal Key)        β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚ Script-Path Spend
                                       β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚                                         β”‚
                  β–Ό                                         β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Path 1: CTV Covenant Script  β”‚          β”‚  Path 2: CSFS Delegation     β”‚
   β”‚ (<trigger_hash> OP_CTV)      β”‚          β”‚(<sig> <msg> <pubkey> OP_CSFS)β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚                                         β”‚
                  β–Ό                                         β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                 β”‚                      β”‚   Delegated     β”‚
         β–Ό                 β–Ό                      β”‚   Spending      β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚  Transaction    β”‚
β”‚   πŸ”₯ HOT PATH   β”‚   β”‚   ❄️ COLD PATH  β”‚        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚   (IF Branch)   β”‚   β”‚  (ELSE Branch)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Usage

# Hot withdrawal via CTV covenant
cargo run -- auto-demo --vault-type hybrid --scenario hot-withdrawal

# Cold recovery via CTV covenant
cargo run -- auto-demo --vault-type hybrid --scenario cold-recovery

# CSFS delegation spending
cargo run -- auto-demo --vault-type hybrid --scenario csfs-delegation

# Interactive dashboard
cargo run -- dashboard --vault-type hybrid

Corporate Roles

  • Treasurer: CSFS delegation authority
  • Operations: Delegated spending recipient
  • Hot Wallet: Time-locked withdrawals
  • Cold Wallet: Emergency recovery
🌐 Nostr Vault (CSFS + Nostr)

Overview

Decentralized social signature verification system using CSFS to verify Nostr event signatures directly on the Bitcoin blockchain.

Key Features

  • Nostr Integration: Real Nostr event generation and signing
  • Onchain Verification: CSFS validates Nostr signatures
  • Social Consensus: Decentralized signature authority
  • Event Hash Binding: Cryptographic link to social events

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    Nostr Event    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Social Layer  β”‚ ────────────────► β”‚  Bitcoin Layer  β”‚
β”‚  (Nostr Event)  β”‚                   β”‚ (CSFS Spending) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   Schnorr Sig                         Signature Verification
   Event Content                       Onchain Validation

Usage

# Nostr signature verification demo
cargo run -- auto-demo --vault-type nostr

# View detailed Nostr event information
cargo run -- auto-demo --vault-type nostr --scenario detailed

Technical Details

  • Nostr Events: Standard Nostr event format with content and signature
  • CSFS Verification: Onchain signature validation using OP_CHECKSIGFROMSTACK
  • Event Binding: Hash commitment to specific social events
  • Schnorr Signatures: Compatible with Bitcoin's signature format
πŸ“Š Prediction Market (Nostr + CSFS)

Overview

Bitcoin prediction market using Nostr oracles and CSFS for outcome verification with real Bitcoin operations.

Key Features

  • Nostr Oracle Integration: Decentralized outcome resolution
  • Proportional Payouts: Winners split pool based on bet size

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    Bet     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    Oracle    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Participants  β”‚ ────────► β”‚ Market Address  β”‚ ───────────► β”‚  Payout CSFS    β”‚
β”‚    (Bettors)    β”‚           β”‚   (Taproot)     β”‚              β”‚  Transaction    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   Multiple bets                Dual outcome                    Winner claims
   Different outcomes           scripts A/B                     Proportional share

Usage

# Run full prediction market demo
cargo run --bin demo_prediction_market

# Run with automatic mode (no manual prompts)
cargo run --bin demo_prediction_market -- --auto

# Command-line market management
cargo run --bin nostr_market -- --help

Market Flow

  1. Market Creation: Define question, outcomes, oracle, settlement time
  2. Betting Phase: Participants fund market with real Bitcoin
  3. Price Monitoring: Live Bitcoin price tracking via CoinGecko API
  4. Oracle Settlement: Nostr oracle signs outcome at settlement time
  5. Payout Distribution: Winners claim proportional shares via CSFS

Technical Implementation

  • Taproot Scripts: Dual-path scripts for binary outcomes A/B
  • CSFS Verification: Oracle signatures validated onchain
  • Real Transactions: Actual Bitcoin network operations
  • Transaction Analysis: Detailed blockchain transaction parsing
  • Explorer Integration: Live transaction links and monitoring

πŸš€ Quick Start

Prerequisites

  • Rust 1.70+
  • Access to Mutinynet signet node
  • Bitcoin Core with RPC access

Installation

git clone https://github.com/AbdelStark/doko.git
cd doko
cargo build --release

Configuration

Create a .env file in the project root:

RPC_URL=127.0.0.1
RPC_PORT=38332
RPC_USER=user
RPC_PASSWORD=password
RPC_WALLET=vault_manager_wallet

Available Commands

# Vault demos
cargo run -- auto-demo --vault-type simple --scenario cold-recovery
cargo run -- auto-demo --vault-type hybrid --scenario csfs-delegation
cargo run -- auto-demo --vault-type nostr

# Interactive dashboards
cargo run -- dashboard --vault-type simple
cargo run -- dashboard --vault-type hybrid

# Prediction market
cargo run --bin demo_prediction_market -- --auto
cargo run --bin nostr_market create --question "Bitcoin above $100k?" --outcome-a "Yes" --outcome-b "No"

πŸ“Š Dashboard Interface

Doko TUI Dashboard Demo

Interactive TUI dashboard for vault monitoring and management

Dashboard Features

  • Real-time Monitoring: Live blockchain state tracking
  • Transaction History: Comprehensive transaction logs
  • Vault Management: Interactive vault operations
  • Balance Tracking: Multi-address balance monitoring
  • Network Status: Chain state and confirmation tracking

πŸ› οΈ Development

Project Structure

doko/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ vaults/          # Vault implementations
β”‚   β”œβ”€β”€ prediction_markets/ # Prediction market system
β”‚   β”œβ”€β”€ services/        # Bitcoin network services
β”‚   β”œβ”€β”€ tui/            # Terminal user interface
β”‚   └── config/         # Configuration management
β”œβ”€β”€ bin/                # Executable binaries
β”œβ”€β”€ app/                # Web interface (future)
└── resources/          # Static assets

Key Modules

  • Vaults: Simple, Hybrid, and Nostr vault implementations
  • Prediction Markets: Nostr-based prediction market system
  • Services: RPC client, explorer integration, transaction analysis
  • TUI: Interactive terminal dashboards
  • Config: Network configuration and environment management

Testing

# Run all tests
cargo test

# Run specific test suites
cargo test --test integration_tests
cargo test --lib prediction_markets

# Run with verbose output
cargo test -- --nocapture

πŸ“„ License

This project is licensed under the MIT License.

About

Bitcoin Vault proof of concept using CTV + CSFS

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors