AVM: Smart Contracts on Bitcoin by Simulating The Bitcoin Virtual Machine

Bitcoin Square
5 min readJun 4, 2024

--

Just this week, @atomicalsxyz released the latest AVM virtual machine whitepaper. But what exactly does the AVM whitepaper from the Atomicals protocol discuss, and what impact will it have on the future of the Bitcoin ecosystem? Let’s analyze the protocol and the whitepaper in detail below.

Background

With the evolution of the Bitcoin ecosystem, the introduction of technologies such as Segwit, Taproot, Schnorr, MAST, and Taproot Scripts has spurred the emergence of new applications. Various Bitcoin token issuance methods have been developed based on these developments, further advancing the Bitcoin ecosystem.

The creation of the Atomicals protocol was serendipitous. Initially, the founder, Arthur wanted to develop a DID project based on the Ordinals protocol right after its launch. However, he encountered some limitations. In May 2023, he tweeted about the idea of the protocol, and it officially launched in September of the same year. The ARC-20 concept within Atomicals is often misunderstood as another inscription protocol, but it resembles a colored coin approach. It uses Bitcoin’s smallest unit, the sats, as its basic “atom.” Each token unit is backed by at least one satoshi and operates under the same rules as sending and receiving bitcoins using the UTXO architecture.

When tracking transaction history and calculating current ARC-20 asset balances, inspecting the Bitcoin UTXOs associated with ARC-20 tokens is only necessary without additional data retrieval from off-chain storage modules. This distinguishes ARC-20 from the BRC-20 protocol, which typically relies on off-chain indexers and storage layers. The ARC-20 protocol significantly reduces the cost of indexing servers, enhances decentralization, and ensures transfer security through the BTC network without generating redundant transactions. It maintains the same atomicity as BTC, making it suitable for developing native applications. The Atomicals protocol aims to issue assets and enrich their use cases to enhance liquidity and expand functionality.

What is AVM?

Bitcoin was originally designed as a peer-to-peer electronic cash system with basic Script scripting capabilities and OP Codes. To date, all overlay protocols on Bitcoin are based on fixed or predefined state machines. Essentially, these overlay protocols share two types of state machines: one for signaling to create digital assets and another for managing the transfer of these assets. The rules of these state machines are inherently immutable and are hardcoded within their respective overlay protocol indexers — meaning that application developers cannot customize the behavior of digital assets.

However, due to the limitations of the UTXO model and predefined state transition rules, this stateless model can only manage a limited administration of Bitcoin’s single asset. To introduce assets like BRC20, ARC20, Runes, etc., on the Bitcoin network, a more complex dynamic “state machine” model is required to record these assets’ storage, transactions, and state changes. One approach is to use external protocols and Layer 2 solutions, such as the Nervos Network, RGB, and Lightning Network mentioned in previous articles, which build “state machines” off-chain. Another approach is directly expanding the Script functionality by adding new opcodes or storage spaces, such as Covenant and OP_CAT BIP proposals. However, the first approach makes it difficult to reach a consensus in the short term, while the second approach has uncertainties.

The AVM provides a solution that lies between these two approaches by building a virtual machine execution environment directly on the Bitcoin mainnet, enabling the creation and transfer of complex assets in a specialized manner and allowing application developers to customize and define any rules for their digital assets fully.

Principles

We all know that a smart contract programming language should have at least the following key attributes: predictable runtime, Turing completeness, and the ability to execute efficiently in resource-constrained systems. Given these requirements, Bitcoin Script is very suitable as an instruction set for defining the rules for creating and transferring digital assets. Smart contract program code is stored in Bitcoin transactions, and overlay protocol indexers execute this code to perform various method calls and state transitions. All involved parties execute the same logic and reach the same state transitions, forming a spontaneous consensus.

By simulating the Bitcoin virtual machine and its script interpreter, various overlay digital asset smart contracts are created and executed. The Bitcoin blockchain acts as a timestamp and data provider, storing smart contract programs on-chain, but overlay protocol indexers execute these programs within a sandbox runtime. Overlay protocol indexer nodes are operated by application developers, service providers, and users, forming an emergent consensus:

  • Bitcoin Script Simulation: The Bitcoin instruction set achieves Turing completeness through a double-stack PDA implementation.
  • Sandbox Runtime Environment: The entire simulation runs in a controlled, isolated environment, ensuring that execution inside the sandbox does not interfere with execution outside it.
  • State Hash: Allows participants to verify whether their indexer’s state is correctly synchronized, preventing potential attacks due to state inconsistencies.

In simple terms, AVM directly leverages the limited storage space and OP Codes processing framework of the current BTC network. By introducing a special encoding and decoding method in each BTC mainnet transaction, namely the sandbox environment, this sandbox is a streamlined version of the Bitcoin script interpreter. It has some significant differences, such as directly accepting execution scriptPubKey and scriptSig, as well as various other data like token states and protected memory snapshots. This environment can independently complete a full set of asset storage, transaction recording, and more, thereby enabling complex smart contract processing as well as state synchronization and validation.

Future Development

What are the potential developments for AVM in the future? AVM offers an advanced execution environment capable of handling smart contracts and dApps, equipped with a custom instruction set to enhance performance. It also aims to lower gas fees and optimize state transition functions to increase parallel processing capabilities, thereby improving throughput and scalability. Additionally, AVM achieves interoperability and cross-chain communication. In simple terms, AVM enables the Atomicals protocol to execute various tasks, not just the simple token issuance mechanisms seen before. Once it meets the needs for asset issuance and management, the Bitcoin ecosystem can truly develop, leading to larger-scale applications and system architectures.

Despite AVM’s limitations, such as being able to operate only on ARC20 assets and the unknown usability of layer-one smart contracts given the mainnet block speeds and fees, it is still exciting. Moreover, although Bitcoin’s scripting language is designed for resource-constrained environments, complex smart contracts might still consume significant computational resources, raising concerns about execution efficiency. Nonetheless, its emergence is exciting, and we look forward to further technological breakthroughs.

About us?

Bitcoin Square is a Bitcoin ecological and alpha community established in May 2023. We are committed to providing the latest market dynamics, professional market analysis, and a community environment with an investment research spirit.

--

--

Bitcoin Square

Growing the BTC community | BTC Talks | BTC News | Crypto Alpha Group