Ethereum Virtual Machine (EVM) Explanation

Benjamin
Benjamin
Sep 1, 2018 · 5 min read

Ethereum virtual machine explanation

The Ethereum virtual machine can be considered a quasi-turing machine. Turing integrity refers to the data manipulation rules system, named after the Turing machine creator Alan Turing. Programming languages ​​and central processing units (CPUs) are good examples of systems for accessing and modifying data. If these rules can be used to simulate Turing’s hypothetical computer, the rule is considered “Turing complete.” The Turing Complete System can mathematically demonstrate the ability to perform any possible calculation or computer program. In other words, the Turing Completion Machine can mathematically solve any problems you provide to it. Ethereum virtual machines are only quasi-turing, because the calculations performed by the machine are constrained by gases, which limits the number of calculations that can be done.

Gas and EVM bytecode

In Ethereum, natural gas can be considered equivalent to a fee. Each transaction executed on the Ethereum network requires an additional fee, which is paid in the form of natural gas. The concept of natural gas in Ethereum can be broken down into two: natural gas and natural gas prices

Gas — Used as a tool to measure the cost of performing a specific calculation.
Natural Gas Price — This is the amount of Ether that an individual is willing to spend on each unit of natural gas. Natural gas prices are usually measured in ‘Wei’, which is the smallest Ether unit, where 10 ^ 18 Wei represents an ether.
Therefore, in order for an individual to execute a transaction on the Ethereuem network, the sender must set the natural gas limit price and natural gas price attached to the transaction. If the sender does not have the gas required to perform the transaction, it is said to “deplete the gas” and is ineffective.

Gas can limit the number of calculations that an Ethereum virtual machine can perform in several ways, including:

  • The blocks mined in the Ethereum blockchain are subject to gas restrictions, so the amount of natural gas used in all exchanges within the block cannot exceed a certain amount.
  • Natural gas prices are natural gas prices, and whether or not the natural gas limit is removed and the machine is theoretically able to solve any problems it receives, some transactions may be too complex and prove to be economically impractical.

The Ethereum virtual machine has its own programming language called “EVM bytecode.” When the code is written in a more advanced programming language (such as Ethereum’s contract-oriented language Solidity), this code can be compiled into EVM bytecode so that the Ethereum virtual machine can understand what has been written.

Transaction-based state machine

The Ethereum virtual machine is an important element of Ethereum construction because it handles internal states and calculations on the network. The machine must also process account information related to address, balance, current gasoline price, and block information.

As mentioned earlier, the Ethereum virtual machine handles the internal state of the network. The machine must track the status of many components to successfully support transactions. This is important because the state of these components really drives the change in the overall blockchain. This is why Ethereum is often described as a transaction-based state machine. A brief explanation of the “state” concept can be useful before we look at the various components that the Ethereum virtual machine must track.

In the field of computer science, a state machine refers to a machine that is capable of reading a series of inputs and transitioning to a new state based on those inputs. Similarly, the state machine of Ethereum is the same. The starting point is blank before any input is made, or before any transaction on the Ethereum is executed. When performing transactions on the network, any point during this time represents the current state of Ethereum. In order to perform a state transition, the transaction must be valid, and the transaction is considered valid when the transaction is successfully validated by the mining process.

This mining process is known as Workload Proof (PoW), which affects nodes on the Ethereum network consuming computer resources to receive privileges to create valid transaction blocks and add them to the blockchain. When miners can provide mathematical “evidence”, miners can add blocks to the blockchain. The valid evidence sends the block a valid signal to the network, and the block is accepted and added to the chain. The miner who successfully validates the block will receive Ether’s local asset Ether in exchange for consuming computing resources during the PoW process.

The components that the Ethereum virtual machine must track include: account status, world status, storage status, block information, and runtime environment information.

Account status

Ethereum can be thought of as a small number of small accounts that can interact with each other (this may be because of Ethereum’s messaging framework. Ethereum’s accounts can be broken down into: externally owned accounts and contracted accounts.

  • External accounts — These accounts are controlled by a private key and have no code associated with them.
  • Contract Accounts — These accounts are controlled by contract codes and have codes associated with them.

An externally owned account can send messages to other externally owned accounts or other contracted accounts. This is done by digitally signing the transaction with a private key. Communication between two external accounts can be enjoyed simply. The value transfer of external accounts and contract accounts has the effect of executing contract account codes. This enables the contract account to perform the actions listed in the code, including: token transfer, creation of new tokens, and more. It is important to note that contract accounts cannot initiate new transactions (with external accounts) on their own. Contract accounts are passive because they can only participate in transactions that respond to other transactions they receive, either from externally owned accounts or from other contract accounts.

There are four elements including account status, including:

  • Nonce — If the account is externally owned, this value represents the number of transactions sent from the address of the account. However, if it is a contract account, nonce indicates the number of contracts created by the account.
  • Balance — The number of Weis owned by the account address.
  • CodeHash — This is the immutable hash of the Ethereum virtual machine code for the corresponding account.

World countries
The global state of Ethereum actually includes a mapping between the 160-bit address identifier and the account status. All of this mapping information is stored in a data structure called the Merkle Patricia Tree. The data structure consists of a set of nodes with:

  • A large number of leaf nodes at the bottom of the tree hold the underlying data.
  • A set of intermediate nodes, where each node is a hash of two child nodes.
  • A single root hash is also formed by the hash of the first two child nodes, representing the top of the tree structure.

Storage status

This is account-specific status information maintained while running on the Ethereum virtual machine.

Block information

These are the state values ​​required to support the transaction, and the block information includes:

  • Blockhash — the hash of the most recently completed block
  • Coinbase — the address of the recipient
  • Timestamp — the timestamp of the current block
  • Number — the number of the current block
  • Difficulty — the difficulty of the current block
  • Gaslimit — gas limit attached to the current block

Runtime environment information

This is information for executing transactions, including:

  • Natural gas price — current natural gas price specified by the transaction promoter
  • Codesize — the size of the transaction code base
  • Caller — the address of the account that executed the transaction
  • Source — the address of the original sender of the transaction

GitHub: https://github.com/Bitconch/BUS

Web:www.bitconch.io

Twitter:https://twitter.com/bitconch

Telegram : https://t.me/BitconchEnglish

Facebook:https://www.facebook.com/BitConchofficial

Bitconch

A new protocol for smart contract and DApp

Benjamin

Written by

Benjamin

Blockchain industry practitioner.

Bitconch

Bitconch

A new protocol for smart contract and DApp

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade