Skip to content
Crypto.world

Research

Bithoven: Formal Safety for Expressive Bitcoin Smart Contracts

Writing raw Bitcoin Script is error-prone, and the authors point to empirical analyses of the Bitcoin blockchain that uncovered thousands of defective scripts with vulnerabilities such as…

Bithoven: Formal Safety for Expressive Bitcoin Smart Contracts
arXiv
2601.01436
Published
2026-01-04
Authors
Hyunhum Cho, Ik Rae Jeong

AI summary

Overview

Research area: Bitcoin smart contract languages, formal methods, and compiler-level security (Cryptography and Security, arXiv:2601.01436v1, cs.CR).

Technical level: Advanced. The paper presents full formal syntax, small-step operational semantics, and a complete typing-rule derivation system, alongside a compiler implementation.

Scope: The paper specifies Bithoven, a high-level imperative language for writing Bitcoin Script contracts, together with a multi-stage static analyzer that is claimed to eliminate defined classes of script defects before deployment.

What This Paper Is About

Writing raw Bitcoin Script is error-prone, and the authors point to empirical analyses of the Bitcoin blockchain that uncovered thousands of defective scripts with vulnerabilities such as "unbound-txid" (anyone-can-spend) and "useless-sig" (mangled logic), leading to demonstrable fund loss. Existing abstractions such as Miniscript improve analyzability but are described as a highly-analyzable assembly language and compiler target rather than a developer-centric imperative source language, and its grammar does not track stateful resource consumption, leaving it exposed to liveness errors. Bithoven's goal is to give developers an intuitive, expressive, type-safe language that compiles to native Bitcoin Script while statically guaranteeing the absence of defined defect classes.

Key Contributions

  1. A formally specified, type-safe, high-level imperative language for native Bitcoin Script. The paper gives the complete abstract syntax, small-step operational semantics, and a type system (Section III and V), covering pragmas (pragma version, pragma target for legacy, segwit, or taproot), typed stack declarations, if/else, verify, older (relative timelock / CSV), after (absolute timelock / CLTV), return, and a unified checksig construct that accepts either a single signature/public-key pair or an m-of-n multisig structure.

  2. A multi-stage static analysis pipeline. The compiler combines a type checker, a liveness and scope analyzer, a recursive security checker, and a semantic control-flow analyzer. The paper claims this detects not only type-system and consensus-level defects but also complex liveness errors such as signature reuse, which it states Miniscript does not prevent (Section VI-A).

  3. A fault model and a claim of compile-time prevention across it. The paper defines a threat and fault model for a benign but fallible developer, distinguishing attacker-spendable defects from never-spendable defects, and extends the cited taxonomy from prior work [7] with type system, control flow, stack discipline, and consensus rule violations, summarized in a comparison table (Table II).

  4. An open-source Rust implementation with a Web IDE, plus a comparison with Miniscript. The compiler uses the LALRPOP parser generator and the rust-bitcoin library, and the paper presents a comparative analysis arguing superior expressiveness for complex logic while maintaining structural isomorphism with optimized policy languages and low on-chain overhead (Section VI-E).

Main Findings

  • Compilation pipeline gating: Source (.bithoven) is parsed by LALRPOP into an AST, which passes through type checking, liveness analysis, security checking, and control-flow analysis; only a fully verified AST is passed to the opcode generator (Fig. 3).

  • Types added where Bitcoin Script has none: Bithoven defines the types num, bool, string, sig, and pubkey. The sig type is symbolic and used only in stack declarations, which the paper says is what lets the semantic analyzer enforce higher-level invariants such as blocking unbound-txid spending paths.

  • Consensus-constant enforcement: The typing rule for older and after requires the literal n to satisfy 0 ≤ n < 2^32, blocking malformed locktime constants at compile time.

  • Defect classes claimed eliminated: The fault model names unbound-txid, uncertain-sig, useless-sig (e.g., OP_CHECKSIG OP_NOT), never-true, consensus rule violations, type errors, and liveness errors such as reuse of a consumed variable. The paper claims compile-time prevention of all classes in this model.

  • Stack discipline by construction: Only the return statement produces the script's final output; other statements such as verify or older are designed not to leave intermediate values on the stack, which the authors say removes a class of stack manipulation errors.

  • Reverse-order stack declarations: Stack declarations are written to resemble a function signature, and the compiler maps them onto Bitcoin's LIFO stack.

  • Efficiency claim is qualitative in the available text: The abstract states that Bithoven compiles to Bitcoin Script with efficiency comparable to hand-optimized code and that this is achieved within the byte-size constraints of the Bitcoin blockchain. Specific byte sizes, fee savings, benchmark names, and dataset sizes are not reported in the paper content available, so no quantitative comparison figures can be given here.

  • No consensus change required: Unlike Simplicity (which aims to replace the VM) and BitML-style formalisms (which the paper describes as often requiring complex predicates or consensus changes), Bithoven targets currently deployed Script and models checksig and locktime outcomes as non-deterministic in its semantics because verification depends on transaction context.

Methodology in Plain English

The authors start by defining what can go wrong: they assume an honest but fallible developer, and an adversary who can see all transactions and craft arbitrary input scripts but cannot break ECDSA or SHA256. The only opening is a faulty output script. Faults are split into scripts that let an attacker spend (semantic security flaws, misused cryptographic checks) and scripts that nobody can spend (bad constants, type mismatches, impossible control flow).

They then design a language with an explicit, typed input interface. Because the language knows the type of every variable at the start, the compiler can check every operation before generating code. Arithmetic is restricted to numbers, logical operators to booleans, comparisons to numbers, strings, or booleans, and checksig must receive a well-formed signature/public-key pair, with public keys validated on the secp256k1 curve.

Beyond simple type checking, the compiler walks the program multiple times. One pass tracks which resources, such as signatures, have been consumed so none is used twice. Another scans locally for known anti-patterns. A final pass builds a control-flow graph and checks global properties, such as whether every path is protected by a signature requirement and whether every branch terminates with return. Only code that survives all of this is turned into opcodes.

For evaluation, the authors implement the compiler in Rust with LALRPOP and rust-bitcoin, publish it open source with a Web IDE, and compare against Miniscript. Note that the detailed evaluation sections in the supplied text are truncated after the implementation description, so the specific experimental results, measurements, and case studies described in Sections VI-B through VI-E are not reported in the content available.

Why This Matters

Impact on research. The paper argues that safety and developer usability need not be traded off in the UTXO model: an imperative high-level language can retain Script's security model without requiring Turing-completeness or a consensus change. It also pushes formal-methods work from post-hoc verification toward correct-by-construction compilation, and it extends static analysis beyond type and consensus checks into resource liveness, a gap the authors identify in Miniscript.

Real-world applications (drawn from the contract types the paper names as its focus):

  • Vaults and other custody contracts that must not admit an anyone-can-spend path.
  • Covenants and other constrained-spending arrangements.
  • Multisig schemes, including m-of-n checks handled by a single checksig construct.
  • Hashed TimeLock Contracts, which combine sha256/ripemd160 preimage checks with older and after timelocks.

Industry relevance. Miniscript is integrated into Bitcoin Core and standardized as BIP 379, so there is an established market for analyzable Script tooling. Bithoven positions itself one level above that as a source language, targeting the same deployment environments via pragma target for legacy (P2SH), Segwit (P2WSH), and Taproot (P2TR). The paper also cites community warnings that raw Script complexity leads to demonstrable fund loss, and notes recent proposals such as BitVM2 and Taproot Covenants as evidence that safe high-level design is timely.

Future Directions

  • Quantitative evaluation against Miniscript. The paper claims comparable efficiency to hand-optimized code and low on-chain overhead, but the concrete byte-size, cost, or benchmark results are not visible in the available text; a full accounting of these measurements is the natural next step.

  • Extension to newer protocol features. The pragma target mechanism is presented as an adaptability hook; extending it as Bitcoin consensus evolves (the paper cites the Taproot upgrade as an example of why theory-heavy formalisms age poorly) remains open.

  • Beyond the stated fault model. The model explicitly excludes network-layer and consensus-level attacks such as 51% control, double-spending, and transaction censorship; whether similar a priori guarantees can be extended to cross-transaction protocols is unaddressed.

  • Formal connection to the semantics. The operational semantics treat checksig and locktime statements as non-deterministic because verification depends on transaction context; relating the static analysis guarantees to a fully contextual, cryptographic model is left as future work.

Target Audience

Developers building Bitcoin contracts who want an expressive, readable alternative to hand-written Script; compiler and programming-languages researchers working on formal semantics, type systems, and static analysis for UTXO-based chains; Bitcoin wallet and custody engineers evaluating Miniscript-adjacent tooling; and security researchers studying the documented defect classes in deployed Bitcoin Script. Readers need comfort with typing judgments and operational semantics to follow Sections IV and V, though Sections I through III and VI are accessible to experienced blockchain engineers.

Authors’ abstract

The rigorous security model of Bitcoin's UTXO architecture often comes at the cost of developer usability, forcing a reliance on manual stack manipulation that leads to critical financial vulnerabilities like signature malleability, unspendable states and unconstrained execution paths. Industry standards such as Miniscript provide necessary abstractions for policy verification but do not model the full imperative logic required for complex contracts, leaving gaps in state…

The full abstract on arXiv
Read the original paper