What Ethereum Virtual Machine Has To Do With Smart Contracts
Ethereum is one of the most popular cryptocurrency platforms and the first one that has introduced smart contracts as we know them nowadays. In contradiction to Bitcoin Ethereum blockchain smart contracts are frequently used during ICOs. Since the ERC20 was introduced, smart contracts for ICO can be developed even by programmers without significant working experience with Solidity. Regardless of failure cases (such as The DAO fork) the implementation of Ethereum blockchain smart contracts is still used.
Many various platforms are trying to catch up with Ethereum. The main competitors are NEO, EOS, Hyperledger and some other more or less popular projects. However, Ethereum stands out from other platforms as it offers an independent technology called the Ethereum Virtual Machine (EVM).
To explain the EVM, we should start with the concept of accounts. Ethereum has two different types of accounts. This approach is chosen to support smart contracts.
The first account type is “Externally owned account” (EOA). It is intended to be controlled by participants. They are considered as state objects and possess balance. The second account type is “Contract account”. The official document defines it as a union of code and information that belongs to a particular address on the Ethereum blockchain.
All accounts have the same fields:
- Nonce (stands for “number used once”) is used to indicate different transactions and contract creations to prevent double spending issues.
- Balance is a simple value that defines funds owned by a particular address (expressed in Wei tokens).
- Contract code hash is a hash result of a smart contract program, stored in a database state. EOA does not have this part as it is managed by the network participants.
- Account storage hash is a hash value calculated based on data stored in a long term storage area. EOA accounts do not have it either.
All contracts are written in special programing languages developed exclusively for the Ethereum environment. These are:
- Solidity. This language is a main instrument of Ethereum. The majority of Ethereum blockchain smart contracts are written in Solidity. It is actively developing, and the support of Ethereum enthusiasts is always welcome.
- Vyper is an alternative high-level language developed to write smart contracts. Even though Vyper is less popular compared to Solidity, it is still supported.
- LLL ( Lisp Like Language). It is hardly supported at the moment of writing.
- Serpent ( Python-like language). It is also hardly supported at the moment of writing.
- Mutan (Legacy language). It was abandoned in favor of Solidity and is not supported at the moment.
All of these languages are addressing their commands to the same EVM process on blockchain. All their commands are transferred to the bytecode executed in accordance with the EVM logic.
What makes the EVM virtual?
Like any other virtual machine, the EVM is a kind of virtual environment. Basically, it is a program that models a computer inside of another computer. For the external computer, the virtual machine is just another program. For the virtual machine, the external computer does not exist whatsoever. All cooperation and data exchange are one-way initiated, and any outputs can address from inside out. Vice versa, the external computer can influence the virtual machine at any time.
To perform any action, the EVM accepts a program code, converts it to binary and generates a corresponding reaction. The program has two sources: transactions and contracts. Any transaction can call for contract execution with the help of a message. Any contract can also call for another contract if properly written. A target contract code will be executed once a message is received.
EVM as a program in the computer environment
Due to the high code flexibility, Ethereum blockchain smart contracts can perform different operations. They are able to call neighboring contracts with their code executed sequentially. Such an approach allows creating complex programs distributed along the whole Ethereum environment and stored on blockchain. It is worth saying that developers have implemented some precautionary measures. Infinite loops are prevented by gas prices and by the limited number of sequentially called contracts. This guarantees that every process initiated on the EVM will sooner or later end.
The Ethereum Virtual Machine is well-developed, and other platforms, such as Cardano, Hyperledger, Quorum, Hedera, etc. actively use it. Of course, other languages can be applied to the smart contracts creation, too. The list includes both common languages (Go, C++, Java) and some other solutions. We will talk about them in the next articles.