Ping.pub - Move VM on Nervos Proposal

Move VM on Nervos Proposal

This proposal aims to port Move VM on Nervos, It includes the following parts:

  1. Move VM on Nervos
  2. A library that allow Move script to inter-operate with Nervos. including loading data from Nervos, updating data to Nervos, publishing Move Modules and running Move scripts.
  3. A toolkit, including Move Compiler, Move Bytecode Verifier, Simulator etc.

Team backgrounds

Our team, Ping.pub, is a startup focused on blockchain technology. We provide secure and robust validator services for many POS blockchains, such as Cosmos, IRISNET, Kusama etc. We won the ‘Uptime Leader’ prize on the Cosmos GoS hackathon, and we also developed a browser, wallet, and faucet module for Cosmos.

Co-founders:

  • Dongdong Ma - Graduated from Tsinghua University, worked as a CTO for several years in a subsidiary of Tsinghua Tongfang
  • Ping Liang - Serial entrepreneur, successfully founded several Internet companies, and is also a programming enthusiast and contributor to the open source community
  • Yiming Ding - Active contributor to the Vue community, a big fan of smart contract development

Team Website
https://ping.pub

Project and justification

Move was invented by Facebook using as smart contract language on it’s blockchain - Libra. It is the most advanced smart contract language in the world. Move is simple, secure and powerful.
Although Nervos already has many smart contract languages and SDKs, we still strongly recommend that Nervos should have Move, because it can expand the types of smart contract languages, and it can also build a bridge that connects the Libra ecosystem to bring more developers and investors.

Our co-founder Mr. Liang Ping has been deeply involved in the development and testing of the Java VM on AIX unix / OS2 at IBM. This work experience is very helpful for porting Move VM. Since Facebook announced the Libra project, our team has been researching and learning the Move language and how Move works. Plus most developers in our team are proficient in multiple programming languages, such as C / C ++, Java, Rust, Go, Solidity. Based on the above experience, we are confident that we can complete the project of porting Move VM to Nervos

Technical specification and implementation

This is a complex and challenging project, but we want to illustrate his implementation in the simplest way

  1. Move VM Runtime
    Move VM Runtime is a key component that allows the blockchain to execute move Bytecode. It is a rust program, we only need to specify the target platform as risc-v when it is compiled. In theory, this will allows the Runtime to run on the CKB VM.
  2. Model Transform
    Libra uses the account model by default, while CKB uses the Cell model. In order to adapt to this change, we have to modify the built-in functions of Move.
  3. Toolkit
    As we add changes to built-in functions and account models, we also have to adjust Move’s official compiler and Bytecode Verifier.
  4. Execution of Smart Contract
    Each smart contract will accept some parameters and global state as input parameters. When the smart contract is executed in the Move VM, the state will not change immediately, but a “Write Sets” will be generated as output. These inputs and outputs can be mapped to the input cell and output cell.
  5. Storage of Smart Contract
    Move VM can execute two types of programs: transaction scripts and modules(Smart contract in other blockchain). We plan to embed one-time transaction scripts in TX and store reusable modules in script cells.
  6. Dependency of Smart Contract
    Usually a module needs to import other modules to implement its business logic. So when VM execute these smart contracts, there needs to be a mechanism to ensure that the dependencies required by the module and the corresponding storage cells are also preloaded.

Timeline/Roadmap

  • M1. 1 month, run Move VM on CKB VM and successfully execute a simple move script.
  • M2. 1 month, Implement Move Bytecode deployment / store / load on Nervos.
  • M3. 2 ~ 3 months, complete the Move VM to read the parameters and preload the dependencies from Nervos, and update the state changes produced by Move VM to Nervos.
  • M4. 2~3months, Move SDK & built-in functions
  • M5. 1 month, Toolkit
  • M6. 2 month, Best practices, Tutorials, docs.

Approximately 5 months in total.

3 Likes

First, MoveVM is a standalone and general-purpose virtual machine for smart contract . We can compile it into a standard ELF format executable file and run it on the RISC-V environment. Actuallly, Facebook has built LibraVM on top of MoveVM. This design fully illustrates that Facebook intends to make Move a universal smart contract language.

Second, although the Move language is a specialized smart contract language, it is actually the same programming language as other languages, such as Ruby. Therefore, our porting process is similar to CKB Ruby.

Third, Module Transforming. Libra’s account model is mainly implemented by the two built-in Std modules named LibraAccount and LibraCoin. In fact, we do not need all the Std modules of Libra and will delete them. What we need is building a new stdlib that implement the CKB environment and Cell model, including loading transaction, script hash, cell data as well as algorithms. The reference is as follows:
mruby-contract and cbk-syscall

Fourth, how is it implemented? Referring to the implementation of Ruby, the execution of the move bytecode will be converted to this form of script model on Nervos for execution

{
  "version": 0,
  "reference": "0x12b464bcab8f55822501cdb91ea35ea707d72ec970363972388a0c49b94d377c",
  "signed_args": [
    "Move Bytecode Script", 
    "024a501efd328e062c8675f2365970728c859c592beeefd6be8ead3d901330bc01"
  ],
  "args": [
"3044022038f282cffdd26e2a050d7779ddc29be81a7e2f8a73706d2b7a6fde8a78e950ee0220538657b4c01be3e77827a82e92d33a923e864c55b88fd18cd5e5b25597432e9b"
    "1"
  ]
}

Finally, About storing states needs CKBytes。So far I haven’t found any particular codes to deal with this in Ruby’s implementation, please let me know if I am wrong. As far as I know, CKB is related to the capacity of Cell. Cell is mainly used to implement asset storage. If necessary, we can add corresponding code to handle this logic.