Smart contracts on Bitcoin

Write smart contracts and build decentralized applications (dapps) on Bitcoin.


Bitcoin is widely regarded as the most secure blockchain due to its resilience against external interference. However, the protocol's data format is limited, preventing the extension of its security features to other applications.
Thanks to the Taproot-type transaction, it is now possible to embed any data into a Bitcoin Blockchain, which will be permanently stored on the Bitcoin network and inherit its features, such as availability, immutability, and determinism.
This embedding technique enables the development of new protocols. Bitcoin Virtual Machine is working towards implementing a Turing-Complete virtual machine running on top of the Bitcoin network, so that developers to create decentralized applications on Bitcoin.
Bitcoin Virtual Machines are low-cost and lightning-fast Bitcoin L2 blockchains that aim to make Bitcoin as generalized as possible — usable for far more than just a currency. It enables developers to create DAO, DEX, NFT, token, auction, lending, data storage, and many other use cases on Bitcoin.


At the heart of our system, BVM is a state machine similar to Ethereum-VM that utilizes the Bitcoin blockchain as a data layer to achieve transaction-level consensus. This approach allows BVM to function as a general-purpose state machine while taking advantage of the Bitcoin blockchain's security and data availability without requiring additional modules, such as network or consensus protocols.
There are 4 most important components needed to explain: the local mempool, Ethereum-like VM, TxWriter, and TxReader.

Bitcoin Virtual Machine

Our BVM state is an Ethereum-compatible virtual machine. The framework has been configured to support larger transaction sizes and higher block gas limits, enabling us to support more kinds of applications.

Local Mempool

As part of the system, each node maintains a collection of transactions that the user sends to the node in a local mempool. The mempool will help to verify the validation of the transaction before it is written to the Bitcoin network.
This mempool is local because it is not shared with other nodes. The transaction is only exposed publicly when it is written to a Bitcoin transaction (the process of TxWriter) and broadcast to the Bitcoin network.


TxWriter enables us to embed BVM transactions into Bitcoin transactions. To achieve this, we use a similar technique that Ordinals use to inscribe data into the Bitcoin network.
There is a major difference between Ordinals and Bitcoin Virtual Machine. Ordinals let people inscribe data like images and texts onto Bitcoin. Bitcoin Virtual Machine lets developers deploy programs, smart contracts, and decentralized applications.
Essentially, the BVM transaction data is embedded into a Bitcoin transaction via the witness data field. This embedding is done in a way that does not affect the verification process and has no impact on the transaction logic.
The witness data field is only exposed as an unlock script for the previous output. Pushing data to a Bitcoin transaction requires us to conduct a two-phase transaction process. The first phase is the commit transaction, which involves creating an unspent transaction output (UTXO) that indicates the witness/script hash for spending. In the second phase, the revealing transaction exposes the witness data/script containing the BVM transaction.


This module is responsible for filtering BVM transactions in every new Bitcoin block and ensuring that the state of the BVM is consistent across all BVM nodes in the network, even in the event of a reorg.
For each Bitcoin block, the BVM will first filter the BVM transaction, sort them by gas fees, and then import them to the VM as a BVM block. As Bitcoin has an immutable, deterministic order, every BVM node that runs an honest codebase will have the same state.
Bitcoin reorg is a process that occurs when two or more miners simultaneously add different blocks to the blockchain. This can cause a fork in the chain, where different parts of the network have different versions of the blockchain. TxReader is designed to handle Bitcoin reorgs by reverting the BVM state to the point of the forked branch and then re-importing the valid blocks into the reverted state.