Cemre Disli
June 16, 2024
What is EVM?
Ethereum Virtual Machine (EVM) Unveiled: A Deep Dive into Smart Contracts, dApps, and the Future of Web3
A decentralized and open source blockchain Ethereum powers many cryptocurrencies. Built using the ERC-20 (Ethereum Request-for-Comments #20) code system, Ethereum hosts self-executing code snippets called smart contracts. This enables the development of innovative financial instruments like decentralized applications (dApps) and new-generation internet applications (Web3) like unique digital assets (NFTs). Executing these processes is eligible with Ethereum Virtual Machine (EVM). EVM is a fully Turing complete machine that is the computational hub of the blockchain network ecosystem. EVM can be imagined as a decentralized computer that contains applications and runs them.
Main qualities of EVM are decentralized execution, smart contract runtime environment and transaction processing. Firstly, unlike traditional computers, the EVM is spread across a global network of computers (nodes) on the Ethereum blockchain. This ensures that smart contracts are executed consistently and securely. Secondly, The EVM provides the platform for smart contracts, which are self-executing contracts written in code. These contracts can perform various tasks like facilitating transactions or managing digital assets. Finally, The EVM processes transactions on the Ethereum network, including updating account balances and ensuring everything follows the set rules.
In this blog, how EVM works and how it helps smart contracts and dApps will be examined. A basic understanding of common terminology in computer science such as byte, memory, and stack is a must for understanding EVM. It's also helpful to know cryptography / blockchain concepts like hash functions and Merkle Patricia Trie.
What is the Ethereum Virtual Machine?
The EVM as a Decentralized Computer
The EVM isn't a single physical machine, but rather a distributed system – a network of computers working together. So, how does it work? A virtual machine (VM) is essentially a computer within a computer. It is software on a computer that acts like a separate computer within the computer, but it relies on the physical resources of the machine (CPU, RAM). Contrary, the EVM leverages the combined power of all the nodes running the EVM software.
EVM is like a virtual machine that exists everywhere at once. In order to explain that image of a complex calculation requiring many computers to solve can be helpful. Each computer in the Ethereum network acts like a single core of this massive virtual machine. The EVM software coordinates them, and the result (execution of a smart contract) is achieved through their combined effort.
The Value of EVM In the Ethereum Network
The EVM (Ethereum Virtual Machine) plays a central and irreplaceable role in Ethereum by acting as the execution engine for smart contracts. Here's a breakdown of its key functions within the Ethereum ecosystem:
- Smart Contract Runtime Environment: The EVM acts as the runtime environment for smart contracts. These self-executing contracts are written in code (like Solidity) and power a wide range of decentralized applications (dApps) on Ethereum. The EVM ensures that these smart contracts are executed consistently and securely across the entire network.
- Transaction Processing: Whenever a transaction involving a smart contract is submitted on the Ethereum network, the EVM on each node processes it. This includes verifying the transaction's validity, updating account balances, and ensuring everything adheres to the Ethereum protocol.
- Decentralized Execution: Unlike traditional computer environments, the EVM is spread across a global network of computers (nodes) on the Ethereum blockchain. Every node on the Ethereum network runs the EVM software. This means the processing power for executing smart contracts comes from the collective power of all these nodes, creating a decentralized and robust system.
- Deterministic Outcomes: The EVM functions on a set of predetermined rules. This guarantees that all nodes in the network arrive at the same outcome when executing a smart contract, maintaining network integrity.
- Gas System: The EVM utilizes a "gas" system to manage computational resources. Users pay gas fees to execute smart contracts, and the fees incentivize nodes to participate in the network and validate transactions.
- Isolation and Security: The security of the Ethereum network relies heavily on the EVM. The EVM acts like a sandboxed environment for smart contracts. This isolation prevents malicious code from affecting other parts of the system or the underlying network.
In essence, the EVM is the foundation for Ethereum's smart contract functionality. It provides a secure, standardized, and decentralized environment for developers to build innovative applications that are transforming how we interact with digital assets and data.
In another point is that EVM has a crucial feature design which is Turing completeness. Turing completeness comes from Turing machines that are a theoretical model of computation. They are simple but powerful enough to represent any possible computation. A system being Turing-complete implies it can be programmed to solve any problem another Turing-complete system can solve, given enough time and memory. This means that the EVM, with enough resources / fees (gas), can theoretically execute any computation that a traditional computer could, given enough time and memory. It is related to smart contracts in several aspects:
- Universal Problem Solver: Turing completeness allows the EVM to handle a vast array of computations. Smart contracts written on the EVM can perform complex calculations, conditional logic, looping, and data manipulation, essentially mimicking any program a traditional computer could run.
- Unlocking Potential: This theoretical ability to execute any computation opens doors for future advancements in smart contract functionality. Developers can design increasingly sophisticated applications that push the boundaries of what's possible on a blockchain. They can use EVM for various purposes beyond simple transactions, such as creating decentralized marketplaces, running complex financial instruments, or even powering rudimentary games.
Nuances to Consider:
- Limited Resources: While theoretically Turing complete, the EVM operates within a real-world environment with limitations. The gas system ensures resources are used efficiently, but complex computations can still be expensive due to high gas fees.
- Finite State Machine: Technically, the EVM is a "quasi-Turing complete" state machine. “Quasi" because unlike a true Turing machine with infinite memory, the EVM's memory is finite, limited by the blockchain's storage capacity. This might restrict certain computations requiring truly unbounded memory.
So, How Does EVM Works?
EVM manages the blockchain state (balances, code etc.) and executes smart contract instructions. These states are stored in the Merkle Patricia Trie. Also, EVM utilizes a stack-based architecture, which means it relies on a data structure called a stack to handle temporary data during smart contract execution. To understand clearly how EVM works, primarily stack-based architecture must be understood.
The stack operates on a Last-In-First-Out (LIFO) principle and it has limited size, typically 1024 elements. Each element in the stack is a 256-bit word, reflecting Ethereum's native word size. This allows the stack to handle various data types like integers, addresses, and small strings. Moreover, the stack holds the operands (data used in operations) for mathematical and logical operations performed by smart contract code. It also stores the return values from function calls within the smart contract.
Moreover, the EVM has specific opcodes dedicated to manipulating the stack. These opcodes include:
- PUSH: Pushes data onto the top of the stack.
- POP: Removes the top element from the stack.
- SWAP: Swaps the positions of two elements on the stack.
- DUP: Duplicates the top element on the stack.
Benefits of Stack-Based Architecture:
- Simplicity: Stack-based architectures are generally considered simpler to implement and reason about compared to register-based architectures.
- Efficiency: For certain types of operations, stack-based architectures can be more efficient, as data can be accessed directly from the top of the stack.
- Interoperability: The stack-based design makes the EVM more compatible with different programming languages that are also stack-based, simplifying smart contract development.
Limitations of Stack-Based Architecture:
- Limited Memory: The stack has a fixed size, which can be restrictive for complex smart contracts requiring extensive temporary data storage. For such scenarios, smart contracts can utilize the EVM's memory, but memory access is generally slower than stack access.
- Debugging Complexity: Debugging issues related to stack manipulation can be challenging as the stack state is constantly changing during execution.
After explanation of these terms, here are the steps how the EVM works:
- Node Software: To run a full Ethereum node (computer that validates transactions), you need client software like Geth or Nethermind. This software includes EVM.
- Transaction Processing: Nodes store copies of transaction data. The EVM on each node processes these transactions to update the overall state of the blockchain, which is essentially a giant distributed ledger.
- Block Creation: The EVM plays a role in creating new blocks. It sets standards for how the state of the blockchain transitions from one block to the next. These states are stored in a special data structure called a Merkle Patricia Trie, which ensures everyone agrees on the true state of Ethereum.
- Transaction Execution: When a transaction involves a smart contract, the EVM gets to work. It interprets the instructions within the smart contract, which are called Opcodes (a low-level machine language command that specifies the operation to be performed). However, smart contracts are typically written in higher-level languages like Solidity for better readability.
- Bytecode Compilation: Before deployment, a compiler (like the Solidity compiler) translates the human-readable smart contract code into bytecode, the format the EVM understands.
- The Ethereum State Transition Function: It describes how the state of the blockchain changes in response to a set of transactions (T). In simpler terms, it defines how the current state (S) of the blockchain is transformed into a new state (S') after a batch of transactions is executed.
Y(S, T)= S'
- S: Represents the current state of the Ethereum blockchain. This state encompasses the balances of all accounts, the code of smart contracts, and other pertinent data.
- T: Represents a set of transactions that are intended to be applied to the blockchain. These transactions could involve sending ETH, executing smart contracts, or modifying other aspects of the state.
- Y(S, T): Represents the new state of the blockchain resulting from the application of the transactions in T to the initial state S. This new state reflects the updated balances, smart contract execution outcomes, and any other state changes induced by the transactions.
How Does the EVM Give Value?
The deterministic, secure, and efficient design of the EVM allows smart contracts to run consistently and reliably on Ethereum, fostering trust and innovation within the blockchain ecosystem.
It is time to catch a glimpse of real-world use cases in order to consolidate importance of EVM on smart contracts.
Decentralized Finance (DeFi):
- Lending and Borrowing: Smart contracts automate peer-to-peer lending and borrowing, eliminating the need for traditional financial institutions. Users can lend or borrow crypto assets at predetermined interest rates, creating a more accessible and transparent financial system.
- Decentralized Exchanges (DEXs): Smart contracts facilitate trading cryptocurrencies directly between users, bypassing centralized exchanges and offering greater control over assets.
Example: Aave is a popular DeFi protocol on Ethereum that allows users to lend and borrow various crypto assets with automated interest rate adjustments based on supply and demand.
Non-Fungible Tokens (NFTs):
- Ownership and Tracking: Smart contracts can represent unique digital assets like artwork, collectibles, and in-game items as NFTs. They store ownership information on the blockchain, ensuring authenticity and facilitating secure trading.
- Programmable Functionality: Smart contracts can be embedded within NFTs, adding functionalities like automatic royalty payments to creators when their NFTs are resold.
Example: CryptoKitties, one of the first successful NFT projects, uses smart contracts to represent ownership and manage the breeding of virtual cats on the Ethereum blockchain.
Decentralized Autonomous Organizations (DAOs):
- Collective Decision-Making: Smart contracts automate the governance processes of DAOs, allowing members to vote on proposals and manage the organization's treasury through pre-defined rules. This creates a transparent and community-driven decision-making structure.
- Self-Executing Actions: Smart contracts can be programmed to automatically execute actions based on predefined conditions. For example, a DAO could use a smart contract to distribute funds to project contributors upon reaching specific milestones.
Example: Uniswap, a decentralized exchange protocol, operates as a DAO where token holders vote on protocol upgrades and development proposals.
Additionally, the Ethereum Virtual Machine (EVM) can be used on the world of Decentralized Applications (dApps). Here's what the EVM provides to dApps:
- Censorship-Resistant Platforms: dApps built on the EVM are resistant to censorship. No single entity controls the network, so anyone can deploy an application and users can interact with it freely. This might redeem applications whic are restricted in certain regions, fostering innovation in areas like free speech and independent media.
- Disrupting Industries: The potential for disruption goes beyond finance. EVM-based dApps can revolutionize everything from supply chain management to identity verification. Imagine a system where every step of a product's journey is transparently tracked on the blockchain, or a secure platform for storing and managing personal data without relying on a central authority.
The EVM acts as the engine propelling dApps forward. It's a powerful tool with the potential to reshape entire industries and empower individuals in groundbreaking ways. As the technology matures and new applications emerge, we can expect even more disruption and innovation driven by the Ethereum Virtual Machine.
What Can the EVM Bring for the Future?
As a foundational technology, the EVM provides the fertile ground for building a more open, decentralized, secure, and user-centric web experience.
Key features of EVM for Web3:
- Interoperability: EVM-compatible blockchains can communicate and interact with each other. This allows for seamless data exchange and creation of dApps that leverage functionalities from different chains. .
- Security: The EVM inherits the security of the underlying blockchain, typically Ethereum. This ensures a high level of trust and immutability for applications built on top of it. Users can be confident that their transactions and data stored within dApps are secure and tamper-proof.
- Developer Friendliness: The EVM boasts a mature developer ecosystem with established tools and programming languages like Solidity. This low barrier to entry fosters innovation and attracts a wider pool of developers to build the next generation of dApps for Web3.
Industries in which EVM will most possibly show its effects:
Finance: New Economic Models
The EVM enables entirely new economic models to emerge within Web3:
- Tokenization: EVM facilitates the creation and management of tokens that represent assets, access rights, or even governance votes within dApps. This allows for fractional ownership of real-world assets or creation of entirely new digital economies within dApps.
- Decentralized Finance (DeFi): As mentioned earlier, DeFi thrives on the EVM. It empowers individuals to participate in financial activities like lending, borrowing, and trading without relying on traditional institutions. This fosters financial inclusion and potentially unlocks better deals for users.
- Play-to-Earn Gaming: EVM-based games allow players to truly own in-game assets as NFTs and even earn rewards for their participation. This creates a new paradigm in gaming, where players have more control over their digital experiences.
Evolving Governance Structures:
EVM lays the groundwork for novel governance structures within Web3:
- Decentralized Autonomous Organizations (DAOs): DAOs are essentially communities governed by code. The EVM executes smart contracts that define the rules and voting mechanisms for these DAOs. This allows for transparent and democratic decision-making within online communities.
- Community Ownership: EVM-based projects can distribute ownership tokens to their users. These tokens allow users to participate in governance decisions, shaping the future direction of the dApp or protocol.
How Beneficial Is EVM Compatibility with Blockchains?
Throughout the EVM’s domination, other blockchains from Ethereum blockchain increasingly adopt EVM for themselves. There are important reasons for the situation:
- Developer Adoption: Ethereum boasts a vast developer ecosystem. By adopting EVM compatibility, other blockchains can leverage this existing pool of talent. Developers familiar with Ethereum can easily deploy their existing smart contracts or build new ones on these EVM-compatible chains, saving time and resources.
- Interoperability: EVM compatibility fosters a more interconnected blockchain landscape. Tools, wallets, and infrastructure built for Ethereum can often be used seamlessly with EVM-compatible chains. This allows for easier asset movement and interaction between different blockchain ecosystems.
- Easier dApp Migration: EVM compatibility allows developers to port their Ethereum-based dApps to the new chain with relative ease. The core code written in Solidity remains largely unchanged, requiring minimal adjustments to function on the new platform. This significantly reduces development time and costs associated with launching dApps on a different blockchain.
- Faster Transactions and Lower Fees: While Ethereum itself faces scalability challenges, some EVM-compatible chains offer faster transaction processing and lower fees. EVM-compatible chains often prioritize faster transaction processing and lower fees, attracting users frustrated with Ethereum's limitations.
Besides, many blockchains have emerged as prominent players in the EVM-compatible space, each with its own unique features:
- Polygon (MATIC): A well-established scaling solution for Ethereum, Polygon offers faster transactions and lower fees while maintaining EVM compatibility.
- Binance Smart Chain (BNB): Developed by cryptocurrency exchange Binance, BSC offers a high-performance environment for dApps with fast transaction processing and lower fees compared to Ethereum.
- Avalanche (AVAX): Known for its high scalability and security, Avalanche utilizes a unique consensus mechanism to achieve faster transaction finality.
- Fantom (FTM): A fast and scalable blockchain platform offering EVM compatibility and a focus on DeFi applications.
- Optimism (OP): Another Ethereum layer-2 scaling solution, Optimism utilizes optimistic rollups to achieve faster transaction processing while maintaining security on the Ethereum mainnet.
The rise of EVM-compatible blockchains signifies a growing trend towards a more interoperable and developer-friendly blockchain ecosystem. By leveraging the strengths of the EVM, these chains offer exciting options for developers and users alike. As the technology continues to evolve, we can expect even more innovation and competition in the EVM-compatible landscape.
Despite all these strengths, the EVM faces some limitations:
- Scalability Issues: The Ethereum network, where the EVM originated, struggles with scalability. As the number of users and dApps grows, transaction processing times can become slow, and gas fees (the cost to execute a transaction) can surge. This can hinder user experience and limit the network's capacity for growth.
- Gas Fees: Gas fees on the Ethereum network can be quite high, especially during periods of peak traffic. This can be a barrier to entry for new users and projects, as deploying and interacting with dApps becomes expensive. EVM should find a way for cheaper gas fees.
- Limited Functionality: While powerful, the EVM's current design has limitations. It's not optimized for certain tasks, and some developers find it restrictive for building more complex applications.
What Are the Options for Improving the EVM?
The Ethereum community is actively working on solutions to address these limitations. Here are some key efforts:
- Ethereum 2.0 (Eth2): One of the most important problems in the 1.0 system, which was the first version of the Ethereum network, was the scaling problem. A significant upgrade to the Ethereum network, Eth2 aims to address scalability issues by shifting from a Proof-of-Work (PoW) consensus mechanism to Proof-of-Stake (PoS). This is expected to significantly increase transaction throughput and reduce gas fees.
- Layer-2 Scaling Solutions: These are protocols built on top of the Ethereum blockchain that handle transactions off-chain, alleviating the burden on the main network. Polygon and Optimism are prominent examples of layer-2 solutions aiming to improve scalability.
- EVM Improvements: Ongoing research and development efforts are focused on optimizing the EVM itself. This could involve exploring alternative virtual machine designs or implementing features to enhance its functionality for developers.
The future of the EVM is likely to involve a combination of these approaches. By addressing current limitations and fostering ongoing development, the EVM can continue to be a powerful foundation for innovation in the decentralized web
Conclusion
All in all, the Ethereum Virtual Machine (EVM) serves the Ethereum blockchain. It provides a secure and standardized platform for developers to construct the building blocks of Web3, including smart contracts, dApps, and innovative financial instruments. By ensuring consistent execution and fostering a thriving developer ecosystem, the EVM empowers a new era of decentralized applications that redefine ownership, control, and trust online.
Despite of the current limitations of the Ethereum network the EVM's potential extends far beyond. Ongoing efforts to address scalability and enhance functionality position the EVM as a powerful catalyst for future innovation. As the technology matures and new applications emerge, we can expect the EVM to continue shaping the landscape of decentralized applications and usher in a more open, secure, and user-centric web experience. The EVM's journey is just beginning, and its impact on the future of technology has yet to be fully realized.