Topics Tech Deep Dive

What Is an Ethereum Virtual Machine (EVM)? A Beginner's Guide

Advanced
Tech Deep Dive
17 Jul 2022

The Ethereum virtual machine (EVM) is often referred to as “the heart of Ethereum” — which is exactly what it is. Just as the heart pumps blood that distributes oxygen and nutrients throughout the body, an EVM grants developers the ability to create smart contracts and DApps in the Solidity programming language. It’s responsible for the majority of DApps being created today, which is what distinguishes it from Bitcoin and other distributed ledgers. In this article, we’ll dive headfirst into Ethereum virtual machines and break down what they are, how they work and their role in DApp development and the advancement of Web 3.0.

What Is an EVM?

An Ethereum virtual machine is a software platform, or “virtual computer,” used by developers to create decentralized applications (DApps), as well as to execute and deploy smart contracts on the Ethereum system.

Whether you’re a programmer with an interest in DApps or an investor wanting to learn more about the ever-evolving world of EVM crypto, you’ve probably heard of Ethereum virtual machines.To best understand what an EVM is, it helps to first learn a little about its history.

According to Vitalik Buterin, Ethereum’s creator, BitTorrent was the very first DApp. Bram Cohen invented the file-sharing protocol in 2001, and despite several efforts to destroy it, BitTorrent remains very much alive.

To truly halt BitTorrent, every computer in every home across the world would have to be shut down. It’s a virtual machine unbound by physical constraints. The same is true of the Ethereum virtual machine. The EVM eliminates the need for superpowered hardware, and is an ideal platform for beginning programmers. However, knowledge of bytes, stacks, and blockchain concepts like hash functions and proof of work is helpful when trying to gain a deeper understanding of EVM-compatible code and the Ethereum virtual machine in general.

The Ethereum virtual machine’s purpose is to determine the state of every block in the Ethereum blockchain. While EVMs are similar to other blockchain-based networks in that they use a distributed ledger to maintain databases for transactions, they add another layer of functioning due to their smart contract capabilities. Many refer to this second layer as a “distributed state machine.”

What Does an EVM Do?

In its most rudimentary form, an Ethereum virtual machine is a large database for holding all of Ethereum’s accounts and balances. At the same time, it’s also a machine state with the ability to execute machine code and change with each new block added to the blockchain ledger. The specific rules that determine how the EVM will change with each new block are actually defined by the EVM itself.

More simply put, an Ethereum virtual machine is a processing engine and software platform that functions like a decentralized computer. From DeFi and EVM crypto apps to games and marketplaces like OpenSea, developers use the Ethereum virtual machine to create DApps based on Ethereum and its EVM-compatible programming language, Solidity.

Most important, the Ethereum virtual machine is the part of the Ethereum network responsible for the execution and deployment of smart contracts. It’s where smart contracts and millions of DApps based on Ethereum blockchain live and breathe.

Think of Ethereum’s blockchain as a P2P structure of different individual nodes. One node connects to the next, making each node responsible for the security and stability of the entire ecosystem. To do so and maintain consensus throughout the Ethereum blockchain, each node uses the EVM.

EVMs and Their Similarities to CPUs

To further clarify the concept of the EVM, it helps to get back to basics by thinking about how computer programs work. All of their software is written in a programming language, such as Java or C++. However, since CPUs can’t read Java or C++, the code is compiled and translated into bytecode.

Ethereum isn’t a CPU — it’s a distributed worldwide network with 100 CPUs simultaneously running the EVM. However, the EVM functions as a virtual CPU or virtual “machine” running inside of the Go Ethereum, or “Geth,” program.

Similar to other software programs, developers create DApps and write smart contracts in a programming language. Instead of Java or C++, the language for Ethereum is called Solidity. Solidity code is compiled into bytecode and distributed to every computer (node) running Geth in the network.

