What is EVM(Ethereum Virtual Machine)?

Eiki Takeuchi
5 min readJun 6, 2019

Explaining the core system of the Ethereum Virtual Machine

Introduction

This article explains EVM(Ethereum Virtual Machine) and related terms in plain English. If you are a beginner in Ethereum, this article might help you understand what EVM is and its surrounding terms. (The article is for someone other than an expert. Below is the index(scope) of this article.

■ What is EVM?
■ Why do we need EVM?
■ What is EVM bytecode?
■ What is ABI?
■ What is Solidity?
■ Gas and EVM
■ What is the Client?

What is EVM?

EVM is a runtime environment for the Ethereum blockchain. It allows intelligent contract code to run by compiling to EVM bytecode. EVM plays a core role in the Ethereum blockchain to ensure a trustless mechanism without having any central administrator. EVM keeps each node systemically isolated from others to avoid security risks. Even if one node is compromised, it does not influence any other nodes and blockchain network. EVM ensures that the Ethereum blockchain is secured.

As called a world computer, Ethereum can solve more complex computational logics differently from Bitcoin blockchain(it can only simply transfer money). EVM reads the code, calculates Gas, executes, and mines to record to Block. Again, it plays a core and essential role in Ethereum.

Why do we need EVM?

EVM enables intelligent contracts (Solidity) to be executed on any computer(OS agnostic). EVM is installed on the computer(operating system) and works as a middle layer between a smart contract and an operating system. Once Solidity code is compiled to bytecode, EVM can read to execute. If you are a developer, JVM(Java Virtual Machine) might let you understand more easily.

If we do not have EVM, we must develop respective compilers for each operating system. EVM makes the Ethereum ecosystem compatible and efficient.

EVM bytecode

Here, I’ll break down two terms: “bytecode” and “EVM bytecode.” In computer science, “bytecode” is a computer language compiled from source code and run on a Virtual Machine. Bytecode is not human-readable but computer-readable.

[Flow]
Source Code -> Bytecode -> Machine Code
Source Code: File written in programming language such as Java, Solidity.
Bytecode: Compiled from source code and run on Virtual Machine such as JVM, EVM
Machine Code: Code that only operating system can read. Bytecode is converted to Machine Code and finally executed.

Once you understand what bytecode is, it is easy to understand what “EVM bytecode” is. EVM byte code is compiled from Solidity and executed on EVM.

What is Opcodes?

In computer science, Opcode (operation code) is a set of computer instruction codes. We can tell hardware directly what it should do. It is a portion of machine language instruction. Ethereum has an original opcode system called Ethereum Virtual Machine Opcodes. Internally, EVM converts “EVM bytecode” to “Ethereum Virtual Machine Opcodes” to execute specific tasks. A developer can also directly write Opcode with Solidity Assembly. But it might be a lot harder to understand than Solidity.

Contract ABI

ABI(Application Binary Interface) is an interface between two program modules, often between an operating system and user programs. In Ethereum, Contract ABI is a standard(or scheme) defined as data structure and functions with JSON array format to interact with a smart contract from an external application. It enables application-to-contract and contract-to-contract interaction. When developers make their wallet or DApp that interacts with the smart contract, the application would call Contract ABI.

Solidity

Solidity is a high-level programming language that executes EVM. It needs to be compiled to bytecode to be executed on EVM with a compiler such as Solc. It is designed for smart contracts, and the syntax is based on ECMAScript, similar to JavaScript. But it is not only influenced by JavaScript but also C++, Python, and PowerShell. Solidity creates a “Contract” as a base frame, like a “Class” in object-oriented programming. All programs start from “Contract” as object-oriented programming does from “Class.” Today, Solidity is the primary language on Ethereum and other blockchain platforms such as Monax and Hyperledger Burrow.

Gas and EVM

Gas in Ethereum is the fuel that is consumed for computation. Whenever the users execute a smart contract on Ethereum, they must pay Gas as a fee. Every line of code in Solidity requires a certain amount of Gas to be executed. The amount of Gas in each instruction is clearly defined in Ethereum Yellow Paper below.

ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER

Ethereum Gas system plays a vital role in incentivizing miners. The Ethereum blockchain is run by someone who runs EVM using their computer resources. Therefore, the user needs to pay for their computation effort. The reason why they are not paid with ETH is to hedge against market volatility. If you want to know more details, please refer here.

What is Client

Ethereum Client is a software that implements EVM. It has a variety of implementations, such as Geth(Go-Ethereum) and Parity(Rust implementation). It provides not only EVM but also other functions, such as a command-line interface to interact with the Ethereum blockchain. Here, I’ll explain more deeply what Ethereum Client is by starting with a definition of “Client.”

In computer science, the term “client” means software/hardware which connects to the server. The Client uses the resources and services that the server provides. In a blockchain, a client is software/hardware that connects to other clients peer-to-peer. The Client is also called a “node” in a similar way. However, “client” refers to more software installed on hardware and “Node” to the whole physical computer, including hardware and software(“client”).

The Client has two types: full node client and lightweight Client. Full node client downloads all blockchain data on disk and receives blocks and transactions to validate. On the other hand, the lightweight Client downloads only the blockchain header to save disk space. The functions of each node are listed below.

Full Node Client

  • Stores the complete blockchain data available on disk and can serve the network with any data on request.
  • Receives new transactions and blocks while participating in block validation.
  • Verifies all blocks and states.
  • Stores recent state only for more efficient initial sync.
  • All states can be derived from a full node.
  • Once fully synced, stores all states moving forward, similar to archive nodes (more below).

Lightweight Client

  • Stores the header chain and requests everything else on demand.
  • The validity of the data can be verified against the state roots in the block headers.

Conclusion

Here, I explained EVM and the terms surrounding it (bytecode, ABI, Solidity, Gas, and Client). As EVM is a core system in the Ethereum blockchain, we need to know the surrounding terms to understand how EVM works. If you want to delve more deeply, please refer to the following references. Hopefully, this article helps you to understand EVM as a first step.

--

--

Eiki Takeuchi

I'm Eiki Takeuchi. I work as a Scrum Master/Agile coach. I regularly write about Scrum, Agile, and leadership on Medium. X: https://x.com/eiki234