The next generation Ethereum Virtual Machine — Crosslink 2019 Taiwan

This is a wrap-up for Second State’s VP of Engineering, Mr. Hung-Ying Tai’s presentation on SOLL, Ewasm VM's current research content and future direction. The sharing is very exciting, including content on EVM bytecode, Webassembly, Ewasm1.0 and Ewasm2.0

EVM bytecode and Webassembly (WASM)

When Ethereum's smart contract transaction is executed, for example, when transfer Token to another address, we read the EVM bytecode into the Ethereum virtual machine, and the EVM bytecode has the following characteristics:

  • 256-bit stack-based virtual machine
  • Too many high level instructions Storage(SSTORE, SLOAD) SHA3(keccak-256) Call, Create Contract…
  • Different from the actual machine architecture (usually 32/64 bit), and 256 bit need to be done by simulation
  • Less language support (Vyper, Solidity, …)

Webassembly (WASM) is a binary programming language that allows suites developed in different programming languages to be used in browsers. WASM has the following features:

  • Stack-based virtual machine: has locals ( ~= register or memory) only access top 3 items from stack v.s EVM’s 16
  • Support for 32 / 64 bit operations
  • No high-level instruction
  • RISC Instruction Set, can map to a common CPU ISA
  • Large community power Supported in all major browser Lots of language support (C++, Rust, …)

Ewasm 1.0

Let's take a look at the features of Ewasm:

  • Ewasm is a subset of wasm
  • Floating point arithmetic is not supported because no error is allowed
  • You can only import the library of Ethereum and avoid importing ㄒ system library.
  • Insert useGAS before each instruction to calculate the cost of GAS

Ethereum Environment Interface

There are many high-level instructions in the EVM like SSLOAD and SHA3. These commands are in Ewasm 1.0. because WASM can dynamically read libraries (modules). Ethereum defines the Ethereum Environment Interface so that clients can use different languages. Corresponding to the library, and it is easier to complete the prototype and upgrade.

The following slide is a list of functions defined by the Ethereum Environment Interface. Ethereum Environment Interface Definition.

How to remove illegal instructions?

Ewasm uses system contract to remove illegal instructions and add useGas bytecode, such as floating point numbers or illegal imports, in two ways:

  • Check the contract's bytecode using the system contract
  • Like the current precompiles running on the client, check the contract before deployment

The following slide shows the Ewasm 1.0 stack. Before the contract deployment, the Ewasm bytecode will be checked by Sentinal. After the successful deployment, the client will communicate with Heru (Wasm Engine) through EVM-C if the contract is to be executed. Ewasm Stack

Performance problem

Does Ewasm perform better? The speaker shared the results of both EVM execution of Sha1 and BN128mul. It can be found that EVM is the faster when running BN128mul, mainly because WASM only supports 32/64-bit operations. For 256-bit it requires additional simulation (ONE 256 bit operations may be replaced by 25 64 bit operations). As EVM provides precompiles, Wasm engine can support bignum library to speed up.

Ewasm 2.0

Ewasm 2.0's smart contract is called Execution Environments (EE), which is different from Ewasm 1.0.

  • EE is all written by WASM
  • Because of the cross shard support, each EE is executed on a shard
  • EE can only get state root, and the execution of the contract is not the same as before.
  • EE is stateless

The following slide shows the ERC20 Token compared to Ewasm 2.0 and Ewasm 1.0 storage. Ewasm 1.0 has a corresponding key for each data, while Ewasm 2.0 only has state root, so it can only interact with state root. Ewasm 2.0 vs Ewasm 1.0

Phase One and Done

At the current stage of Ewasm 2.0 to phase one and done, there are also tested networks that can perform EE on shard blocks, and Ethereum also has open source Ewasm 2.0 test tool: Scout. Hello World for Ewasm 2.0

The above slide is Eth 2's Hello World EE. You can see that the first line in the main function reads the pre state root, then verify if the block data size is 0, and finally save the state root back. Eth 2's smart contract code are all in this form.

Conclusion

Ewasm 1.0 currently supports EVM 1 and most of the functions have a test net. Second state develops a compiler SOLL, which can compile solidity into Ewasm. Check it out if interested.

Ewasm 2.0 is still under study. The following slide is the direction of the research and contribution shared by the speaker.

Reference

1.Crosslink 简报 2.webassembly.org (http://webassembly.org/) 3.Scout 4.Second State’s Soll Compiler 5.Compiling and deploying an ERC20 contract onto the eWASM testnet— YouTube 6.Ewasm overview and the precompile problem: Alex Beregszaszi and Casey Detrio @ Ethereum \\ Part 1 — YouTube 7.Ewasm overview and the precompile problem: Alex Beregszaszi and Casey Detrio @ Ethereum \\ Part 2 — YouTube 8.Wasm for blockchain&Eth2 execution: Paul Dworzanski,Alex Beregszaszi,Casey Detrio@Ethereum \\ Part 2 — YouTube 9.Ewasm for sharding 10.Ewasm updates 11.Ewasm design 12.wasm-intro

Translated from traditional Chinese by Ethereum Taipei