When a smart contract gets deployed, every node receives a copy of it, runs its bytecode and gives the code to whomever called for the deployment, resulting in “state change.” This means the blockchain’s current state has been altered, which can be done only with the consensus of every node.

Therefore, an EVM is often referred to as a “distributed state machine.” It tracks the state of the blockchain as it transforms with each transaction.

How Do EVMs Work?

If you’ve ever downloaded a song, movie or software from BitTorrent, then you know what a decentralized network can do. Even the world’s most powerful authorities can’t remove it because doing so would require shutting down every computer tied to the network.

One of the best ways of scaling a decentralized network is through the use of virtual machines. Acting as a layer between machines and the code they execute, virtual machines can be run on various hardware and operating systems from anywhere in the world.

Virtual machines like the EVM function similarly to physical machines with CPUs, memory and storage, but they operate as nothing but code. Theoretically, anyone can run a virtual machine, giving it the flexibility and portability decentralized networks need.

The Ethereum virtual machine uses a decentralized nodal network to execute smart contracts. It’s a dynamic, sandboxed virtual stack, embedded inside each Ethereum node to execute EVM-compatible smart contract bytecode.

Smart Contracts, Nodes and P2P

When learning what EVMs are and what they do for crypto in cases like DeFi lending, keep in mind that smart contracts are written in Solidity and other higher-level languages, and then they’re translated to bytecode and compiled to the EVM. This means the machine code is isolated from the filesystem, processes and network of the host computer.

Each node in Ethereum’s network must agree with the next one in order to execute the same instructions. This makes the Ethereum virtual machine Turing Complete, which means it can perform logical steps for computational function.

For each instruction the EVM implements, a cost is assigned to it, allowing the system to keep track of the execution costs. The cost of making EVM crypto transactions and executing other instructions is measured in EVM-compatible units known as gas.

By enabling an economy based on charges for executed instructions rather than executed financial transactions, like Bitcoin, Turing Completeness is achieved. This means the Ethereum virtual machine is a peer-to-peer, globally connected computer, able to create smart contracts, P2P crowdfunding events, file-sharing economies and more.

Not unlike the internet in the early 1990s, the future is there for the taking.

Opcodes

At the moment, there are approximately 150 different opcodes an EVM can execute. So, what exactly are opcodes — and why are they important in understanding EVMs?

The reason the Ethereum virtual machine is referred to as Turing Complete is largely because of its ability to execute machine-level instructions known as opcodes.

EVM-compatible opcodes help the EVM complete specific tasks related to EVM crypto transactions or smart contracts. However, opcodes are used for a variety of operations, ranging from arithmetic and data logging to memory and the retrieval of block information.

That said, opcodes aren’t written directly into an EVM. Due to their ability to let developers easily create and interact with smart contracts, EVMs are written in the Solidity programming language. However, this native language must be converted to opcode for an EVM to interpret.

Each opcode is assigned one byte. This means a maximum of 256 opcodes can be used.

Smart Contracts

When trying to understand what an EVM is, a basic knowledge of smart contracts and their role in EVM crypto, DeFi and other blockchain functions is necessary.

Sometimes referred to as the “App of the EVM,” smart contracts are EVM-compatible lines of code used by parties to transact with one another without the use of a third party, or interference from central authorities.

Within each smart contract is a defined list of operations that are to be executed when certain on- or off-chain conditions are met. These operations can range from the transfer of funds to certain addresses, to the creation of new smart contracts and the communication between existing ones. Instead of requiring a third party, anyone can send funds to a smart contract address to prompt these operations.

Ethereum took the Bitcoin concept and supercharged it by allowing developers to build smart contracts on top of their blockchain. The next step was creating an environment where smart contracts could live and interact with one another. This is where the Ethereum virtual machine comes into play.

The EVM combines the resources of not just one but thousands of CPUs connected to Ethereum’s network. In addition to verifying transactions, it translates smart contract opcode written in Solidity into bytecode, so instructions can be read and operations can be executed. For this last part, you need gas.

