Bithoven Developer Guide

Learn to build safe, expressive smart contracts on Bitcoin with readable, type-safe code.

Version 0.0.1 Beta Legacy / SegWit / Taproot

1. Introduction

Bithoven is a high-level, imperative programming language designed for Bitcoin smart contracts. It bridges the gap between complex contract logic and the low-level stack machine of the Bitcoin Virtual Machine (VM).

Unlike writing raw Bitcoin Scriptβ€”which is notoriously difficult and error-proneβ€”Bithoven allows you to write readable, auditable code with modern control flow (if/else), named variables, and built-in safety checks. It compiles down to highly optimized native Bitcoin Script.

Why Bithoven?

  • Imperative Syntax: Use familiar control flow instead of mental stack juggling.
  • Formal Safety: The compiler prevents "anyone-can-spend" bugs and signature reuse.
  • Zero-Cost Abstraction: Compiles to efficient opcodes with minimal overhead.

πŸ“Š Bithoven vs. Raw Bitcoin Script

❌ Bitcoin Script (Raw)
OP_IF
  <1000> OP_CSV OP_DROP
  <alice_pk> OP_CHECKSIG
OP_ELSE
  OP_HASH256
  <hash> OP_EQUALVERIFY
  <bob_pk> OP_CHECKSIG
OP_ENDIF

Stack-based, hard to read, error-prone

βœ… Bithoven (High-Level)
if condition {
  older 1000;
  return checksig(sig_alice, alice_pk);
} else {
  verify sha256(sha256(preimage)) == hash;
  return checksig(sig_bob, bob_pk);
}

Readable, type-safe, beginner-friendly

2. Getting Started

Installation

You can install the Bithoven compiler via the command line or package managers.

Terminal
# For Rust Users
cargo add bithoven

# For Node.js Users
npm install bithoven

# CLI Tool
cargo install bithoven

Online IDE

Try Bithoven instantly in your browser without installation:

Go to Bithoven Online IDE

3. Structure of a Contract

A Bithoven contract (file extension .bithoven) consists of three main parts:

  1. Pragmas: Compiler directives.
  2. Stack Definitions: The expected input variables (Witness data).
  3. Logic Block: The executable code.

Example: Single Signature

// 1. Pragmas
pragma bithoven version 0.0.1;
pragma bithoven target segwit;

// 2. Stack Input Definitions (The "Witness")
(sig_alice: signature)

// 3. Logic Block
{
    return checksig(sig_alice, "0245a6b3f8eeab8e88501a9a25391318dce9bf35e24c377ee82799543606bf5212");
}

4. Language Basics

Pragmas

Pragmas define the compiler version and the Bitcoin protocol target. The target controls opcode generation.

Types

Type Description Example
bool Boolean values true
number Integer values (32-bit signed) 1000
string Hex or ASCII string data "secret"
signature ECDSA or Schnorr signatures sig_alice
pubkey Valid public key point "0245..."

Stack Input Definitions

Bithoven allows you to define multiple valid "spending paths" at the top of your file. The compiler verifies that every path is secure.

(condition: bool, sig_alice: signature) // Path A
(condition: bool, preimage: string, sig_bob: signature) // Path B

5. Control Flow

Conditionals

Use standard if/else logic.

if condition {
    // Branch A
    return true;
} else {
    // Branch B
    return false;
}

Assertions

Halts execution if false.

// Fails transaction if false
verify sha256(preimage) == "53de...4e45f";

6. Bitcoin Primitives

Time Locks

Keywords enforce 32-bit limits automatically.

Cryptography

Hashing: sha256(data), ripemd160(data)

Signature Checks: Supports single and multisig via checksig.

// Single Signature
checksig(sig_var, "pubkey_hex")

// 2-of-2 Multisig
checksig [2,
    (sig_alice, "pk_alice_hex"),
    (sig_bob, "pk_bob_hex")
]

7. Security Features

