Ethereum Virtual Machine is a lightweight virtual machine that is designed to run various smart contracts on the Ethereum network. EVM functions differently from traditional operating systems such as Windows that can only run on one machine at a time. An EVM is a high-level abstraction built on a native OS to emulate a physical machine.
With an EVM, the same platform can run on many different operating systems and hardware architectures. This feature makes VMs suitable for networks such as Ethereum that are basically accessible through various clients on different machines distributed all over the world. An EVM can emulate the functions that can be done on a physical CPU and is responsible for most of the functions on the Ethereum network.
EVM has the following characteristics:
A deterministic program gives the same outputs to the same set of inputs irrespective of the number of times it executes the same code. In Ethereum, dApps deal with millions of dollars at a time, and various users need to know how the code reacts at every stage of its execution.
Smart contracts need to run in completely isolated environments. This ensures that if a hack or bug happens to a smart contract it will not affect the rest of the underlying protocol.
Ethereum smart contracts are Turing-Complete. Therefore, they should be in a position to solve any problem given enough time and resources. Smart contracts should come with a terminating mechanism because it is hard to determine if a contract will finish all of its operations within a given time limit or not. Ethereum uses the ‘gas’ limit to terminate smart contracts that exceed execution limits.
WebAssembly (WASM) is a new type of code that executes on modern browsers efficiently. This new code is created and defined by the World Wide Web Consortium (W3C). WASM is built for the web and involves engineers from Google, Mozilla, and Apple. Essentially, WASM, often referred to as Ethereum 2.0, has all the functionalities of EVM and comes with extras.
As already stated, various engineers from big technology companies such as Google, Microsoft and Apple are part of the development team. Such engineers are thus ensuring that WASM is compatible with their engines and protocols.
Simply put, EVM is a jack-of-all-trades but a master of none. How EVM deals with compilation is a perfect example of this point. The native engine struggles with finding the optimal path for executing certain operations, eventually affecting EVM’s overall throughput.
EVM can only process 256-bit bytecodes, which means that those smaller than 256 must first be converted to 256-bit format before being fed to EVM. The scalability issue of EVM is apparent as it only processes 25 transactions per second.
WASM transitions directly into compiled code, which enables it to load faster while at the same time increasing the number of transactions processed by each block.
EVM relies on precompiles (precompiled contracts). When a call for a precompile is issued, the EVM will execute a predefined native code and then present the results. These precompiles are specific to a certain protocol for the basic operations, such as signature schemes and hashes.
Even though precompiles make cryptographic computations efficient without consuming loads of gas, they come with issues. The introduction of new precompiles usually demands the network to undergo a system-wide hard fork.
WASM eliminates Ethereum’s reliance on precompiled contracts. Because WASM is so gas efficient, developers can create smart contracts that are efficient and fast without worrying about potential hard forks.
WASM supports more languages and also comes with a more extensive set of tools than EVM. WASM supports traditional languages such as Rust, C, and C++. WASM is also supported by native JavaScript engines such as Google’s V8 engine (Node.js and Chromium-based browsers), Microsoft’s Chakra engine (Microsoft Edge), and Mozilla’s Spidermonkey engine (Thunderbird and Firefox).
Ethereum introduced certain capabilities that were unavailable on the Bitcoin blockchain. The introduction of the Ethereum Virtual Machine allowed developers to create and deploy smart contracts with ease. However, EVM came with many limitations that WASM is trying to solve. According to WebAssembly.org, WebAssembly 1.0 has already been shipped to four major browser engines.
Also published here.