Skip links

Table of Contents

What is an Ethereum Virtual Machine (EVM) and How It Works?

What is a Virtual Machine (VM)?

A virtual machine (VM) is a software program that creates a virtual computer within your physical computer. This virtual computer can run its own operating system and software, and it is isolated from the rest of your computer. This makes VMs useful for a variety of purposes, such as:

  • Running multiple operating systems on the same computer
  • Testing software in a safe environment
  • Isolating malware from the rest of your computer

What is The Ethereum Virtual Machine Definition?

Did you know that the Ethereum Virtual Machine was originally designed to be a simple machine that could only execute simple transactions?

However, over time, it has evolved into a powerful tool that can be used to execute complex applications.The Ethereum Virtual Machine is a special type of VM that is used to run smart contracts on the Ethereum blockchain. Smart contracts are self-executing agreements that are stored on the blockchain. They can be used to automate a wide variety of tasks, such as:

  • Transferring money between accounts
  • Creating tokens
  • Managing ownership of assets

The Ethereum Virtual Machine is a Turing-complete machine, which means that it can theoretically execute any program. However, the EVM is also limited by the amount of gas that is available for each transaction. Gas is a unit of measurement that is used to track the computational resources used by each operation.

How the Ethereum Virtual Machine Works?

The Ethereum Virtual Machine is a stack-based virtual machine that runs on every Ethereum node. It executes smart contracts, which are self-executing agreements between two parties. The EVM uses a stack to store the state of the program and to perform computations. It also uses gas to track the amount of computational resources used by each transaction. The Ethereum Virtual Machine first validates the code of each transaction before it is executed. If the code is valid, it then executes the transaction, which may involve updating the state of the blockchain or sending funds to another account.

The EVM uses bytecodes and opcodes to execute smart contracts. Bytecodes are the instructions that the Ethereum Virtual Machine executes, and opcodes are the codes that represent these instructions. There are over 140 opcodes in the EVM, each of which performs a specific operation.

Here is an example of how bytecodes and opcodes work. The following bytecode is the instruction to add two numbers together:

0x01 0x02 0x03 0x00

This bytecode is interpreted by the EVM as follows:

  • 0x01 is the opcode for the ADD instruction.
  • 0x02 is the first operand.
  • 0x03 is the second operand.
  • 0x00 is the return value.

The EVM will first load the first operand (0x02) onto the stack. Then, it will load the second operand (0x03) onto the stack. Finally, it will execute the ADD instruction, which will add the two operands together and store the result (0x05) on the stack.

Few examples of EVM Opcodes:

OpcodeHex CodeDescription
ADD0x01Binary operation that adds the top two items from the stack and pushes the result back onto the stack.
MUL0x02Binary operation that multiplies the top two stack items and pushes the result back onto the stack.
SUB0x03Binary operation that subtracts the second stack item from the first (top two items on the stack) and pushes the result back onto the stack.
DIV0x04Binary operation that divides the first stack item by the second and pushes the quotient back onto the stack. If it is a division by zero, it pushes zero.
JUMP0x56Unconditional jump operation that replaces the program counter with the top item from the stack. The next opcode is taken from that position in the code.
JUMPI0x57Conditional jump operation that takes two arguments from the stack. If the first item is non-zero, it sets the program counter to the value of the second item. Otherwise, no effect.
PUSH1, PUSH320x60 – 0x7fPlaces 1 to 32 bytes item on stack. For instance, PUSH1 might place a single byte onto the stack, while PUSH32 would place 32 bytes onto the stack.
CALL0xf1Executes a new message call and sends the output data from the executed contract back to the current one. It takes seven arguments from the stack.
EVM opcodes examples

The EVM will continue to execute bytecodes in this way until the entire smart contract has been executed. The EVM is a complex piece of software, but it is essential to the functioning of the Ethereum network. It allows Ethereum to be a platform for decentralized applications, and it is responsible for ensuring that the Ethereum network is secure and reliable.

Now that we have gained some insights into the execution of bytecode by the EVM, let’s proceed to grasp the concept of the Ethereum state transition function.

The Ethereum State Transition Function

The Ethereum State Transition Function (STF) is a mathematical function that describes how the state of the Ethereum blockchain changes over time. The STF takes two inputs: the current state of the blockchain and a transaction. The STF then outputs the new state of the blockchain after the transaction has been executed.

