Into_XCM_03: XCVM

Chinedu E. Nwadike
3 min readFeb 28, 2023

--

source: source: shorturl.at/rSTW7

For blockchains to work together and form the basis of Web3, they need a common language for communication. Polkadot attempts to set the standard with XCM, a powerful format for secure messaging across Polkadot-native parachains and with external networks via bridges.

This article will provide an overview of Polkadot’s Cross-Consensus Virtual Machine (XCVM) and how messages are executed (XCM).

Caution: XCM is a complex piece of technology and requires a good understanding of how blockchains work to make complete sense of it. This article assumes you understand what happens after you sign a blockchain transaction.

basics

XCM is a language that allows different consensus systems like parachain to interact with each other. It enables protocols to define a message and how it should be executed on a remote protocol.

A message between the polkadot relay chain and a parachain can be transmitted through vertical message passing (UMP and DMP). In contrast, messages between parachains can be sent through cross-consensus messaging passing protocol (XCMP and HRMP).

Because a message describes a step-by-step process and defines resources to be used in the execution of that process, it is considered a program.

Each step of this process is an instruction that can be understood and interpreted by the XCM virtual machine.

XCVM core

The XCM virtual machine is a register-based execution environment. These registers are dedicated storage that stores values that provide context for instructions. Some examples of these registers include:

  • Holding Register, which temporarily keeps on-chain assets during execution.
  • Programme Counter, which keeps track of which instruction is being executed.
  • Error, which stores the error of the latest instruction execution if there is any.
  • Error Handler, which contains any code which should be executed in case of an error

A complete list of XCVM registers can be found here.

XCVM has diverse instructions for different actions. Some of the commonly used instructions include:

  • TransferAsset
  • DepositAsset
  • WithdrawAsset
  • Transact

You can find a detailed description of how a corresponding TransferAsset instruction can be composed is described in my previous article here.

A full list of XCVM instruction sets can be found here.

XCVM operates by going through each instruction in a message, it fetches an instruction and dispatches a corresponding instruction set.

If the instructions in a message are exhausted, execution stops and another message is loaded and executed.

interpreting a message

For a message to be correctly interpreted, each instruction contained in the message must correspond to one of the XCVM instruction sets. By extension, an invalid message is a message that contains one or more instructions that do not correspond to any XCVM instruction set.

After a message is composed and sent, it is received by an XCVM hosted on the destination chain. Once a message is received, it is inserted into the message queue. This message queue includes all the messages that are yet to be executed by the virtual machine.

On execution of a message, all the instructions in a message must run successfully. This means each message instruction is matched to its corresponding XCVM instruction sets, and the triggered dispatch is successful.

If an instruction or its corresponding XCVM instruction set dispatch throws an error, the execution stops and all the effects of previous instructions are reverted. This prevents unpredictable behaviors due to partial message execution.

Once a message is fully executed, the Error Handler and other registers are cleared and the next message in the message queue is mounted on XCVM for execution.

Conclusion

Polkadot’s XCM is positioned to be a language for building innovative new cross-chain applications and services. XCVM gives applications to confidently interoperate with remote protocols in a manner that is guaranteed to be correct.

like this article?

Keep an eye out here to learn more about XCM.

kusama address: 16RTtFPL4RA6pJW7iYVnREgBteEepZFCcJtBrJq1SmvbCrq

--

--

Chinedu E. Nwadike

Software engineer with interest in distributed systems and blockchain interoperability.