Table of Contents
- What is the Ethereum Virtual Machine (EVM)?
- How Does the EVM Work?
- What are the Differences Between State Machines and Distributed Ledgers?
- Why is EVM Compatibility Important?
- EVM Use Cases
Ethereum Virtual Machine is a computation engine that implements smart contracts and updates the state of the Ethereum blockchain after a block is added.
EVM compatibility is the ability to write and run a smart contract code compatible with the EVM; thus, it can be interpreted by the Ethereum nodes.
ERC20 tokens, DEXs, DAOs, and NFTs are the common use case of the EVM.
Bitcoin (BTC), the biggest cryptocurrency by market cap, introduced the world to crypto in 2008. However, most people felt Ethereum’s practical application of smart contracts in 2015 was the most important step towards perfecting Bitcoin’s formula. Essentially, smart contracts enable developers to store on-chain activities by programming them. To understand smart contracts properly, you should learn about the Ethereum Virtual Machine (EVM), which is the engine that facilitates the creation and deployment of smart contracts. Bitcoin also has its own smart contracts, albeit not as complex as Ethereum's.
This article takes a closer look at EVM, what it is, how it works, the differences between state machines and distributed ledgers, the importance of EVM compatibility, and EVM use cases.
What is the Ethereum Virtual Machine (EVM)?
We can think of the Ethereum Virtual Machine as a software piece built on the hardware/node infrastructure of the Ethereum network. This software piece fulfills essential roles like running and maintaining smart contract code.
Source: Ethereum illustrated
The illustration shows that EVM is both a virtual and state machine. But what does that mean?
EVM as a Virtual Machine
EVM is a Turing-complete virtual machine you can access from any part of the world via a network node. The point proves EVM’s Turing completeness that it can deploy any computer program. Basically, Ethereum developers can’t run decentralized applications (dApps) that power decentralized finance (DeFi) without EVM.
It’s important to note that virtual machines are not tied to specific physical gadgets, nor do they have interfaces and hardware. They leverage the computing power of various participants (nodes) to create a runtime environment for creating and deploying smart contracts. Unlike physical computers, virtual machines are not limited to one operating system or geographical location. Participants across the world can use them regardless of their jurisdictions and hardware devices.
EVM as a State Machine
A state machine is a computation engine that changes across states. When you send a transaction request to a smart contract, the EVM switches Ethereum’s state to respond to your call. The ability to interpret and implement smart contract requests distinguishes Ethereum from other networks, such as Bitcoin. According to smart contract input data, EVM’s state-switching ability enables Ethereum to keep up with other states from block to block.
EVM can deploy any smart contract program. But more intricate smart contracts require more gas fees to run. While gas fees have become a contagious issue in crypto, they are a core aspect of the EVM. A line from the Ethereum yellow paper reads: “the computation is intrinsically bounded through a parameter, gas, which limits the total amount of computation done.” The gas and gas limits help the EVM mitigate network abuse.
How Does EVM Work?
The EVM utilizes a stack-based architecture and a word size of 256 bits. The word size enables EVM to handle native hashing and elliptic curve processes, ensuring the rightful owners spend assets. Though Solidity is the most common smart contract language, the EVM supports other languages like Vyper. Developers use programming languages to code smart contracts, which are compiled into bytecodes. Runtime bytecodes are bytecodes stored on-chain. They are also converted into opcodes that the EVM interprets to perform requests.
The EVM is loaded with details when a transaction request initiates a smart contract. The other variable necessary for implementing smart contracts is the gas supply, which relates to the gas fee users pay. The gas supply decreases as the transaction progresses, and if the supply hits zero, the transaction is discarded. Discarded transactions are not included in the network blocks since they are considered invalid. However, the block verifier is compensated for offering resources up to the abandoning stage.
Smart Contracts and the EVM
Smart contracts, or the “App of the EVM,” are EVM-compatible code lines for interacting between parties without needing an intermediary. These contracts are loaded with pre-defined activities implemented when the conditions are met. These activities range from asset transfer to developing new contracts and the interaction between existing ones.
Ethereum grabbed the Bitcoin concept and built upon it by enabling developers to create and run smart contracts on the network. The most important step was establishing an EVM environment where smart contracts could live and operate.
Why is Gas Needed for the EVM?
Gas is the fuel that powers the EVM. When you interact with smart contracts (like sending crypto to another wallet or borrowing in a lending protocol), you must pay gas for the network validators to verify your transaction. Moreover, gas acts as a computation fee for implementing smart contracts.
Opcodes are the part of machine language instruction that specifies the operation that needs to be performed. Every opcode is allocated a gas fee, and the more complicated the opcode, the higher the gas. Gas fees are used to reward validators for providing the much-needed resources to verify transactions. Besides, gas fees monetarily prevent Distributed Denial of Service (DDoS) attacks and keep the blockchain secure and running.
What are the Differences Between State Machines and Distributed Ledgers?
Often, people use the analogy of decentralized ledgers to refer to blockchains like Bitcoin, which facilitates a distributed digital currency through core cryptography tools. Essentially, the ledger maintains an activity account that follows a set of rules that control what users can and cannot do with it. For instance, your Bitcoin wallet can’t spend more coins than its balance. Such rules reinforce Bitcoin transactions and many other networks.
Though Ethereum has its native currency, Ether (ETH), which complies with almost similar pre-defined rules, it also has a much more powerful feature – smart contracts. This powerful feature calls for a sophisticated analogy. As such, Ethereum is a state machine – an extensive data structure that maintains accounts and balances and can change from block to block according to the set rules – where the Ethereum Virtual Machine (EVM) defines the rules of switching block states.
A state machine’s ability to interpret and implement smart contract requests distinguishes it from distributed ledgers like Bitcoin. Unlike Bitcoin, Ethereum’s state changes enable developers to build custom cryptocurrencies and Non-Fungible Tokens (NFTs), signify ownership of underlying physical assets, develop domain names, and build fully-functioning DeFi apps.
Why is EVM Compatibility Important?
EVM compatibility is the ability to write and run a smart contract code compatible with the EVM; thus, it can be interpreted by the Ethereum nodes. EVM compatibility has allowed the most popular Layer 1 (L1) chains, like BNB Smart Chain, Avalanche, Polygon, and Solana, to be highly effective. This also minimizes the entry barriers for app developers to run Ethereum smart contracts on multiple chains.
As mentioned earlier, the EVM converts various smart contracts into a bytecode – a standard format decipherable by the Ethereum blockchain. This allows developers to flawlessly run Ethereum codes on EVM-compatible chains, eliminating costly and time-consuming contract audits. The “Plug and Play” function makes the chains appealing to developers as they take minimal time to deploy dApps.
From a user’s point of view, it’s advantageous to use EVM-compatible networks as they enable users to become early adopters of newly launched products and services. This often includes airdrops, where projects give cryptocurrency tokens away in exchange for meeting certain criteria. New projects also offer early adopters better returns on their staking and liquidity pool investments.
EVM compatibility is also important in building cross-chain bridges that unlock value transfer across chains. For example, much of the success of the BNB Smart Chain resulted from the ease with which Ethereum ecosystem users could move their assets to a new blockchain through the Binance bridge. Other cross-chain bridges like the Avalanche and Spookyswap have replicated the success of the Binance bridge and accelerated the growth of their respective ecosystems.
Just like how towns expand when they have bridges that facilitate the easy movement of goods in and out, unlocking new customer bases for local businesses and helping the town council to increase its tax revenues, blockchains need to be seamlessly integrated with others to benefit from the network impacts of the free movement of data and value across chains. Examples of EVM-compatible chains include BNB Smart Chain, Avalanche, Fantom, Cardano, Solana, Polygon, etc.
EVM and MetaMask
MetaMask is a popular hot wallet that anyone can access. It’s known for its ease of use and support for desktop and mobile devices. Moreover, you can swap, send, and receive digital assets and collect NFTs from various marketplaces. It runs and supports EVM-compatible networks and ERC20 tokens that live on multiple native chains. MetaMask serves more than 30M monthly active users and is linked to almost 17,000 DeFi protocols and apps.
Apart from its ease of use, crypto users love MetaMask for its anonymity functionality. To start using MetaMask, you download the desktop or mobile app without providing personal information, such as email address, physical address, or identity number. Besides, MetaMask is a non-custodial wallet, implying it doesn’t have a centralized database, nor does it collect user information.
EVM Use Cases
These are the top use cases of EVM:
ERC20 tokens are minted using smart contracts and defined data structures. The structure facilitates the naming, supply and tracking of the tokens. ERC20 tokens have more utility than ERC721 tokens since they are fungible digital currencies that you can easily exchange for other assets. For example, Nexus Mutual, which offers insurance services on smart contracts, uses the NXM ERC20 token to enable its users to make claims and buy coverage.
Another example is Livepeer, a decentralized video streaming platform. It leverages the LPT ERC20 token to reward users for supplying the ecosystem with resources.
Decentralized Exchanges (DEXs)
DEXs facilitate ERC20 token swaps via smart contracts. The contracts allow users to exploit liquidity pools without the involvement of custodians, handing them the title of automated market makers (AMMs). Uniswap and Sushiswap are popular examples of EVM-compatible DEXs.
NFT developers use smart contracts to mint ERC721 tokens with exclusive features across the Ethereum ecosystem. Apart from the art market, gaming projects like the Axie Infinity and Gods Unchained use ERC721 tokens for in-game items and collectables.
A decentralized autonomous organization (DAO) governs the EVM. Basically, a DAO is a community project without a central authority, giving the members total control of the project. Besides being autonomous, DAOs are transparent. Smart contracts stipulate the guidelines and implement policies based on the coded instructions. Since DAO activities are accessible, verifiable, and open to public audit, the participants can learn how the protocol runs.
This article has traversed the Ethereum Virtual Machine, how it works, the differences between state machines and distributed ledgers, and why gas is needed for the EVM. It also dived deep into the importance of EVM compatibility, EVM-compatible blockchains, and EVM use cases. Generally, EVMs are the core pillars of the creation and deployment of smart contracts. A proper understanding of the EVM is important for anyone looking to develop or interact with dApps.
Josiah is a tech evangelist passionate about helping the world understand Blockchain, Crypto, NFT, DeFi, Tokenization, Fintech, and Web3 concepts. His hobbies are listening to music and playing football. Follow the author on Twitter @TechWriting001