What is EVM(Ethereum Virtual Machine)?
Tags: Evm, Abi, Solidity, Ethereum, Blockchain

Explaining core system Ethereum Virtual Machine

Introduction

This article explains EVM(Ethereum Virtual Machine) and related terms in plain English. If you are a beginner of Ethereum, this article might help you to understand what EVM is and surrounding terms(The article is not for an expert. If you are looking for something deep dive, please refer the other sources like here). 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 Ethereum blockchain. It allows smart contract code to run by compiling to EVM bytecode. EVM plays a core role in Ethereum blockchain to ensure a trustless mechanism without having any central administrator. EVM keeps each node systemically isolated from others in order to avoid security risks. Even if one node is compromised, it does not influence any other nodes and blockchain network. EVM ensures Ethereum blockchain to be secured.

As called world computer, Ethereum can solve more complex computational logics differently from Bitcoin blockchain(it only can 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 smart contract(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 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 need to develop respective compilers for each operating system. EVM makes Ethereum ecosystem compatible and efficient.

EVM bytecode

Here, I’ll clearly break down two terms: “bytecode” and “EVM bytecode”. In computer science, “bytecode” is a computer language which is compiled from source code and run on 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 instruction code for computers. We can tell hardware directly what it should do. It is a portion of machine language instruction. Ethereum has original opcode system, called Ethereum Virtual Machine Opcodes. Internally, EVM converts “EVM bytecode” to “Ethereum Virtual Machine Opcodes” to execute specific tasks. A developer also can 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), which is defined as data structure and functions with JSON array format, to interact with a smart contract from external application. It enables application-to-contract and contract-to-contract interaction. When developers make their wallet or DApp that interact with the smart contract, the application would call Contract ABI.

Solidity

Solidity is a high-level programming language on which executes EVM. It needs to be compiled to bytecode to be executed on EVM with compiler such as solc. It is designed for Smart Contract and the syntax is based on ECMAScript so that similar to JavaScript. But it is not only influenced by JavaScript but also C++, Python, and PowerShell. Solidity creates “Contract” as a base frame like “Class” in object-oriented programming. All programs start from “Contract” as object-oriented programming does from “Class”. As of today, Solidity is the primary language on Ethereum as well as 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 need to pay Gas as a fee. Each and every line of code in Solidity requires a certain amount of gas to be executed. Amount of Gas in each instruction is clearly defined in Ethereum Yellow Paper like below.

Ethereum Gas system plays a very important role to incentivize miners. Ethereum blockchain is run by someone who runs EVM by using their own computer resources. Therefore, the user needs to pay for their computation effort. The reason why they are not paid with ETH is to hedge from 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 Ethereum blockchain. Here, I’ll explain a bit more deeply what Ethereum Client is by starting a definition of “Client”.

In computer science, a 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 a software/hardware that connects to other clients in a peer-to-peer way. The client is also called “node” in a similar way. However, “client” refers to more like software installed on hardware and “Node” to 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 transaction to validate. On the other hand, the lightweight client downloads only blockchain header in order to save disk space. Below the functions of each node are listed.

Full Node Client

Stores the full 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 state can be derived from a full node.

Once fully synced, stores all state moving forward similar to archive nodes (more below).

Lightweight Client

Stores the header chain and requests everything else on demand.

Can verify the validity of the data against the state roots in the block headers.

cites: https://docs.ethhub.io/using-ethereum/running-an-ethereum-node/

Conclusion

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

References

What Is An Ethereum (ETH) Virtual Machine (EVM)?

What is Ethereum Gas? [The Most Comprehensive Step-By-Step Guide Ever!]

Running an Ethereum Node

A Deep Dive into the Ethereum Virtual Machine (EVM) — part 2: Memory and Storage