Gas

Gas is the fuel that drives the Ethereum virtual machine. Whether you’re transferring EVM crypto or investing in an NFT, gas is needed to pay for the execution of the operation. Gas acts as a computational fee required for executing smart contracts.

Each opcode is assigned a gas cost. The more complex the opcode, the higher the gas fee. At the moment, the starting cost of every transaction is 21,000 gas.

Gas fees are charged to compensate the validators responsible for checking to make sure the transaction information is valid, and that there are no exceptions or errors from the EVM.

Even more important, gas fees help prevent DDoS attacks and keep the network secure. Since deploying complex contracts at scale would require lengthy and expensive computations, attackers are monetarily discouraged from making any malicious attempts. The attack would simply be too expensive to run.

What Are EVM-Compatible Blockchains?

Interoperability between blockchains has proven to be a significant problem. As issues with Ethereum — such as high gas fees and slow transactions — persisted, developers began creating DApps and smart contracts based on other permissionless blockchains to offer faster transactions and lower gas fees. Unfortunately, many of these blockchains are severely limited and lack interoperability with other blockchains.

EVM-compatible blockchains have proven to be an easy way of solving this issue. Rather than starting from scratch and creating an environment similar to that of EVMs through the use of cross-chain bridges, developers can copy certain pieces of the Ethereum network, and create DApps that allow users to quickly and easily transfer assets between any EVM networks.

With this interoperability, many of today’s most used blockchains follow this EVM-compatible model. Examples include some of the biggest names in the EVM crypto space, such as:

Binance Smart Chain

Avalanche

Fantom

Cardano

Polygon

Tron

Regardless of your reasons for wanting to understand EVMs, it’s important to know that all of these sidechains are EVM compatible.  They offer all of the benefits and reach of the Ethereum blockchain, but with faster speeds, higher capacity and lower transaction costs.

Ultimately, when discussing EVM-compatible blockchains, it all comes down to optimization and creating the best possible decentralized user experience. That said, there are other benefits as well.

Ethereum Ecosystem Interoperability

One of the biggest benefits of EVMs is their interoperability within the Ethereum ecosystem. Ethereum is the most widely used blockchain in the world. Thanks to the Ethereum virtual machine, DApps based on the Ethereum blockchain are able to communicate and interact with one another, allowing for a faster and more seamless user experience.

By using blockchain bridges, interoperability among blockchains can be achieved. Users can freely send assets across EVM networks from one DApp to the next.

Easy for Dapps to Be Ported Over

Ethereum virtual machines make it easy to migrate and expand DApps to new chains without having to rewrite any code. Using another type of virtual machine, like Move-VM or Wasm, requires more resources and makes porting DApps much more difficult.

Low Barrier to Entry for Ethereum Developers

An EVM also has a low-barrier entry for Ethereum developers. There’s no need to worry about the nature of EVMs, or whether their code is EVM compatible. There’s also no need to learn other programming languages, since developers can use familiar Ethereum tools such as Waffle and MetaMask.

EVM Use Cases

Now that we’ve gone over what an EVM is and how it works, let’s look at how everything comes together to power EVM crypto and other Ethereum-based projects.

ERC-20 Tokens

Several DApps and Ethereum projects incentivize users with ERC-20 tokens, which are specifically designed to be easily transferred between addresses and maintain the same value across the network.

ERC-20 tokens are created by smart contracts following defined data structures. This data structure is responsible for naming, distributing and monitoring the token.

These tokens are used for much more than EVM crypto. Nexus Mutual, which provides insurance on smart contracts, utilizes the NXM ERC-20 token to give users the ability to make claims and purchase coverage. Another example is Livepeer. Although it’s not exactly the most popular example when discussing EVMs, this decentralized video streaming network employs the Livepeer ERC-20 token to incentivize users to supply the network with resources. These are just two of the many DApps that handle ERC-20 tokens.

