Bithoven: A type-safe Bitcoin Smart Contract compiler (written in Rust + WASM)
⚓ Rust 📅 2025-12-16 👤 surdeus 👁️ 1Hi, Rust Users! I'm a phd student researching in the area of cybersecurity, mostly blockchain, and love to build anything in Rust ![]()
Bitcoin doesn't support high-level smart contracts (unlike Ethereum), but only an assembly-like "Bitcoin Script," which is really challenging to write (just like the 1970s assembly era). As wrong code directly causes security vulnerabilities like unspendable or anyone-can-spend coins, I've researched how to build high-level Bitcoin smart contracts with safety using Rust, and have finally released Bithoven v0.0.1. I would be grateful for any feedback, code reviews, or contributions from anyone who is interested in the area of security, blockchain, and programming languages (and most importantly, Rust).
Key features are following:
- Written in Rust: Leverages Rust's LALR library(LALRPOP) and pattern matching for robust AST parsing and code generation.
- WASM Support: The compiler compiles to WebAssembly, allowing for a client-side IDE without a backend.
- Minimal-Cost Abstraction: Imperative logic (
if,else,return) is flattened into optimized raw opcodes (OP_IF,OP_ELSE). - Type Safety: Strong static typing for
bool,signature, andstringprevents the common runtime crashes found in raw script.
The Syntax
The language syntax is inspired by Rust, C and Solidity(Ethereum Smart Contract). Here is an example of an HTLC (Hashed Time-Locked Contract) that compiles down to Bitcoin script:
pragma bithoven version 0.0.1;
pragma bithoven target segwit;
(condition: bool, sig_alice: signature)
(condition: bool, preimage: string, sig_bob: signature)
{
if condition {
// Enforce relative locktime (sequence)
older 1000;
return checksig (sig_alice, alice_pk);
} else {
// Hashlock verification
verify sha256 sha256 preimage == hash;
return checksig (sig_bob, bob_pk);
}
}
Try it out:
I’ve put together a Web IDE so you can experiment with the syntax and see the compiled output instantlly. No installation required.
- Web IDE: Bithoven
- Documentation: Bithoven Developer Guide
- GitHub: GitHub - ChrisCho-H/bithoven: Bithoven is a smart contract language for composing powerful and secure instruments on Bitcoin.
Current Status: Bithoven is free, open-source software. Please note that the project (and its accompanying academic paper) is currently under review and in the experimental stage.
Thanks for checking it out!
1 post - 1 participant
🏷️ Rust_feed