What You Need to Know About the Ethereum Virtual Machine (EVM)

Ethereum is the second most significant and most popular cryptocurrency, after Bitcoin. It is generally considered to be Bitcoin’s rival in the cryptocurrency world.

Like Bitcoin, Ethereum is decentralized, runs on Blockchain technology, and is an open-source project. However, Ethereum is more flexible and adaptable than Bitcoin. Anyone with the knowledge can create new applications on the platform. With the release of Homestead, the second version of Ethereum, these applications have become safe to use.

Homestead gives users the freedom to create any applications they want, no matter how complex. It has also become a platform for launching new decentralized blockchain applications other than cryptocurrencies.

At the heart of all these processes is the Ethereum Virtual Machine (EVM), a quasi-Turing complete machine that can write any code of random algorithmic complexity.

What Is the Virtual Machine and How Does It Work?

To better understand what EVM is and how it works, we need to understand what the term “quasi-Turing” means. “Quasi” means “partially,” and “Turing” refers to Alan Turing, the “Father of Modern Computer Science” and the creator of the Turing machine.

In the computer world, there are various systems for accessing and modifying data. These systems include central processing units as well as programming languages.

A system or machine that can mathematically perform any calculation or problem given to it is considered Turing complete.

The Ethereum Virtual Machine is labeled a quasi-Turing complete machine because the computations it can solve are bound by gas, which means the number of computations it can perform is limited.

Gas is the equivalent of a fee on the Ethereum network. Every transaction you made on the Ethereum network has a price, and gas serves as the payment method.

The concept of gas on the Ethereum network has two aspects – gas and gas price. Gas is the measurement tool: it identifies the fee required for performing a specific computation. Gas price is the amount of Ether a user is willing to pay for every unit of gas.

Wei is the measurement unit for the gas price. Wei is the smallest unit of Ether, and one Ether is 10^18 Wei.

Before any transaction takes place, both a gas limit and gas price must be set. If you, as the person trying to complete the transaction, don’t have enough gas, the transaction becomes invalid.

Because computations are gas-dependent, there are some computations that the EVM cannot perform. These include mined blocks with gas limits that are too low and very complex computations that are considered economically impractical to solve.

The EVM programming language is called the EVM bytecode. If a higher-level programming language, such as Ethereum’s Solidity, is used to write a specific code, that code will be added to the EVM bytecode so the EVM can understand it.

EVM, a Transaction-based State Machine

The EVM has many uses; two of the primary ones are handling computation and internal state on the network and handling account information related to the users’ names and addresses, current gas price, balances, and block information.

The EVM is a transaction-based state machine, meaning that it manages the internal state on the network. Without the EVM, there would be nothing to track the status of each of the components needed to complete a transaction. These components work together to moderate the level of change in the complex Ethereum blockchain.

As a transaction-based state machine, the EVM needs to monitor the account state, world state, storage state, runtime environment information, and block information.

Account State

The Ethereum network consists of many small accounts that interact with each other – contract accounts or externally owned accounts.

Communication that takes place between two externally owned accounts is called transfer of value. Both these accounts can send messages to each other through a digitally-signed transaction using a private key.

Communication between an externally owned account and a contract account is to enable the latter to use its code to perform different actions, such as creating and transferring tokens.

Externally owned accounts can spur contract accounts into action; contract accounts are reactive. That means they cannot initiate transactions but can only respond to other transactions they receive.

Contract accounts have code or programming language associated with them, and this contract code controls the account. Externally owned accounts have no code but are controlled using private keys.

Any externally owned account can send messages to other externally owned accounts as well as to contract accounts. This type of account has a private key used to sign the account’s transactions.

The account state has four major components: nonce, balance, storageRoot, and codeHash

– Nonce – in externally owned accounts, the nonce represents the number of transactions sent from the account’s address. In contract accounts, it’s the number of contracts created by the account.– Balance – the number of wei owned by the account address– storageRoot – the 256-bit hash of a Merkle Patricia tree’s root node. The tree is empty by default, and it encodes the storage content of the account.– codeHash – this code is immutable: no one can change it after its creation. The codeHash of the EVM of this account is also the code that gets executed if this address receives a message call.

World State

The world state is composed of a mapping between the account state and 160-bit address identifiers. This information is stored in the Merkle Patricia tree.

Storage State

The storage state is account-specific information managed at runtime on the EVM.

Runtime Environment Information

This is the information needed to perform a transaction. It includes:

– Origin – the address of the transaction’s original sender– Caller – the address of the account that is performing the transaction– Gas Price – the current price of the gas that the transaction’s initiator has specified– Code size – how big the transaction codebase is

Block Information

These are the state values that are necessary to support a transaction. The block information includes:

– Blockhash – the hash of the most recently completed block– Coinbase – the recipient’s address– Timestamp of the current block– Number of the current block– Difficulty level of the current block– Gas limit of the current block