Ethereum Virtual Machine (EVM): Everything to Know

By  Beluga Research July 13, 2023

Image for Ethereum Virtual Machine (EVM): Everything to Know

Summary

  • On the Ethereum blockchain, smart contracts are executed by the Ethereum Virtual Machine (EVM)
  • The EVM reads and executes bytecode to perform smart contract operations, powering a lot of blockchain applications
  • EVM is deterministic and consensus-driven, producing consistent results agreed upon by the Ethereum network
  • To manage computational resources and prevent abuse, EVM uses a gas system although this can be problematic for some developers

Overview

The Ethereum Virtual Machine, or EVM, is a key component of the Ethereum blockchain platform. It is a virtual machine that runs on top of the Ethereum blockchain and is responsible for executing smart contracts. The EVM is a deterministic, stack-based virtual machine that is designed to be Turing-complete. This means that any program that can be written in any other programming language can also be written in the EVM.

The EVM is a sandboxed environment, which means that it is isolated from the rest of the system. This ensures that the execution of smart contracts is secure and cannot be tampered with. The EVM also has its own bytecode format, which is used to represent smart contracts on the blockchain.

A Brief History

Ethereum was first proposed in 2013 by Vitalik Buterin, a cryptocurrency researcher and programmer. Buterin envisioned a platform that would allow developers to create decentralized applications and smart contracts. Ethereum was officially launched in 2015, and since then, it has become one of the most popular blockchain platforms in the world.

The EVM was also introduced in 2015, and it quickly became an integral part of the Ethereum platform. The EVM was designed to be a fast and efficient virtual machine that could execute smart contracts securely and reliably.

What Is the Ethereum Virtual Machine (EVM)?

The EVM is a virtual machine that runs on top of the Ethereum blockchain. It is responsible for executing smart contracts and running decentralized applications, or Dapps. The EVM is designed to be a deterministic, stack-based virtual machine that is Turing-complete. This means that any program that can be written in any other programming language can also be written in the EVM.

The EVM utilizes a bytecode format to depict smart contracts within the blockchain. The bytecode is a series of instructions that the EVM executes in order to perform a specific task. Each instruction in the bytecode corresponds to a specific operation that the EVM can perform.

One of the key features of the EVM is its sandboxed environment. The EVM is isolated from the rest of the system, which ensures that the execution of smart contracts is secure and cannot be tampered with. The EVM also has a gas system, which is designed to prevent infinite loops and other types of malicious behavior.

Getting Started

To understand the EVM, it's important to first understand what a virtual machine is. A virtual machine is a software environment that emulates a computer system, allowing programs to be run in a platform-independent manner. The EVM is no different in this regard. It is a virtual machine that is designed specifically for executing smart contracts on the Ethereum blockchain.

Smart contracts are written in a high-level programming language such as Solidity and then compiled into bytecode, which is a low-level representation of the code that can be executed by the EVM. Once a smart contract is deployed to the Ethereum blockchain, it becomes immutable and can be executed by anyone on the network.

Unique Aspects

One of the unique aspects of the EVM is that it is a deterministic machine. This means that given the same input, the EVM will always produce the same output. This is important for smart contracts because it ensures that the behavior of the contract is consistent and predictable. This is achieved through the use of a stack-based architecture, where all operations are performed on a stack of values.

Another unique aspect of the EVM is its gas system. Gas is a unit of measurement that is used to determine the cost of executing a smart contract. Each operation in the EVM has a gas cost associated with it, and the total gas cost of a contract is calculated by summing the gas costs of all the operations in the contract. This system is used to prevent malicious actors from executing code that consumes too many resources, which could potentially harm the network.

The EVM also has a built-in system for handling exceptions. If an exception occurs during the execution of a smart contract, the EVM will revert all state changes made by the contract up to that point. This ensures that the state of the blockchain remains consistent and that no unintended side effects occur.

Finally, the EVM is designed to be highly modular and extensible. This means that new opcodes can be added to the EVM to support new functionality, and the EVM can be optimized for specific use cases. This flexibility has enabled the development of a wide range of decentralized applications on the Ethereum blockchain.

Advantages

  • Decentralization. The EVM runs on a distributed network of nodes, which makes it decentralized and resistant to censorship and control.
  • Security. EVM has a built-in security mechanism that prevents malicious code from executing. It uses a gas-based fee system that ensures that smart contracts are executed in a deterministic and predictable way.
  • Flexibility. The EVM is flexible and can run any type of smart contract code, including those written in high-level programming languages such as Solidity and Vyper.
  • Interoperability. EVM is compatible with other Ethereum-based protocols and can interact with other smart contracts and dapps on the Ethereum network.
  • Immutability. Once a smart contract is deployed on the Ethereum network, it cannot be altered or deleted. This ensures that the code remains transparent and tamper-proof.

Disadvantages

  • Scalability. EVM has limited scalability, which means that it can only process a limited number of transactions per second. This can lead to network congestion and high transaction fees during periods of high demand.
  • Gas Fees. EVM requires gas fees to execute smart contracts, which can create a barrier to entry for developers and users who cannot afford the fees. This can also make it difficult to create decentralized applications that require frequent and complex interactions.
  • Backward Compatibility. EVM has limited backward compatibility, which means that older versions of smart contracts may not be compatible with new versions of the EVM. This can create compatibility issues and lead to fragmentation in the Ethereum ecosystem.
  • Code Vulnerabilities. EVM is susceptible to coding vulnerabilities, which can lead to security breaches and loss of funds. Smart contract developers need to be diligent in testing and auditing their code to ensure that it is secure.