The Ethereum Virtual Machine (EVM)

The Ethereum Virtual Machine (EVM) is a key component of the Ethereum platform. It is a sandboxed environment in which smart contracts can be executed. The EVM is a virtual machine that runs on top of the Ethereum blockchain, and it is responsible for executing smart contract code in a secure and isolated manner.
Smart contracts are written in a high-level programming language, such as Solidity, and compiled into bytecode that can be executed by the EVM. The EVM is designed to be highly deterministic, meaning that given the same input, it will always produce the same output. This makes it possible to verify the correctness of smart contract code and ensure that it will behave as intended.
Overall, the combination of the singleton state and the EVM form the core of the Ethereum platform, and enable the development and execution of decentralized applications and smart contracts.
EVM disassembler

Visual Representation

Ethereum Virtual Machine (EVM)
+-------------------------------------------------------------+
| |
| |
| +-----------------------+ +---------------------+ |
| | Contract Code | | EVM bytecode | |
| | (written in Solidity) | | | |
| +-----------------------+ +---------------------+ |
| | | |
| | | |
| +-----------v-----------+ +-------v--------+ |
| | Compiler | | EVM Loader | |
| | (Solidity to Bytecode)| |(Loads Bytecode)| |
| +-----------+-----------+ +-------+--------+ |
| | | |
| | | |
| +-----------v-----------+ +-------v--------+ |
| | EVM Interpreter | | Execution | |
| | (Runs EVM bytecode) | | Environment | |
| +-----------------------+ +----------------+ |
| |
+-------------------------------------------------------------+
In this example, we have a simplified representation of the Ethereum Virtual Machine (EVM), which is a sandboxed environment in which smart contracts can be executed.
The EVM consists of several components, including the contract code, which is written in a high-level programming language such as Solidity, and the EVM bytecode, which is the compiled version of the contract code that can be executed by the EVM.
The contract code is compiled into EVM bytecode using a compiler, which generates machine-readable instructions that can be executed by the EVM. The EVM bytecode is then loaded into the EVM using a loader, which prepares the bytecode for execution.
The EVM bytecode is then executed in the EVM interpreter, which is responsible for running the code and enforcing the rules of the Ethereum network. The interpreter operates in a sandboxed environment, which prevents it from accessing resources outside of the EVM, ensuring that the execution of the code is secure and isolated.
Overall, the Ethereum Virtual Machine is a critical component of the Ethereum platform, and enables the development and execution of decentralized applications and smart contracts in a secure and transparent manner.

Process in the Ethereum Virtual Machine (EVM)

  1. 1.
    Contract Code: The process begins with the contract code, which is written in a high-level programming language such as Solidity.
  2. 2.
    Compiler: The contract code is compiled into EVM bytecode using a compiler, which generates machine-readable instructions that can be executed by the EVM.
  3. 3.
    EVM Loader: The EVM bytecode is loaded into the EVM using a loader, which prepares the bytecode for execution.
  4. 4.
    EVM Interpreter: The EVM bytecode is then executed in the EVM interpreter, which is responsible for running the code and enforcing the rules of the Ethereum network.
  5. 5.
    Execution Environment: The interpreter operates in a sandboxed environment, which prevents it from accessing resources outside of the EVM, ensuring that the execution of the code is secure and isolated.
  6. 6.
    State Changes: As the EVM bytecode is executed, it can modify the state of the blockchain, including updating account balances and executing smart contract functions.
  7. 7.
    Transactions: When a smart contract function is executed, it is done so as part of a transaction on the blockchain. The transaction includes the input data for the function, as well as any Ether or other assets that are transferred as part of the transaction.
  8. 8.
    Validation and Consensus: Once the transaction is added to a block on the blockchain, it must be validated and verified by the network using a consensus mechanism such as Proof of Work (PoW) or Proof of Stake (PoS).
  9. 9.
    Network Propagation: Finally, the block and its transactions are propagated to all nodes in the network, ensuring that all nodes have an up-to-date copy of the blockchain and its state.
Overall, this process demonstrates how the Ethereum Virtual Machine enables the development and execution of decentralized applications and smart contracts on the Ethereum blockchain in a secure and transparent manner.