AMMs and DEXs

Decentralized exchanges (DEXs) enable the exchange of ERC-20 tokens through the deployment of smart contracts. These smart contracts allow users to tap into the liquidity pools of tokens without third-party interference, giving them the title of automated market makers (AMMs). SushiSwap, Uniswap and several other popular exchanges are actually applications of this decentralized AMM model.

NFT Minting

Another widely popular token is the non-fungible ERC-721. Smart contracts with this token are frequently used for minting non-fungible tokens (NFTs), which are tokens possessing unique value across the Ethereum blockchain.

Unthinkable a few years ago, a piece of code now has the ability to democratize virtual access to art markets. Such gaming projects as Gods Unchained and Axie Infinity also use these tokens for in-game items and collectables.

DeFi Lending

AdaSwap is a Cardano-based decentralized exchange with an AMM. Recently, it announced a collaboration with Milkomeda. Using Layer 2 solutions for a sidechain, Milkomeda gives non-EVM blockchains like Cardano EVM compatibility. With this sidechain, users can transfer assets and run Cardano DApps on Ethereum, and vice versa.

AdaSwap and Milkomeda are using this collaboration to integrate Ethereum virtual machines into the Cardano ecosystem. There are several other DeFi platforms following Cardano’s lead.

DAOs

The Ethereum virtual machine is governed by a decentralized autonomous organization, or DAO. A DAO is a communal entity that lacks a central authority. This gives the community control over the network.

DAOs are Nnot only are DAOs fully autonomous, but they are transparent as well. Smart contracts outline the rules and execute decisions based on code-written instructions, but at any point, voting and proposals can be made through consensus. Even the code itself can be open to public audit.

Ultimately, DAOs are entirely governed by individual members who collectively make critical decisions regarding the project. collectively. The rules of a DAO are established by core community members and implemented through smart contracts. Since these are visible, verifiable, and open to public audit, every member of the DAO can understand how the protocol functions at each and every step of the way.

EVM Limitations

When trying to understand what is an EVMs, it's important to consider both their pros and their cons. Despite its many advantages, EVM technology also comes with certain limitations. For one thing,irstly, using an Ethereum virtual machine requires some level of technical experience. Knowledge of Solidity, Java, and other programming languages is a must.

Secondly, EVMs are infamous for their high gas fees. No matter how smart an EVM may be, it can’t avoid its own popularity and the data congestion that comes with it, resulting in higher transaction fees compared to other chains.

Lastly, the Ethereum virtual machine isn’t entirely decentralized. In fact, about 25 percent of Ethereum nodes are actually running on Amazon Web Services. If AWS were to experience a major outage or discontinue its services, EVMs and the DApps they power would be noticeably affected.

The Future of EVMs

When it comes to Ethereum blockchain and EVMs, we are only at the beginning. In the near future, the speed, complexity, and ability of the Ethereum virtual machine will only increase, in much like the same way as the PCs of the 1990s evolved into the processing powerhouses being used today.

That said, EVMs aren’t perfect. Challenges regarding network throughput and transaction speed continue to be an issue plaguing the system. Currently, these issues are focal points for the Ethereum development community, and solving them is a road map for Ethereum’s continued usage and success.

If Ethereum is to live up to its promise of revolutionizing the way we interact and transact with each other, it will be the result of improvements made to the EVM.

The Bottom Line

In this article, we’ve traversed the Ethereum virtual machine, explored the execution of smart contracts, and looked at how EVMs execute bytecode. We’ve also discussed gGas, the accounting mechanism for EVMs, and talked about how itthey facilitates transactions and protects Ethereum from DDoS attacks. Ultimately, EVMs are the heart and soul of smart contract deployment and execution. Gaining a deeper understanding of the Ethereum virtual machine is essential a must for anyone looking to develop DApps and dive into our future decentralized world.