AVM: Bitcoin Smart Contracts Based on Simulated Virtual Machines

BitcoinSquare
2024-06-07 09:55:44
Collection
Introduction to what AVM is, how it works, and its future development.

Just this week, ++@atomicalsxyz++ released the latest AVM virtual machine white paper. I believe everyone still remembers last year's $ATOM and the $quark ARC-20 tokens that were issued around the New Year. So what exactly does the Atomicals protocol's AVM white paper discuss, and what impact will it have on the future Bitcoin ecosystem? Let's analyze the protocol and the content of the white paper below.

1. Background

With the development of the Bitcoin ecosystem, the introduction of technologies such as Segwit, Taproot, Schnorr, MAST, and Taproot Scripts has spurred the emergence of new applications. This has led to various methods for issuing Bitcoin tokens and has continuously promoted the development of the Bitcoin ecosystem.

The birth of the Ordinals protocol is closely related to the concept of satoshi (sats) on the Bitcoin network. This protocol introduces the concepts of Ordinals and Inscriptions. Ordinals assign a unique number to each sat based on its mining order, and regardless of how the sat is transferred between different wallets, its ordinal identifier remains unchanged. Inscriptions are achieved by engraving information onto the sats. Combined with SegWit and Taproot, the Ordinals protocol allows for the engraving of a file smaller than 4 MB onto each sat on the Bitcoin blockchain, known as an inscription. As the Bitcoin ecosystem has developed, Ordinals founder Casey suggested using Runes as an alternative to BRC-20. Compared to BRC-20, Runes reduce the server consensus layer, making it simpler, while not relying on off-chain data and not requiring a native token, making it very suitable for Bitcoin's native UTXO model.

The introduction of the Atomicals protocol was also a matter of coincidence. Initially, founder Arthur wanted to develop a DID project based on the Ordinals protocol when it was first released, but during the process, he discovered some limitations. Subsequently, in May 2023, he tweeted about the protocol's ideas, and it officially launched in September of last year. The concept of ARC-20 in Atomicals is not the inscription protocol that many people understand; it is more like a colored coin. It uses Bitcoin's smallest unit, sat, as the basic "atom," with the unique feature that each token unit is supported by at least one sat unit and operates according to the same rules for sending and receiving Bitcoin based on unspent transaction outputs (UTXO) architecture.

When tracking historical transaction records and calculating the current ARC-20 asset balance, users only need to check the Bitcoin UTXO associated with the ARC-20 token, without needing to retrieve additional data from off-chain storage modules. This is a major difference between ARC-20 and the BRC-20 protocol, as the BRC-20 protocol typically relies on off-chain indexers and off-chain storage layers. The ARC-20 protocol significantly reduces the cost of indexing servers, increases decentralization, and its transfer security relies on the BTC network, avoiding redundant transactions while maintaining the same atomicity as BTC, making it suitable for developing various native applications. The Atomicals protocol aims not only to issue assets but also to provide richer use cases for assets to enhance their liquidity and expand functionality.

2. What is AVM

Bitcoin was originally designed as a peer-to-peer electronic cash system, equipped with certain Script data storage capabilities and basic OP Codes. To date, all overlay protocols on Bitcoin are based on fixed or predefined state machines. All overlay protocols essentially share two types of state machines: one for signaling to create digital assets and another for managing the transfer of these digital assets. The rules of the state machine are essentially immutable and hard-coded into their respective overlay protocol indexers—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 handle limited management of the single BTC asset. To introduce assets like BRC20, ARC20, and Runes on the Bitcoin network, a more complex dynamic "state machine" model is needed to record the storage, transactions, and state changes of these assets. One approach is to use external protocols and Layer 2 solutions, such as Nervos Network, RGB, and the Lightning Network mentioned in our previous articles, which build a "state machine" model off-chain; another approach is to directly extend the Script functionality by adding new opcodes or storage space, such as the Covenant and OP_CAT BIP proposals. However, the problem is that the first approach is difficult to reach consensus in a short time, while the second approach carries uncertainty.

The AVM virtual machine provides a solution that lies between the two, directly building a virtual machine execution environment on the Bitcoin mainnet to facilitate the creation and transfer of complex assets through special processing methods, allowing application developers to fully customize and define any rules for their digital assets. The basic idea is to allow developers to place smart contract code in the data segment of transactions so that all relevant parties can execute it. By storing the code on the blockchain, different parties can easily synchronize states by executing logic in the same way.

3. How It Works

We all know that a smart contract programming language should possess at least the following key attributes: predictable runtime, Turing completeness, and efficient execution in resource-constrained systems. From 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 for various method calls and state transitions. All relevant parties execute the same logic and achieve the same state transitions, forming a spontaneous consensus.

By simulating the Bitcoin virtual machine and its script interpreter, various smart contracts covering digital assets can be created and executed. The Bitcoin blockchain serves as a timestamp and data provider, storing smart contract programs on-chain, but the execution of these programs is carried out by overlay protocol indexers in a sandbox runtime. The overlay protocol indexer nodes are operated collaboratively by application developers, service providers, and users, forming an emerging consensus:

  1. Bitcoin Script Simulation: The Bitcoin instruction set achieves Turing completeness through a dual-stack PDA;

  2. Sandbox Runtime Environment: The entire simulator operates in a controlled isolated environment, ensuring that executions within the sandbox do not interfere with those outside;

  3. State Hash: This allows participants to verify whether their indexer states are correctly synchronized, preventing potential attacks from state inconsistencies.

In simple terms, AVM directly utilizes the limited storage space and OP Codes processing framework of current BTC by introducing a special encoding and decoding method in each BTC mainnet transaction, which is a sandbox environment. This sandbox is a streamlined version of the Bitcoin script interpreter, with some significant differences, such as directly accepting execution locking scripts (scriptPubKey) and unlocking scripts (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 records, etc., thereby enabling complex smart contract processing, state synchronization, and verification.

4. Future Development

So what potential developments does AVM have in the future? It provides a high-level execution environment capable of handling smart contracts and dApps, equipped with a custom instruction set to enhance performance while reducing gas fees, optimizing state transition functions to increase parallel processing capabilities, thereby improving throughput and scalability. At the same time, AVM achieves interoperability and cross-chain communication. In simple terms, AVM allows the Atomicals protocol to perform various tasks, not just the previously simple token issuance mechanism. Only after meeting the needs for asset issuance and management can the Bitcoin ecosystem truly develop, leading to larger-scale applications and system architecture implementations.

Despite the many limitations of AVM, such as only being able to operate ARC20 assets and the availability of a layer of smart contracts under the mainnet's block speed and fee rate still being unknown, and although the Bitcoin script language is designed for resource-constrained environments, complex smart contracts may still consume a large amount of computational resources, raising concerns about execution efficiency. However, its emergence is still exciting, and we look forward to further breakthroughs in technological innovation.

Who Are We?

Bitcoin Square is a Bitcoin ecosystem 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.

ChainCatcher reminds readers to view blockchain rationally, enhance risk awareness, and be cautious of various virtual token issuances and speculations. All content on this site is solely market information or related party opinions, and does not constitute any form of investment advice. If you find sensitive information in the content, please click "Report", and we will handle it promptly.
ChainCatcher Building the Web3 world with innovators