Basics of the Ethereum Virtual Machine (EVM)

Basics of the Ethereum Virtual Machine (EVM)

Studying the Ethereum project published at Coinmarketrate.com, you will certainly pay attention to such a term as Ethereum-Virtual-Machine. It is EVM that opens up a lot of opportunities for the Ethereum blockchain.

If you want to start using EVM, then you don’t have to be an experienced programmer. EVMs are designed in such a way that they do not require really powerful equipment, which makes them suitable for beginners.

The Ethereum blockchain platform includes external and contract accounts. With a transfer initiated from any of them, users can send ETH or data in binary format.

When platform developers use gas, it protects EVM from various attacks that can slow down the blockchain network. In addition, depending on the type, the Ethereum network data is placed in storage, memory or stack.

Ethereum works by executing opcodes

Users can disable EVM accounts or completely delete them using the Solidity self-destruct command. But how does Ethereum actually work?

The smart contract platform is capable of performing various tasks by executing certain types of instructions, known as opcodes. Each opcode has a size of 1 byte (or 8 bits), and is encoded into a bytecode. Opcodes are also split into bytes when users perform a specific task.

Since there are 140 opcodes in total, Ethereum virtual machines are considered Turing complete, which means that they can (theoretically) solve any computational tasks.

The source code executed on it does not have access to other system processes on users’ computers, which effectively isolates the EVM.

As already mentioned, there are two main types of accounts in Ethereum: external and contractual. EVMs are able to work equally with both. And each account has a certain ETH balance. At the same time, any transfer carrying ETH can change it.

It is also worth noting that a transfer initiated from one account to another may contain a certain amount of ETH or binary data, also called payload.

Additional actions may depend on the actual invoice. So, if it includes the source code, then it is executed. The payload actually turns into input data. And if it is not set, then the code that users send is executed and eventually returns the code for a completely new contract.

At the design stage, the source code of the contract contains nothing (in other words, it is empty).

Since there is no centralized authority, contracts are executed on all nodes of the Ethereum network. This approach can lead to a (significant) slowdown of the blockchain network, which may have been intended. In order to really slow down the work, they can create many different and complex contracts.

To provide protection against such attacks, each opcode comes with a basic level of gas cost, and gas is like a token that is used to pay EVM for executing a transaction.

Its main purpose is to set a certain limit on how much work is required to perform an operation. When the EVM completes the operation, it starts to consume its gas (gradually).

EVM stores data/information in storage, memory or stack

The EVM specification lists three independent storage areas, which include storage, memory, and stack. Storage areas can be located inside each account, and are capable of storing contract state variables.

The storage is assigned during the smart contract release process. Users can change it by calling the sendTransaction function.

It is noteworthy that no contract can read the repository of another contract (for security and privacy reasons), or write directly to it. Meanwhile, memory is linear and can contain temporary variables.

Since they actually exist only in the calling function itself, memory is erased between calls. Users can access memory at the byte level, but the limit of one read is set to 256 bits, and writing can be in any range from 8 to 256 bits.

To expand the memory, users have to pay for gas. Moreover, it can scale quadratically, and the more it expands, the more it will cost. But it’s still cheaper to use compared to memory.

The EVM specification defines it as a stack machine. The stack is where the calculations take place. This data area can contain up to 1024 small local variables. And each stack element has a total size of 256 bits.

The stack is also the most economical of the various data storage areas.

A programmer may have limited access to the stack. He can copy one of the top 16 elements to the top, or force the top element to swap places with one of the 16 located below it.

To gain deeper access, users can start moving stack items to the storage area, or directly into memory.

Logs are not technically a memory type

It’s worth noting that logs aren’t really a memory type. But they are also used for data storage, so they can also be considered when getting acquainted with Ethereum/Solidity.

Logs can transfer data through an indexed structure with a display reaching the block level. Smart contracts will not have access to the data contained in the journal after its creation. But they can be accessed from outside the blockchain itself. Some of this data is also contained in bloom filters.

Another important information you need to know about EVM is related to the Solidity self-destruct operation, which removes the source code from the blockchain. However, it will still remain part of the history of the blockchain, and can be preserved in most EVM nodes.

EVM technologies are evolving, rapidly reaching maturity

EVM technology has evolved significantly over the past few years. One of the notable projects called Syscoin, which uses the best of Bitcoin and Ethereum through a coordinated platform, has developed its own virtual machine, with improved network capabilities (Network Enhanced Virtual Machine, NEVM).

As the project developers explain, the Syscoin design preserves the “gold standard” of the security of the Bitcoin consensus mechanism and unified mining, while providing the performance characteristics expected in the future of Ethereum 2.0 thanks to the L2 ZK-Rollup technology.

The main advantages of NEVM are: L2 scalability for smart contracts, as well as independent reward markets that operate on the basis of ZK-Rollup.

NEVM is also compatible with Ethereum, so almost any ETH-based smart contract can be deployed on NEVM. In addition, the platform provides reliable security, since it uses the proven L1 protocol, applying the merger of bitcoin miners PoW and consensus that meets the requirements of Bitcoin.

In addition to these functions, protocol adaptation allows the transfer of value between Bitcoin and Ethereum (SYS <-> NEVM) without trust, and all this on a single, coordinated platform.