Developer Resources
Block ExplorerGitHubRun a NodeMigration GuideETN Testnet Faucet
  • Overview
  • Foundational topics
    • Intro to the Electroneum Smart Chain
    • Intro to ETN
    • Intro to dapps
    • Web2 vs Web3
    • Accounts
    • Transactions
    • Blocks
    • Electroneum Virtual Machine (EVM)
      • Opcodes
    • Gas and Fees
    • Nodes and clients
    • Networks
    • Consensus mechanisms
      • IBFT
  • Electroneum Stack
    • Intro to the stack
    • Smart contracts
    • Development networks
    • Development frameworks
    • Electroneum client APIs
      • JavaScript APIs
      • JSON-RPC
    • Storage
    • Integrated Development Environments (IDEs)
    • Metamask
  • Advanced
    • Bridges
    • Standards
      • Token standards
        • ERC-20 Fungible Tokens
        • ERC-721 NFTs
    • Oracles
    • Networking layer
      • Network addresses
    • Data structures and encoding
      • Patricia Merkle Trie
      • Recursive-length prefix (RLP)
      • Web3 secret storage definition
  • Design fundamentals
    • Intro to design and UX
  • ETN-SC Client
    • Getting started
      • Introduction
      • Hardware requirements
      • Instaling ETN-SC
    • Fundamentals
      • Command-line options
      • Security
      • Sync-modes
      • Account management
      • Databases
      • Backup & restore
      • Logs
      • Connecting to peers
      • Pruning
      • Private networks
      • Config files
      • Light client
    • Interacting with ETN-SC
      • JSON-RPC Server
        • Batch requests
        • Real-time events
      • JSON-RPC Namespaces
        • admin
        • clique
        • debug
        • eth
        • istanbul
        • les
        • miner
        • net
        • personal
        • txpool
      • JS Console
      • JS Console 2: Contracts
      • GraphQL Server
    • Developers
      • Introduction
      • Dapp developers
        • Dev mode
        • Go API
        • Go Account Management
        • Go Contract Bindings
      • EVM tracing
        • Introduction
        • Basic traces
        • Built-in tracers
        • Custom EVM tracer
        • Tutorial for JavaScript tracing
      • ETN-SC developer
        • Developer guide
        • Disclosures
        • DNS discovery setup guide
        • Code review guidelines
      • Contributing
    • Monitoring
      • Creating Dashboards
      • Understanding Dashboards
      • Ethstats
      • Metrics
    • Tools
      • Clef
        • Introduction
        • APIs
        • Rules
        • Setup
        • Datatypes
        • Tutorial
        • Clique-signing
      • abigen
      • devp2p
    • FAQs
  • Migration to Smart Chain
    • Overview
    • How to Migrate
      • ETN Online Wallets
      • Paper Wallets
      • CLI Wallet Users
      • Exchange Holders
      • Exchanges
    • Bridge Smart Contract
  • Misc. Guides
    • Set up Ledger + Metamask
  • MY.ELECTRONEUM.COM
    • Vendor API
Powered by GitBook
On this page
  • Prerequisites
  • From ledger to state machine
  • The Electroneum state transition function
  • State
  • Transactions
  • EVM Instructions
  • FURTHER READING
  • RELATED TOPICS

Was this helpful?

  1. Foundational topics

Electroneum Virtual Machine (EVM)

PreviousBlocksNextOpcodes

Last updated 1 year ago

Was this helpful?

The EVM’s physical instantiation can’t be described in the same way that one might point to a cloud or an ocean wave, but it does exist as one single entity maintained by thousands of connected computers running an Electroneum Smart Chain client.

The Electroneum protocol itself exists solely for the purpose of keeping the continuous, uninterrupted, and immutable operation of this special state machine. It's the environment in which all Electroneum accounts and smart contracts live. At any given block in the chain, Electroneum Smart Chain has one and only one 'canonical' state, and the EVM is what defines the rules for computing a new valid state from block to block.

Prerequisites

Some basic familiarity with common terminology in computer science such as , , and a are necessary to understand the EVM. It would also be helpful to be comfortable with cryptography/blockchain concepts like and the .

From ledger to state machine

The analogy of a 'distributed ledger' is often used to describe blockchains like Bitcoin, which enable a decentralized currency using fundamental tools of cryptography. The ledger maintains a record of activity which must adhere to a set of rules that govern what someone can and cannot do to modify the ledger. For example, a Bitcoin address cannot spend more Bitcoin than it has previously received. These rules underpin all transactions on Bitcoin and many other blockchains.

While Electroneum has its own native cryptocurrency (ETN) that follows almost exactly the same intuitive rules, it also enables a much more powerful function: . For this more complex feature, a more sophisticated analogy is required. Instead of a distributed ledger, Electroneum Smart Chain is a distributed . Electroneum Smart Chain's state is a large data structure which holds not only all accounts and balances, but a machine state, which can change from block to block according to a pre-defined set of rules, and which can execute arbitrary machine code. The specific rules of changing state from block to block are defined by the EVM.

Diagram adapted from

The Electroneum state transition function

The EVM behaves as a mathematical function would: Given an input, it produces a deterministic output. It therefore is quite helpful to more formally describe Electroneum as having a state transition function:

1Y(S, T)= S'2

Given an old valid state (S) and a new set of valid transactions (T), the Electroneum state transition function Y(S, T) produces a new valid output state S'

State

Transactions

Transactions are cryptographically signed instructions from accounts. There are two types of transactions: those which result in message calls and those which result in contract creation.

EVM Instructions

During execution, the EVM maintains a transient memory (as a word-addressed byte array), which does not persist between transactions.

Contracts, however, do contain a Merkle Patricia storage trie (as a word-addressable word array), associated with the account in question and part of the global state.

FURTHER READING

RELATED TOPICS

In the context of Electroneum, the state is an enormous data structure called a , which keeps all linked by hashes and reducible to a single root hash stored on the blockchain.

Contract creation results in the creation of a new contract account containing compiled bytecode. Whenever another account makes a message call to that contract, it executes its bytecode.

The EVM executes as a with a depth of 1024 items. Each item is a 256-bit word, which was chosen for the ease of use with 256-bit cryptography (such as Keccak-256 hashes or secp256k1 signatures).

Compiled smart contract bytecode executes as a number of EVM , which perform standard stack operations like XOR, AND, ADD, SUB, etc. The EVM also implements a number of blockchain-specific stack operations, such as ADDRESS, BALANCE, BLOCKHASH, etc.

Diagrams adapted from

modified Merkle Patricia Trie
accounts
smart contract
stack machine↗
opcodes
Ethereum Yellowpaper↗
Jellopaper aka KEVM: Semantics of EVM in K↗
The Beigepaper↗
Electroneum Virtual Machine Opcodes↗
Ethereum Virtual Machine Opcodes Interactive Reference↗
A short introduction in Solidity's documentation↗
Gas
bytes↗
memory↗
stack↗
hash functions↗
Merkle tree↗
smart contracts
state machine↗
Ethereum EVM illustrated↗
Ethereum EVM illustrated(opens in a new tab)↗