What Is the Ethereum Virtual Machine (EVM)? 

By Dušanka Seratlić

The Ethereum Virtual Machine (EVM) is a critical component of the Ethereum blockchain that allows for the execution of smart contracts. By creating a middle layer between the code and the hardware, the EVM makes it possible to design Ethereum-based dApps, tokens, and DAOs regardless of the device or platform you might be using.

In this article, we will explore the Ethereum Virtual Machine in more detail, looking at how it works, its architecture, and its role in enabling the decentralized applications that are built on the Ethereum network. Let’s dive in!

What Is a Virtual Machine?

A virtual machine (VM) is a computer program that emulates a real computer, running on top of another computer or device. It allows software to be run on different operating systems and hardware configurations by providing a consistent environment in which programs can execute.

For example, imagine you’re running Linux on your home computer. Maybe you need to do something in Photoshop, but Photoshop is not supported on Linux. How to solve this? One of the options is to run a Windows or MacOS virtual machine on top of your Linux OS. By having a virtual machine, you would essentially have two computers in one: one running Linux, one running Windows. 

How Is the Ethereum Virtual Machine Different? 

There are various types and use cases for virtual machines, but the EVM was designed to be decentralized.

What does that mean? Going back to our previous example, the VM you install might be offered by a single company and is usually run on a centralized server or in the cloud. 

In contrast, the EVM runs on a network of nodes spread across the world, with no central authority. The nodes work together to validate transactions and execute smart contracts on the Ethereum blockchain. This means that control over the execution of smart contracts is distributed across the network, and no single entity has the power to change or manipulate the execution of the contracts.

Additionally, the VM you run on your computer might be different than the one we run on ours.

In the case of the EVM, we all have access to the same computing environment and we all play by the same rules. The EVM functions as a world computer that is secure, decentralized, and accessible to all.

Why Does Ethereum Need the Ethereum Virtual Machine?

The EVM is designed with the singular purpose of providing a decentralized, consistent environment for the execution of smart contracts.

One of Ethereum's key features is that it enables programmable money. Without the EVM, this programmability wouldn’t be possible. Ethereum would function similarly to Bitcoin, existing as a distributed ledger supporting simple transactions.  

And while Ethereum does have a distributed ledger with the record of all transactions going back to the genesis block, it also has a state machine running on top of it - the EVM. Often called the heart of Ethereum, the EVM was the revolutionary idea that enabled Ethereum to become the platform it is today. Without the EVM, we wouldn’t have all the various DAOs, dApps, stablecoins, NFT projects, or DeFi apps we have today.

Pretty great, right? Let’s see how the EVM works under the hood.

How the Ethereum Virtual Machine Works

We mentioned that the EVM is a state machine. The EVM maintains a record of the current state of the Ethereum network, and this state is constantly changing as new transactions and smart contracts are executed. 

For example, when a user sends a transaction to the Ethereum network, the EVM checks the state of the network to ensure that the transaction is valid and that the user has sufficient funds to carry out the transaction. If the transaction is valid, the EVM updates the state of the network to reflect the changes made by the transaction.

Similarly, when a smart contract is executed on the Ethereum network, the EVM uses the code of the contract to update the state of the network in a way that is consistent with the contract's logic and rules.

The EVM is also Turing-complete, or more precisely, quasi-Turing-complete. A Turing-complete system or programming language can solve any problem that is computable, given enough time and memory. The fact that the EVM is Turing-complete means that it can allow for a wide range of applications and use cases beyond simple financial transactions. 

So, what makes the EVM quasi-Turing-complete? To answer that, we need to discuss another important function of the EVM: the gas fees.

Any transaction on Ethereum costs gas. In both Proof of Work and Proof of Stake systems, a portion of the fees is used as a reward for mining or staking. However, gas plays another important role in the system - it secures the network by preventing spam.

What do we mean by that?

Each action the EVM performs costs a certain amount of wei, known as a gas fee. The EVM will execute only those transactions or smart contract calls that have sufficient gas to be executed. You can imagine this as the computation cost for a transaction to go through. So, for example, if you execute a smart contract, it will run only as long as the account has the ether to cover the gas. Once the ether runs out, the EVM will discard the action and the transaction will fail. Why is this the case?

It’s simple. The gas limits and the real-world costs gas introduces serve to prevent spamming. Without gas, a malicious user could let a contract run, spam the network, and congest block space with meaningless transactions. But, because they have to pay gas, there is a limit to how much spam can be introduced to the network. 

Going back to the Turing-completeness, we say that the EVM is quasi-Turing-complete because, while it can solve any computation, it will not do so if the appropriate gas fee is not paid. 

In terms of code, you can use any number of programming languages to write smart contracts (the most popular of which is Solidity). Solidity is then compiled into EVM bytecode, a series of instructions that are interpreted by the EVM.

Bytecode is a low-level representation of code that is machine-readable and executable. Opcodes, on the other hand, are the individual instructions contained within the bytecode that the virtual machine interprets and executes. In other words, the bytecode contains a series of opcodes that instruct the EVM on how to perform specific operations.

How the EVM Interacts with the Ethereum Blockchain

Anyone who runs an Ethereum full node is also running the EVM. You can imagine the Ethereum blockchain as a database and the EVM as the execution layer. You can control the extent to which the EVM and the chain interact, depending on your needs.

The EVM doesn’t have access to real-world data (eg. exchange rates, dates, weather). Instead, the EVM gets the data it needs through oracles. Additionally, the EVM is a sandboxed environment, meaning that you can run a test network and iterate on the smart contracts without affecting the blockchain. 

Once deployed to the blockchain, smart contracts are irreversible. It’s always a good idea to test your code as much as possible before you broadcast your contract for validation.

Why Is the Ethereum Virtual Machine So Revolutionary 

Bitcoin revolutionized digital cash. With the introduction of the EVM, Ethereum made blockchains programmable, allowing for a wide range of use cases beyond simple financial transactions.

Because the EVM is fully virtual, many other blockchains can be EVM-compatible and thus interact with the Ethereum chain, ensuring compatibility and composability cross-chain. 

In short, the EVM makes it possible to have a thriving Web3 ecosystem that extends far beyond Ethereum. 

If you'd like to receive more content like this, subcscribe to our weekly newsletter! 💌

Previous
Previous

The Future of NFTs as Utility Tokens

Next
Next

A Guide to NFT Marketing: A Value-Upfront Approach