The mathematical function for the STF is as follows:

STF(S, T) = S’

Where:

  • S is the current state of the blockchain
  • T is a transaction
  • S’ is the new state of the blockchain after the transaction has been executed

The STF is a key part of the Ethereum blockchain. It is responsible for ensuring that the blockchain is secure and reliable, and it allows Ethereum to be a platform for decentralized applications.

Ethereum Virtual Machine Definition evm
A diagram of the Ethereum Virtual Machine (EVM). This would help to illustrate how it works and how it is connected to the Ethereum blockchain.

What are the Benefits and Drawbacks of the EVM?

BenefitsDrawbacks
Versatile and Programmable:
Enables complex decentralized applications and smart contracts with various functionalities.
Gas Limitations:
The gas mechanism can restrict the execution of resource-intensive tasks, making some operations costly.
Decentralization:Operates on a decentralized blockchain network, ensuring trust and transparency.Security Risks:Vulnerabilities in smart contracts and coding errors can lead to security breaches and financial losses.
Transparency and Auditing:All transactions and smart contract executions are publicly recorded, enabling easy auditing and verification.Scalability Challenges:As the network grows, the EVM’s scalability may become a challenge, leading to slower transaction processing.
Interoperability:Allows integration with other blockchains and protocols, promoting cross-chain interactions.Upgrade and Fork Compatibility:Hard forks or upgrades may introduce incompatibility with older versions of smart contracts, creating disruptions.
Benefits and drawbacks of EVM

Overall, the EVM is a powerful and versatile tool that has the potential to revolutionize the way we interact with the internet. However, it is important to be aware of its limitations and risks before using it.

Here are some additional tips for using the EVM safely and securely:

  • Use a secure programming language: Solidity is a popular and well-respected programming language for creating smart contracts. It is designed to be secure and resistant to attack.
  • Review the code of the EVM before using it: It is open source, which means that you can review its code before using it. This will help you to understand how it works and to identify any potential security risks.
  • Stay up-to-date with the latest EVM updates and security best practices: The EVM is constantly being updated with new features and security improvements. It is important to stay up-to-date with these changes so that you can use it safely.
  • Use gas-efficient code: Gas fees are used to pay for the computational resources used by each transaction. Gas fees can be expensive, so it is important to use gas-efficient code when creating smart contracts.
  • Use safe coding practices: There are a number of safe coding practices that can help to mitigate security risks. These practices include using secure functions, avoiding reentrancy attacks, and testing your smart contracts thoroughly before deploying them.
  • Use a security audit: If you are creating a complex smart contract, you may want to consider having it audited by a security expert. This can help to identify any potential security risks before they are exploited.

By following these tips, you can help to ensure that your use of the EVM is safe and secure.

What are some examples of how the EVM is being used in real-world applications?

  • Decentralized finance (DeFi): DeFi is a rapidly growing ecosystem of financial applications that are built on top of the Ethereum blockchain. These applications allow users to lend, borrow, and trade assets without the need for a central authority. Some of the most popular DeFi applications include MakerDAO, Compound, and Uniswap.
  • Non-fungible tokens (NFTs): NFTs are a type of digital asset that is unique and cannot be replaced. They are often used to represent ownership of digital artworks, collectibles, and other items. Some of the most popular NFT platforms include OpenSea, Rarible, and Foundation.
  • Gaming: The EVM is also being used to power a new generation of decentralized games. These games are built on top of the Ethereum blockchain and allow players to own their in-game assets. Some of the most popular decentralized games include Axie Infinity, The Sandbox, and Gods Unchained.
  • Supply chain management: The EVM can also be used to improve the efficiency and transparency of supply chain management. For example, it can be used to track the movement of goods and to verify the authenticity of products. Some of the companies that are using the EVM for supply chain management include Walmart, IBM, and SAP.

These are just a few examples of how the EVM is being used in real-world applications. As the EVM continues to evolve, it is likely to be used in even more innovative and creative ways.

What are Future Developments and Upgrades of the EVM?

