Hash Ahead Virtual Machine (EVMC)

The physical instance of EVMC cannot be described like people pointing to clouds or ocean waves. It is an entity that exists and is jointly maintained by thousands of computers running Hash Ahead clients.

The Hash Ahead protocol itself exists only to keep this special state machine running continuously, uninterrupted, and immutable. The Hash Ahead virtual machine is the environment on which all Hash Ahead accounts and smart contracts depend. At any given block on the chain, Hash Ahead has one and only one "canonical" state, and the Hash Ahead virtual machine defines the rules for computing a new valid state from one block to another.

Prerequisite

A basic understanding of common terms in computer science such as byte, memory, and stack is a prerequisite for understanding EVMC. Familiarity with cryptography/blockchain concepts like hash functions and Merkle trees is also helpful.

From Ledger to State Machine

The analogy of a "distributed ledger" is often used to describe blockchains like Bitcoin, which use the fundamental tools of cryptography to enable decentralized money. The ledger keeps a record of activity, and that activity must obey a set of rules that limit what users can and cannot do when modifying the ledger. For example, a bitcoin address cannot spend more bitcoins than it has previously received. These rules are the basis for all transactions on Bitcoin and many other blockchains.

While Hash Ahead has its own native cryptocurrency, HAH, that follows almost exactly the same intuitive rules, it also supports something even more powerful: smart contracts. For this more complex functionality, a more complex analogy is required. Hash Ahead is not a distributed ledger, but a distributed state machine. The state of Hash Ahead is a large data structure, which not only holds all accounts and balances, but also holds a machine state, which can be changed between different blocks according to a predefined set of rules, and can execute arbitrary machine code. The specific rules for changing state in a block are defined by EVMC.

Hash Ahead state transition function

EVMC behaves like a mathematical function: given an input, it produces a deterministic output. So it's very helpful to describe Hash Ahead more formally as having state transition functions:

1Y(S, T)= S'2

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

State

In a Hash Ahead environment, the state is a huge data structure called a modified Merkle Patricia tree, which holds all accounts linked together by hash and traceable back to a single root hash.

Trade

Transactions are cryptographically signed instructions from accounts. There are two types of transactions: one is a message call transaction, and the other is a contract creation transaction.

A contract creation transaction creates a new contract account that contains the compiled smart contract bytecode. Whenever another account makes a message call to the contract, it executes its bytecode.

EVMC description

The EVMC operates as a stack machine with a stack depth of 1024 items. Each item is a 256-bit word, and 256-bit cryptography (such as Keccak-256 hashing or secp256k1 signatures) has been chosen for ease of use.

During execution, EVMC maintains a transient memory (as a word-addressable byte array) that does not persist between transactions.

However, the contract does contain a Merkle Patricia storage trie (as a word-addressable array of words) associated with the account and part of the global state.

Compiled smart contract bytecode is executed as a number of EVMC opcodes which perform standard stack operations such as XORANDADDSUB, etc. EVMC also implements some blockchain-specific stack operations, such asADDRESSBALANCEBLOCKHASH , etc.

EVMC implementation

All implementations of EVMC must comply with the Hash Ahead specification.

In Hash Ahead, there are multiple Hash Ahead virtual machine implementations written in various programming languages.

All Hash Ahead clients include an EVMC implementation.

Last updated