Bithoven is "Correct-by-Construction." The static analyzer runs during compilation.

Liveness Safety

Ensures every variable (especially signatures) is consumed exactly once. Prevents signature reuse and resource exhaustion.

Semantic Security

Analyzes execution paths to ensure safe termination. Prevents Anyone-Can-Spend bugs.

Type Safety

Strictly validates types. Prevents consensus failures like arithmetic on strings or invalid public key points.

8. Examples Gallery

Explore real-world Bitcoin smart contract patterns implemented in Bithoven. Each example demonstrates key concepts and can be tried live in the Web IDE.

πŸŽ“ Suggested Learning Path

1 Beginner β†’ Basic signatures & locks
2 Intermediate β†’ Combine concepts
3 Advanced β†’ Multi-party patterns
4 Expert β†’ Complex systems

BEGINNER Getting Started

✍️ Single Signature (P2PKH) Try in IDE β†’

The most basic Bitcoin transaction - requires only a signature to spend.

πŸ’‘ Learns: Basic syntax, checksig operation

Use case: Simple wallet, standard payments

πŸ”’ Hash Lock Try in IDE β†’

Spend coins by revealing a secret that matches a SHA256 hash.

πŸ’‘ Learns: Hash verification, secret reveals

Use case: Atomic swaps, payment channels

⏰ Time Lock (CLTV) Try in IDE β†’

Coins locked until a specific block height using absolute timelocks.

πŸ’‘ Learns: Absolute timelocks (after), CLTV

Use case: Vesting schedules, delayed payments

INTERMEDIATE Combining Concepts

⚑ HTLC (Hash Time-Locked Contract) Try in IDE β†’

Lightning Network standard combining hash locks and timelocks with if/else branches.

πŸ’‘ Learns: Conditional paths, combining hash+time locks, relative timelocks (older)

Use case: Lightning Network, payment channels

πŸ”„ Atomic Swap Try in IDE β†’

Trustless cross-chain trading with hash locks and timeout refunds.

πŸ’‘ Learns: Cross-chain patterns, double SHA256, refund mechanisms

Use case: Decentralized exchanges, cross-chain swaps

πŸ‘₯ Multisig (2-of-2) Try in IDE β†’

Taproot multi-signature authorization requiring both parties to sign.

πŸ’‘ Learns: Multisig syntax, Taproot vs SegWit differences

Use case: Joint accounts, shared custody

ADVANCED Multi-Party Patterns

🀝 Escrow (2-of-3 Multisig) Try in IDE β†’

Marketplace contract with buyer, seller, and arbitrator. Multiple spending paths for different scenarios.

πŸ’‘ Learns: 3-party coordination, nested conditions, refund timeouts

Use case: P2P marketplaces, freelance platforms, real estate

🏦 Vault (Time-Delayed Withdrawal) Try in IDE β†’

Security wallet with delayed withdrawals and immediate cold storage recovery.

πŸ’‘ Learns: Hot/cold key hierarchy, security delays, emergency recovery

Use case: Corporate treasuries, high-value custody, exchange cold storage

πŸ—³οΈ Multisig Voting (2-of-3 Threshold) Try in IDE β†’

Democratic governance requiring 2-of-3 approval with security timelock, or 3-of-3 emergency override.

πŸ’‘ Learns: Threshold signatures, governance delays, emergency overrides

Use case: DAO treasuries, board approvals, multi-stakeholder governance

πŸ‘¨β€πŸ‘©β€πŸ‘§ Inheritance (Tiered Access) Try in IDE β†’

Three-tier access: owner (anytime), heir (after 1000 blocks + secret), lawyers (after 10,000 blocks).

πŸ’‘ Learns: Cascading timelocks, secret-based access, fallback multisig

Use case: Estate planning, inheritance vaults, tiered recovery

EXPERT Complex Systems

🎲 Prediction Market (Oracle Integration) Try in IDE β†’

Decentralized betting with cryptographic oracle commitment, multi-outcome resolution, and refund mechanism.

