We have now completed our work to integrate Move to Substrate. Using this pallet, builders can now integrate the Move VM, thereby allowing Substrate blockchains to execute Move smart contracts. Anyone can now create a Move parachain on Polkadot.

Overview

Since our last update in December, we have diligently worked on the Move Substrate integration. Equilibrium has now finished milestone three and delivered the Move pallet to be used in Substrate. To reach our goals, we had to:

  • adapt the existing Move virtual machine (MoveVM) that can store Move modules and bundles (a collection of modules) and execute Move scripts as smart contracts in Substrate runtime,
  • design a brand-new Substrate pallet in which the MoveVM is integrated and operates in single and multiple signer scenarios,
  • and establish a calibrated and balanced gas cost system for the MoveVM and create a logical connection to Substrate weights so that they can be converted into fees in the blockchain.

Project repositories

MoveVM Adaptation

Our work included forking the original Diem-based MoveVM and doing adaptation work to achieve full compatibility within Substrate runtime. The work included the following:

  • Providing a simple MoveVM backend abstract interface with full no-std support encapsulating all MoveVM handling operations, managing storage and balance handling.

  • Direct mapping between 32-byte address space in the MoveVM storage and addresses belonging to Substrate accounts.

  • Setting up a dedicated

    smove

    compiler and package tool capable of supporting directly SS58 accounts capable of preparing Move smart contracts for the MoveVM inside the runtime.

Pallet Move Design

As mentioned above, the pallet shall provide the ability to publish Move modules and bundles, and the possibility to call those functionalities when executing Move scripts. Therefore, we defined three important extrinsic calls (pseudo code):

fn execute(origin, transaction_bc, gas_limit, cheque_limit)
fn publish_module(origin, bytecode, gas_limit)
fn publish_module_bundle(origin, bundle, gas_limit)

The signed origins will be turned into the Move datatype signer (authorised Move account access), and the following parameters in different namings will always be the compiled and serialised Move bytecode.

The “execute” extrinsic is designed to be used in multiple signer scenarios (situations in which a smart contract needs to be signed by multiple participants). Parachain developers can configure a maximum lifetime and a maximum number of signers for those multiple signer script execution requests via the pallet’s configuration.

We will discuss the gas cost background a little more in detail later, but for now, let’s mention that you can limit those costs for executing or publishing Move bytecode.

Because the pallet enables Move smart contract developers to transfer tokens directly on the blockchain (internally using the Substrate trait Currency), the user can also specify a ‘cheque limit’ to specify the maximum amount of tokens used during the execution.

For parachain maintainers or, more in detail, the sudo user, one more extrinsic is available to update the two Move standard libraries, which technically are bundled but “owned” by sudo:

fn update_stdlib_bundle(origin, stdlib)

Gas Costs

Operations within the MoveVM can use variable CPU processing time and memory access, and gas fees address that issue. Every Move bytecode instruction and native function call has a fine-tuned defined gas cost. The MoveVM calculates the gas costs for each Move script execution, which are converted to the Substrate weights, which can then be turned into fees in the blockchain. The relation between MoveVM gas and Substrate weight is linear - the more gas the MoveVM consumes, the higher the Substrate fees will be for the end user.

By creating parameterised Substrate benchmark functions driven by gas costs and Move example code, we could generate an almost perfectly linear relationship between gas costs and Substrate weights. The Move example code used increased linearly between iterations of the running benchmarks. In case of later gas cost adoptions, only the Substrate-Move internal gas cost table for bytecode instructions needs to be tuned.

To avoid unnecessary gas costs, users can estimate the needed amount of gas for publishing a module/bundle and executing a Move script in advance using the tool “smove”, an extended variant of the foregoing “move-cli”.

Conclusion

The introduced pallet brings the interoperable Move ecosystem into the Substrate. Slightly tweaked and adapted, but the VM can handle Move language the way it’s supposed to.

We have created comprehensive documentation and two tutorials as part of our commitment to user-friendliness and future updates. These resources provide a quick introduction to using the pallet and guide users on how to modify possible parameter updates in the future. Feel free to reach out to us at hello@equilibrium.co

Originally delivered as Eiger, before Eiger and Equilibrium Labs merged to form Equilibrium.