Forming the backbone of the Ethereum Blockchain, Ethereum Virtual Machine provides developers with a run-time environment to build DApps and other applications.
Bitcoin introduced the world to cryptocurrency in 2008. Still, most crypto-enthusiasts believe Ethereum’s seamless integration of smart contracts in 2015 was the first step towards perfecting Bitcoin’s formula. Ethereum’s smart contracts gave developers an easy way to store on-chain transaction protocols using a programming language. To understand smart contracts, you have to understand the Ethereum Virtual Machine (EVM). It is the state machine that enables smart contract deployment and execution in Ethereum’s decentralized ecosystem. The EVM is also the virtual machine used to power the Hedera Smart Contract service, and optimized for blazing-fast transactions, low fees, and incredible scalability.
Ether (ETH), which is the second largest cryptocurrency in terms of market capitalization, is popular among cryptocurrency investors because of its native ETH token. However, its native Solidity programming language and Ethereum Virtual Machine (EVM) are instrumental in the adulation it receives from the developer community. In fact, the Ethereum blockchain continues to attract decentralized application (DApp) developers due to its flexibility, the vast range of developer tools available and the platform’s large user base.
Forming the core of the blockchain’s architecture, the EVM is the program that executes its application code or smart contracts, as they are called, providing a run-time environment for them that runs on top of the Ethereum network. What’s more, the EVM is Turing-complete and can thus run any program coded in any programming language, thereby allowing developers to easily create custom smart contracts and DApps for the burgeoning Web3 space.
In addition to these important functionalities, EVM has access to all nodes in the network, handles smart contracts execution and effectively handles all transactions on the Ethereum blockchain, making it one of the most powerful virtual machines in existence today.
What is Ethereum Virtual Machine (EVM) and how does it work?
The EVM is a Turing complete virtual machine that can be accessed globally through a participating network node. The EVM’s Turing completeness is measured by the fact it can run any program. Without the EVM, developers wouldn’t be able to implement the numerous dApps (decentralized applications) for which Ethereum is known.
Virtual machines aren’t tied to a specific physical device and have no system interface or hardware. A virtual machine uses the computing power of many participants to provide a runtime environment similar to a physical computer. Unlike physical computers, virtual machines aren’t bound to a single operating system or location. People worldwide can use the machine regardless of where they live or what kind of computer they use.
Conceptualized in 2013 by programmer Vitalik Buterin, the Ethereum network owes its phenomenal success as the preferred blockchain for DApp developers to the Ethereum Virtual Machine (EVM) that was designed by Gavin Wood during his tenure at Ethereum. Written in C++ and using the LLVM Project compiler, EVM is a special state machine that operates continuously and whose immutable operations determine the state of each block in the Ethereum blockchain.
The EVM not only governs what nodes can or cannot do to the distributed ledger maintained by the Ethereum blockchain but also defines the specific rules of changing state from block to block. The latter functionality is what enables the smart contract functionality that Ethereum has come to be known for.
To understand what an Ethereum Virtual Machine does, one needs to look at each of the different functions it serves in ensuring the smooth operation of the Ethereum network. For every input that it receives, the EVM produces an output that is deterministic in nature and follows a mathematical function in the simplest sense.
Operating like a stack machine that pushes transient values to and from a pushdown stack, the EVM has a depth of 1024 items, with each of them being a 256-bit word. It also maintains a temporary memory in the form of a byte array, which changes between two transactions on the Ethereum blockchain. Smart contract codes that have been compiled are executed by the EVM in the form of a collection of 140 standard opcodes, while other blockchain-specific stack operations are also implemented by it.
Thus, the EVM has a machine state that is volatile by nature during the processing of any transaction and a global or world state that contains information regarding the different accounts maintained on the Ethereum blockchain. All actions are governed by the Ethereum Virtual Machine, EVM code, which in itself has gone through several iterations since the launch of the Ethereum network in 2015, leading to the existence of different implementations of the EVM currently in use.
In fact, the EVM is responsible for maintaining a level of abstraction between thousands of Ethereum nodes and the executing code, acting as a function that delivers consistent results without divulging many details to clients or nodes.
What is the purpose of the Ethereum Virtual Machine (EVM)?
The EVM has been reliably powering all applications running on the Ethereum network without any major downtime reported. For developers, the Ethereum Virtual Machine acts as the overarching program that runs smaller executable programs which are known as smart contracts in Ethereum, while providing them the freedom to write these smart contracts in a variety of programming languages including Solidity, Vyper, Python and Yul, among others.
Due to this flexibility offered by the Ethereum Virtual Machine, the Ethereum blockchain has spawned thousands of DApps in the decentralized finance (DeFi) and nonfungible token (NFT) space. Each of these DApps and the smart contracts that they are made of are converted into bytecode that is fed into the EVM and distributed among all nodes in the Ethereum network. When a smart contract is deployed, the EVM is responsible for communicating with all nodes and effecting state changes when a consensus has been arrived at.
It can be said that the EVM is inserted inside every Ethereum node to execute smart contracts using bytecode instead of the base programming language, thus isolating the physical host computer from the machine code on which Ethereum runs.
Benefits of Ethereum Virtual Machine (EVM)
On account of the way in which the EVM operates, developers can execute code without worrying about its impact on the rest of the network or the possibility of it playing truant with data or personal files hosted on any of the node computers.
Additionally, they can run complex smart contracts on different computing environments with distributed consensus. This ensures that the failure of a single node does not have any negative impact on the running of the DApp or smart contract, since the EVM code remains the same across all nodes. Moreover, since account data is maintained at a global level in the EVM, developers find it perfect for writing custom smart contract code and creating distinct DApps that can access this global data set and produce reliable outputs.
The sanctity of the outcome is what makes the Ethereum Virtual Machine, in particular, and the Ethereum blockchain in general well-suited to the sustainable expansion of the DApps and smart contract Ethereum ecosystem. Add to this the library of standard codes available for developers to choose from, an increasing number of EVM-compatible layer-2 blockchains and a large number of potential EVM use cases possible, and it is easy to see why the EVM is the preferred platform for Web3 development.
Drawbacks of Ethereum Virtual Machine (EVM)
Despite the many advantages offered by the Ethereum Virtual Machine, there are certain downsides that need to be considered by developers and entrepreneurs building on Ethereum. The most important of these is the high transaction fees or gas costs associated with running a smart contract on the Ethereum network.
Paid in ETH, these fees vary depending on the complexity of the contract and the network congestion at the time of execution, making it imperative for developers and entrepreneurs to price their services accordingly. Additionally, since Solidity is the most preferred language for coding on the EVM, it does imply that developers need to have adequate experience with it and possess a modicum of technical expertise to create efficient smart contracts by using it.
The latter is important since any additional computation requirement will lead to higher gas costs and ultimately prove detrimental to the project’s success. If developers choose to code using other languages, they need to be careful in resolving any inherent repetitions in the code since the EVM will proceed to compile them anyway. While upgrading smart contracts is possible at a later stage, it comes with security risks associated with creating an intermediary smart contract that references the address of the original smart contract.
The future of EVMs
Notwithstanding the revolutionary changes brought about by the EVM to the blockchain ecosystem, this technology for reading and executing code is being improved upon by a number of blockchain projects.
With cross-chain interoperability being the most important aspect for developers, many EVM-compatible blockchains have propped up, with most offering lower gas and faster transaction speeds than the Ethereum protocol. As a result, these blockchains are now able to interact with Ethereum users seamlessly and are facilitating fund transfers to their own networks using blockchain bridges.
However, with the Ethereum protocol successfully completing the Merge in September 2022, the next target is to shift from EVM to Ethereum WebAssembly (eWASM). Designed to be highly modular and platform-independent, eWASM is being touted as the next game-changer for the Ethereum protocol and could motivate other blockchains to employ this run-time environment for smart contracts as well. However, whether eWASMs will replace the EVM as the most trusted mechanism for smart contracts is a question that only time will answer.
Is the EVM decentralized?
The EVM could be described as “mostly decentralized.” Countless individuals worldwide run nodes, but the majority of Ethereum nodes are hosted on centralized servers like Amazon Web Services. If the owners shut down the nodes, it could damage the network. Still, over time, as new computers participate in the Ethereum network by running nodes, the ecosystem becomes more decentralized.
How is data stored?
The Ethereum protocol uses two distinct data types – permanent data and ephemeral data. Permanent data, such as a transaction, is recorded in Ethereum’s tree-like data structure and will never be altered. Ephemeral data, such as a wallet’s balance, is recorded and changed in response to new transactions.
EVM’s opcodes use contract memory to retrieve data. Contract state memory is stored at the contract address and is not persistent. A variable’s position in a smart contract’s storage array is determined by its order in the code. If a given variable is 256 bits or less, the EVM will try to fit multiple variables in the space. When a contract inherits another contract, the storage variables of the base contract are stored in the first slots in the order of inheritance.
Whereas contract memory is impermanent, contract storage is stored indefinitely. Contract storage is like a public database where values can be read externally without the need to send a transaction. Still, contract storage is expensive compared to contract state memory.
Using the Ethereum Learning Machine
Ethereum’s EVM has allowed the project to achieve its goal of “decentralizing everything.”
The EVM is complex in its functionality but accessible to new developers, leading to many decentralized applications. Still, newer projects and blockchains continue to improve upon the EVM model. For example, Hedera recently announced smart contract 2.0 availability on the Hedera mainnet.
Hedera’s investment in the EVM will lead to numerous benefits for developers, including low gas fees, fast transaction finality, carbon-negative operations, and leaderless architecture. Additionally, because new blockchain developers use the EVM 30 percent of the time, Hedera’s EVM compatibility will give entry-level Solidity developers a new, less expensive way to develop and deploy dApps.