The Ethereum Virtual Machine (EVM) is constantly evolving, and there are a number of future developments and updates that are being planned. Some of the most notable include:

  • EVM Opcodes: The EVM currently has a set of 140 opcodes that can be used to write code. However, there are a number of new opcodes that are being proposed that would allow developers to write more complex and efficient code.
  • EVM Gas Fees: Gas fees are the fees that users pay to execute code on the EVM. They are currently based on the amount of code that is executed, but there are proposals to change the gas fee system to make it more efficient and fair.
  • EVM Security: The EVM is a secure platform, but there are always potential security risks. Developers are working to improve the security of the EVM by implementing new security features and by educating developers on how to write secure code.
  • EVM Scalability: The EVM is a scalable platform, but it can still experience congestion during periods of high demand. Developers are working on ways to improve the scalability of the EVM by implementing new scaling solutions, such as sharding and rollups.

These are just a few of the future developments and updates that are planned for the EVM. As the EVM continues to evolve, it is likely to become even more powerful and versatile, and it will continue to play a major role in the development of decentralized applications.

Final Thoughts

You now have a deeper understanding of what is an EVM (Ethereum Virtual Machine) is and how it works. Have any further questions, ideas to share, or perhaps want to showcase what you’ve learned? Feel free to reach out to us via Twitter.

Frequently asked questions

What is the Ethereum Virtual Machine (EVM)?

  • The EVM is a runtime environment for smart contracts in Ethereum, completely isolated for security.

How does EVM work in the Ethereum platform?

  • EVM executes operations on every node in the network for consensus and correctness.

What is gas in the context of the EVM?

  • Gas is the execution fee paid for transactions or smart contracts processing on Ethereum.

How is the EVM related to smart contracts?

  • EVM provides the environment to execute Ethereum smart contracts written in languages like Solidity.

What languages can you use to write smart contracts for the EVM?

  • Languages like Solidity, Serpent, LLL, and Vyper can be used for Ethereum smart contracts.

Can the EVM run applications beyond finance?

  • Yes, Ethereum’s architecture allows for diverse decentralized applications (DApps) including games, social networking, etc.

Are there alternatives to the EVM in the blockchain world?

  • Yes, platforms like Bitcoin and NEO have their own versions of a virtual machine.

Do all Ethereum nodes run an EVM?

  • Yes, all full nodes on the Ethereum network run an EVM instance for consensus.

What is Ethereum 2.0 and how does it impact the EVM?

  • Ethereum 2.0, or Eth2, is an upgrade aiming to increase transaction speed and efficiency, potentially affecting the EVM.

Can smart contracts be executed on other virtual machines?

  • Yes, platforms like Neo, EOS, and Tron support smart contracts with their own virtual machines

Metana Guarantees a Job 💼

Plus Risk Free 2-Week Refund Policy ✨

You’re guaranteed a new job in web3—or you’ll get a full tuition refund. We also offer a hassle-free two-week refund policy. If you’re not satisfied with your purchase for any reason, you can request a refund, no questions asked.

Web3 Solidity Bootcamp

The most advanced Solidity curriculum on the internet!

Full Stack Web3 Beginner Bootcamp

Learn foundational principles while gaining hands-on experience with Ethereum, DeFi, and Solidity.

You may also like

Metana Guarantees a Job 💼

Plus Risk Free 2-Week Refund Policy

You’re guaranteed a new job in web3—or you’ll get a full tuition refund. We also offer a hassle-free two-week refund policy. If you’re not satisfied with your purchase for any reason, you can request a refund, no questions asked.

Web3 Solidity Bootcamp

The most advanced Solidity curriculum on the internet

Full Stack Web3 Beginner Bootcamp

Learn foundational principles while gaining hands-on experience with Ethereum, DeFi, and Solidity.

Learn foundational principles while gaining hands-on experience with Ethereum, DeFi, and Solidity.

Events by Metana

Dive into the exciting world of Web3 with us as we explore cutting-edge technical topics, provide valuable insights into the job market landscape, and offer guidance on securing lucrative positions in Web3.

Subscribe to Lettercamp

We help you land your dream job! Subscribe to find out how

Start Your Application

Secure your spot now. Spots are limited, and we accept qualified applicants on a first come, first served basis..

Career Track(Required)

The application is free and takes just 3 minutes to complete.

What is included in the course?

Expert-curated curriculum

Weekly 1:1 video calls with your mentor

Weekly group mentoring calls

On-demand mentor support

Portfolio reviews by Design hiring managers

Resume & LinkedIn profile reviews

Active online student community

1:1 and group career coaching calls

Access to our employer network

Job Guarantee