In the long run, WASM is becoming the choice of more and more projects in the world. Sooner or later, projects such as EOS, Ontology, EOS, Polkadot, Cardano, etc. have already or are developing WASM virtual machines. Included in the Ethereum 2.0 plan, it is also preparing for a complete rewrite of the virtual machine, which will replace EVM with WASM.
Going through the Internet world, WebAssembly is becoming an industry standard. In the past few weeks, Apple and Microsoft have added support for WebAssembly in new versions of Safari and Edge, respectively. Including Mozilla Firefox and Google Chrome have previously supported WebAssembly. This enables the four major browsers to be run on the Web and compiled into WASM code.
What is WASM
WASM (WebAssembly) is a technical solution that can write code in a non-Java programming language and can run on the browser. It is also the first native Java alternative since the emerge of the Web.
For developers, WASM is a new coding method. It has friendly features such as portability, small size, fast loading, and compatibility with the Web, and provides a compilation target (translator) for languages such as C/C++/Rust/Subscript so that it can become a language that the Web can interpret.
WASM Technical Features
Efficiency: WASM has a complete set of semantics, and has a compact binary format with a small size. This makes the efficiency of WASM bytecode runtime close to that of native machine code.
Open source: WebAssembly designed an unconventional whole text format for debugging, testing, experimenting, optimizing, learning, teaching or writing programs. The source code of the WASM module can be viewed on the Web page in this text format.
Why WASM is better
Although EVM is highly compatible, it requires developers to pre-compile. At the same time, the cost of gas is required, which has a high programming cost. The essence of EVM processing code is that the program translates instructions and executes them, instead of reading instructions and executing them by the local machine CPU, so the efficiency is very low.
However, the operation of Java is relatively cumbersome, and it is also inefficient when it needs to be used frequently in the execution process.
Compared with EVM and Java, WASM has been supported by all popular browsers. At the same time, WASM bytecode can compile programs written in all other languages (C, C++, Java). The application layer ecology established based on this not only allows developers to get started quickly, but also has high performance and efficiency to achieve.
On the other hand, the cost of compiling on WASM is greatly reduced. WASM is memory safe, platform independent, and can be effectively mapped to all types of CPU architectures. The instruction set is highly efficient while maintaining sufficient portability. The WASM instruction set can be easily determined by removing floating-point instructions, which will make it suitable for replacing EVM languages. At the same time, WASM can achieve trustless programming without increasing memory consumption. Accurate calculations can be made by stack analysis and measurement on WASM.
What innovations has TrustBase made based on WASM
TrustBase Parachain is a Polkadot parachain based on the Substrate framework that uses the WASM virtual machine to compile smart contracts at the smart contract execution layer. The self-developed Subscript language provides a new solution for the full life cycle development of smart contracts. Specifically:
1. Static syntax checking. Different from TypeScript, which is aimed at the dynamic type operating environment, Subscript has strict static syntax checking when compiling, which avoids the inability to effectively compile the dynamic characteristics of TypeScript in advance.
2. Multiple access support. When the smart contract interacts with the environment outside the sandbox, the parameters that can be passed are limited to basic integer types. Subscript provides a complete syntax that can be used to define external interface types. Subscript also comes with its own command functions that can access the underlying WASM, providing integer operations, virtual machine stack access, memory loading and other operations.
3. Rich library functions. Subscript adds ERC20 compatible, ERC721 compatible contracts, authority control contracts, proxy contracts, governance contracts, multi-signature contracts and other common contract library functions to the extended library, and extends the support for String, Address, Hash and other data types.
4. IDE development environment. Subscript uses Subscript Workbench to provide developers with a browser-based smart contract integrated development environment (IDE). Workbench is similar to the Ethereum development environment Remix, and comes with the compilation tools needed for WASM smart contract development. DAPP developers can synchronize the code in Github in Subscript Workbench, create smart contract projects, compile WASM, and publish to the test network. After the development of the smart contract virtual machine is completed, Subscript Workbench can also provide online debugging functions for smart contracts similar to Remix. Developers can choose to add breakpoints to the browser source code to debug the compiled WASM code in a single step.
Subscript language realizes WASM virtual machine compatibility based on Polkadot Substrate framework. Different with Solidity’s EVM compatibility, WASM has better backward compatibility with Polkadot’s fragmented multi-chain structure. Developers using Subscript language to develop Polkadot smart contracts will not generate historical baggage similar to the Ethereum smart contract platform. With the richness of the Polkadot Parachain ecosystem in the future, this will become crucial.