Virtual Machine(EVM)

A physical instance of EVM cannot be described in the way one might point to a cloud or an ocean wave; it is a real entity that exists and is maintained by thousands of computers running Ethernet clients together.

The PolySmartChain protocol itself exists solely to keep this particular state machine running continuously, uninterruptedly and permanently. This is the environment in which all PolySmartChain accounts and smart contracts exist. PolySmartChain has only one "canonical" state on any given block in the chain, and EVM defines the rules for computing a new valid state from one block to the next.

From ledger to state machine

The analogy of a "distributed ledger" is often used to describe a blockchain like Bitcoin, which uses the basic tools of cryptography to implement decentralized currency. Cryptocurrencies behave like "normal" currencies because there are rules that govern what people can and cannot do to modify 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 PolySmartChain has its own native cryptocurrency (PSCETH) that follows almost exactly the same intuitive rules, it also supports a more powerful feature: smart contracts. For this more complex functionality, a more complex analogy is required. PolySmartChain is not a distributed ledger, but a distributed state machine.PolySmartChain's state is a large data structure that keeps not only all accounts and balances, but also a machine state that can be changed between 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 EVM.

PolySmartChain State Transition Function

An EVM behaves like a mathematical function: for a given input, it produces a deterministic output. It is therefore very helpful to describe Ether more formally as having a state transition function:

    Y(S, T)= S'

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

Status

In the context of PolySmartChain, the state is a huge data structure called the adjusted Merkle Patricia Trie that enables all accounts to be linked by hash and can be traced back to a single root hash stored on the blockchain.

Transaction

A transaction is a cryptographically signed instruction from an account. There are two types of transactions: one is a message call transaction and the other is a contract create transaction.

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

EVM Explanation

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

During execution, the EVM maintains a transient memory (as an array of word-addressable bytes) that does not persist between transactions.

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

The compiled smart contract bytecode is executed as many EVM opcodes that perform standard stack operations such as XOR AND ADDSUBetc. EVM also implements some blockchain specific stack operations such as ADDRESSBALANCEBLOCKHASH etc.

EVM Implementation

All implementations of EVM follow the specifications described in the Ethernet Yellow Book, thanks to the contributions made by Ethernet.

Last updated