πŸ’‘ Learns: Oracle commitment schemes, multi-outcome branching, complex refund logic

Use case: Sports betting, price predictions, decentralized insurance

πŸ“š Quick Reference

By Difficulty:

  • Beginner singlesig, hashlock, timelock
  • Intermediate htlc, atomic_swap, multisig
  • Advanced escrow, vault, voting, inheritance
  • Expert prediction_market

By Use Case:

  • Payments: Lightning (htlc), atomic_swap
  • Security: vault, inheritance
  • Governance: multisig_voting, escrow
  • DeFi: prediction_market, atomic_swap

9. Frequently Asked Questions

Q: What is Bithoven?

A: Bithoven is a high-level, type-safe programming language for writing Bitcoin smart contracts. It provides imperative syntax (if/else, return) instead of low-level stack operations, and compiles to native Bitcoin Script.

Q: Do I need to know Bitcoin Script to use Bithoven?

A: No! That's the point. Bithoven abstracts away the complexity of Bitcoin Script's stack-based operations. You write readable code with familiar programming constructs, and the compiler handles the low-level details.

Q: How does Bithoven compare to Miniscript?

A: Miniscript is a policy language focused on composability and correctness. Bithoven is an imperative programming language that offers more expressive control flow (nested if/else, early returns) while maintaining formal safety guarantees. Both compile to Bitcoin Script, but Bithoven targets developers who want imperative syntax.

Q: What's the difference between older and after?

A: older N is a relative timelock (OP_CHECKSEQUENCEVERIFY) - locks coins for N blocks after the UTXO is created. after N is an absolute timelock (OP_CHECKLOCKTIMEVERIFY) - locks coins until block height N. Use older for "wait X blocks from now", and after for "unlock at specific time".

Q: Can Bithoven create multiple outputs or check UTXO values?

A: No. Bitcoin Script (and therefore Bithoven) has amount blindness - scripts cannot read UTXO values or control output amounts. These require pre-signed transactions or off-chain coordination. Bithoven focuses on spending conditions, not transaction construction.

Q: Is Bithoven production-ready?

A: Bithoven v0.0.1 is in beta. The compiler has formal verification and passes extensive tests, but has not been independently audited. Use for research, prototyping, and learning. For production deployments, please conduct thorough testing and security review.

Q: How do I test my Bithoven contracts?

A: Use the Web IDE for quick experimentation. For thorough testing, compile your contract and use Bitcoin testing frameworks like bitcoin-core regtest or btcd.

Q: Where can I get help?

A: Check the GitHub repository for documentation, or open an issue if you encounter problems. For research questions, refer to the Bithoven paper.

10. Glossary

Bitcoin Script
A stack-based programming language used to define spending conditions for Bitcoin transactions.
UTXO
Unspent Transaction Output - a chunk of bitcoin that can be spent by satisfying its script conditions.
Witness
The data provided to satisfy a script's spending conditions (signatures, preimages, etc.).
SegWit
Segregated Witness - a Bitcoin upgrade separating witness data from transaction data for efficiency.
Taproot
Bitcoin's 2021 upgrade enabling more efficient and private smart contracts via Schnorr signatures and MAST.
HTLC
Hash Time-Locked Contract - combines hash locks and timelocks for conditional payments (used in Lightning).
Multisig
Multi-signature - requires multiple signatures to spend (e.g., 2-of-3 means any 2 of 3 parties can spend).
CLTV / CSV
CheckLockTimeVerify (absolute) / CheckSequenceVerify (relative) - opcodes for timelocks.
Atomic Swap
Trustless cross-chain exchange using matching hash locks on different blockchains.
Opcode
Operation code - a single instruction in Bitcoin Script (e.g., OP_CHECKSIG, OP_IF).
Preimage
The secret data that, when hashed, produces a specific hash digest used in hash locks.
Spending Path
A distinct execution branch in a contract with its own witness requirements.