September 16, 2022

Ethereum Virtual Machine (EVM): What Is It And How Does It Work?

The Ethereum Virtual Machine (EVM) is the core feature that makes Ethereum a decentralized platform rather than just a distributed ledger. The EVM allows developers to create smart contracts in Solidity, a programming language that opens the door to secure multi-party computation. This means that several parties can agree on the outcome of the action without having to trust or rely on one another.

Many applications and protocols use smart contracts to reward users for actions valuable to their goals. The EVM is also instrumental in Ethereum’s ability to generate tokens; many projects issue their own tokens as rewards for participation in their ecosystem.

But what exactly is EVM, and how does it work? Keep reading to learn more about this impressive technology.

What is EVM?

Even the most powerful and smartest hacker in the world would find taking down a decentralized network hard, which would require shutting down each network member.

To scale a decentralized network and build secure products, developers use virtual machines (VM). A VM is an abstraction layer between the code and the machine executing the code. Since you can run VMs on different operating systems and hardware and from any geographical location, they work like physical machines with storage, memory, and CPU but operate purely as code.

In theory, any user can run a VM, which makes it a highly portable platform for a decentralized network. This is what the Ethereum Virtual Machine is all about. It uses a decentralized network of nodes to execute smart contracts.

The EVM is a virtual machine that runs smart contracts written in code compiled to bytecode that EVM understands. This isolates the machine code from the rest of the network, as well as its filesystem, and any processes on the host node. Each node on the network runs instances with identical instruction sets.

Smart contracts and EVM

Smart contracts are self-executing computer programs that use digital assets to facilitate, verify, or enforce the negotiation or performance of a contract. They’re “Turing complete” and can run any code, including scripts.

You’ll find a list of defined operations executed within a smart contract when certain conditions, on or off-chain, are met – like transferring funds to a certain address, communicating with another contract, or even creating a new contract. Instead of a third party executing the transaction, any sender can send funds to the smart contract address to trigger these operations.

What makes smart contracts a secure method of transacting is the fact that nobody can change the code. There is always an expected outcome from the smart contract – this is the built-in trust of the code. Anytime a contract is executed, it changes the state of the EVM.

The Ethereum Virtual Machine (EVM) is responsible for computing the state changes that result from executing smart contracts. The EVM maintains the account ether balances, data storage of smart contracts, and transactions on both account and contract levels as they are completed. All these actions change the state of the network.

Smart contracts are primarily written in Solidity but cannot be directly executed by the EVM, so developers first compile them to low-level machine instructions called opcodes.

How does the EVM work?

The Ethereum Virtual Machine’s instruction set allows smart contracts to perform any computational task. Popular use cases include fungible tokens that adhere to the ERC-20 standard and non-fungible tokens (NFTs) under the ERC-721 standard. These NFTs have various properties and are used in crowdfunding, decentralized finance markets, prediction markets, and gaming.

However, their ability comes with a crucial caveat: some programs could take forever to execute. This is called “the halting problem” and puts the Ethereum network at risk of running an endless looping program. The solution to this is a scheduler. Without a scheduler, a program like this might completely stall the network. Ethereum has a smart way of dealing with this issue: Ethereum gas.

What is Ethereum gas?

The Ethereum Virtual Machine (EVM) has a built-in gas mechanism to limit computational power consumption. The network demands fees for its computation costs in the form of ‘gas.’ After a specific level of maximum computation has been performed, the execution ends after the gas fuelling the transaction is depleted. This is when the EVM halts the program.

This makes the EVM only a quasi-Turing complete machine – it runs any program, but only if it ends after using a certain amount of computational power. This limit isn’t set in stone and can be increased by users as long as necessary, but there is a limitation on how much computation a contract call can consume at any given instance. Transactions that go over this limit are terminated.

Challenges of the EVM

The Ethereum Virtual Machine (EVM) has several limitations that affect the network’s total throughput. The EVM’s opcode specification hasn’t been altered since its creation, and it is not optimized for different hardware platforms.

Furthermore, the EVM has to process so many disparate operations, making it slower than it could be. This generates an operational bottleneck that dramatically impacts the blockchain’s efficiency. The EVM hasn’t evolved much since its original design, limiting the platform’s tool and language support for writing smart contract code.

Use cases of the EVM

ERC-20 Tokens

ERC-20 tokens are a type of token that can be transferred from address to address, have a limited supply, and whose value remains constant across the network. Smart contracts following an established data structure on the Ethereum Virtual Machine are used to create ERC-20 tokens.

This data structure controls how names, distributions, and supplies are controlled as well as how they can be monitored. Several applications employ ERC-20 tokens to incentivize users. For example, Livepeer – a decentralized video streaming network – uses its LPT token to incentivize those who supply resources to the network. Nexus Mutual, a decentralized insurance platform that uses smart contracts, takes advantage of the NXM token to allow users to purchase coverage and make claims.

Decentralized Exchanges

A decentralized exchange is a platform that allows users to trade ERC-20 tokens by deploying smart contracts. These smart contracts are called Automated Market Makers (AMM) because they allow users to contribute to liquidity pools of certain tokens without any third party controlling it. Some popular decentralized exchanges include Uniswap and SushiSwap.

Writing smart contracts to Ethereum vs. other networks via EVM

Since the compiler doesn’t change and the runtime environment is identical, writing contracts for the Ethereum or Avalanche C-chain or Polygon Network is identical.

The only change is the different deployment procedure compared to pure Ethereum, which adds a few hours or days of work to the process. Ethereum has contracts that allow developers to write all this logic – but it’s expensive, the transaction fee is high,
and other blockchains offer the same at a much lower fee. You might implement the same logic on a different chain, e.g., Polygon, and it will be 10x cheaper.

Naturally, the Ethereum blockchain has its reputation, and the risk that something goes wrong is lower than in the case of the other more cost-effective chains. However, Polygon and Avalanche chains are recognized crypto chains, and the slightly higher risk might be worth it.

Wrap up

The EVM makes Ethereuma platform instead of just a blockchain. The EVM comes with a number of limitations that are an area of focus for the development community. Thanks to the improvements made to the EVM, it will be more likely for Ethereum to fulfill its promise of revolutionizing how users transact with each other.

At 4soft, we write smart contracts using Solidity. The application is compiled to bytecode, which EVM finds understandable. The great thing about this solution is that bytecode is also understandable to other networks – for example, Avalanche C-Chain. So, there’s no risk that our team doesn’t deliver a smart contract, even if we’re not experts in the language of the particular chain.

Get in touch with us if you’re looking for blockchain experts who know how to take advantage of technologies like the EVM.

September 16, 2022