This picture will be mintable soon

What is the Ethereum Virtual Machine (EVM)

When developing a smart contract on the Ethereum blockchain, you may have come across the term “Ethereum Virtual Machine”.  It could also be that you have been in this space for some time and have come across the term serendipitously, but still don’t quite understand it. The Ethereum Virtual Machine is essentially a computation engine that allows developers to make Ethereum-based decentralized applications. The function of the virtual machine is to effectively improve the portability of software, making sure applications are separated from each other and their host. In brief, EVM is the underlying foundation of Ethereum’s structure.

What are the Components of the Ethereum Virtual Machine (EVM)?

The EVM is considered to be a complex, dedicated software virtual stack, executing contract bytecodes on the entire Ethereum node. Its role is to deploy a number of extra functionalities to the blockchain to ensure users face limited issues on the distributed ledger. Furthermore, the Ethereum Virtual Machine is considered to be Turing Complete. What this means is that the EVM is capable of programming any computational method or language possible. For example, it is possible to write the equivalent code in another Turing complete language for each EVM programme. However, to do this you will need a compiler that allows you to convert it into code that EVM understands. The compiler required for this is made for the solidity language.

How does EVM work? 

Due to its complex nature, we will explain the different parts of the EVM in as much depth as possible. There are 7 components to consider:

  1. Creating a Smart Contract
  2. Opcodes
  3. Bytecodes
  4. Contract State
  5. Costs
  6. Deployment of Smart Contract
  7. Decompiling of bytecode

Creating a Smart Contract

This is the first step in the process. Smart contracts can be written in a variety of programmes, but the most common one used is Solidity. However, smart contract languages like these can’t be performed by the EVM, and instead, they are compiled into what is known as opcodes. Opcodes are essentially low-level machine instructions that tell the EVM what to do.

Opcodes

In total, there are currently 140 unique opcodes that allow the machine to compute anything if given sufficient resources (Turing completeness). Opcodes are considered to be 1 byte, which essentially means that they are each an individual instruction that the EVM can process. There are various ways in which to categorise opcodes, but because there are 140 we are going to only show you a couple of them. This will help you get an idea of a few of the functions available.

1. Stack-manipulating opcodes

a. POP, PUSH, SWAP

2. Memory manipulating opcodes

a. MLOAD, MSTORE, MSIZE

3. Halting Opcodes

a. STOP, RETURN, REVERT, INVALID

Bytecode

In order for the EVM to store opcodes, they have to be encoded to bytecode. In essence, bytecode allows computer object code to be converted by an interpreter (e.g. Java interpreter) into binary code that computer hardware can read.

Contract State

The contract state is an important feature to take into account with the EVM. This can be categorised into: stack, contract memory, or contract storage.

Lower-level programming languages don’t allow users to pass arguments to functions directly, and instead, use what is known as a stack to pass values to functions. Stack is fundamentally an abstract data type that comprises a predefined capacity, which allows adding and removing elements in a specific order. The issue with this is that the stack has a limited number of items it can hold.

Due to these limitations, complicated opcodes tend to be stored in contract memory so that data can be passed on or retrieved. If one wishes to store data indefinitely and make it accessible in the future then one must use storage. This way, values can be read externally and send transactions to the contract with no fees. The only issue with this method is that it is thousands of times more expensive than stack or contract memory.

Costs

Interacting with the smart contract has costs attached to it and there are ways attackers on the Ethereum network can exploit this. To avoid this from happening, every opcode has a base gas cost assigned to it. The more complicated the instruction for the machine, the higher the gas fee. 

Benefits & Limitations of EVM

The Ethereum Virtual Machine is a beautiful creation, and it certainly comes with many beneficial functionalities. Although this is the case, there are also several limitations that must be taken into consideration. Here is a little overview of the benefits and drawbacks of the EVM:

Benefits

  • Allows developers to create their own decentralized apps 
  • Enables deployment of extra functionalities within a blockchain
  • More secure and private
  • Fully decentralized

Limitations:

  • It can be expensive and slow when the network is busy. 
  • Although Ethereum is technically fully decentralized, 60% – 70% of the nodes are run on central cloud facilities. This is not necessarily an issue as the majority of blockchains run like this, and most cloud servers don’t have all their servers in one location.
  • Requires technical expertise to use → Need to know how to code

FAQs

EVM stands for 'Ethereum Virtual Machine' and is a computing engine that allows developers to create smart contracts & dApps.

No. Many blockchains (like Polygon, Avalanche, and Binance Smart Chain) are EVM-compatible. The XRPL on the other hand is not.

Yes. EVM is Turing complete, meaning, given enough time and processing power, it can solve any computational task, regardless of how complex it is.

Conclusion

The Ethereum Virtual Machine is undoubtedly an incredible feature of blockchain technology. It is a very versatile computation engine with many applications for developers and users. However, due to its complex nature, it is impossible to go into full detail about how everything works in one article. Therefore we recommend you do some further research online as there is tons of information available.

Raul Gavira
Raul Gavira

He is a 29-year-old content writer and digital marketer with a passion for Crypto, NFTs and anything else of the digital realm. Born and raised internationally, he speaks three languages fluently: Spanish, English & Dutch. His first interaction with crypto was around 2013, but he was not a firm believer of it at first. Half a decade later he found himself entering the crypto-sphere and since then he has been mesmerized by it. His goal is to continue to learn more about this fascinating world and contribute positively to its growth.