# Explaining core system Ethereum Virtual Machine #### What is EVM (Ethereum Virtual Machine)? 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. ![](https://i.imgur.com/8o8dKbn.jpg) 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](https://ethervm.io/). Internally, EVM converts “EVM bytecode” to “Ethereum Virtual Machine Opcodes” to execute specific tasks. A developer also can directly write opcode with [Solidity Assembly](https://docs.soliditylang.org/en/develop/assembly.html). 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](https://medium.com/@eiki1212/what-is-ethereum-gas-simple-explanation-2f0ae62ed69c) 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](http://paper.gavwood.com/) like below. ![](https://i.imgur.com/HZSYDu0.png) 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 References [What Is An Ethereum (ETH) Virtual Machine (EVM)?](https://xbt.net/blog/ethereum-blog/what-is-an-ethereum-eth-virtual-machine-evm/) [What is Ethereum Gas? [The Most Comprehensive Step-By-Step Guide Ever!]](https://blockgeeks.com/guides/ethereum-gas/) [Running an Ethereum Node](https://blockgeeks.com/guides/ethereum-gas/)