PolySmartChain
English
English
  • PSC Development Documentation
  • Overview
    • PolySmartChain Introduction
    • PSC Token
    • PolySmartChain Network
  • Blockchain Foundation
    • Types of Blockchain
    • Consensus Mechanism
    • GAS
    • Block
    • Account
    • WEB2 and WEB3
    • DAPP
    • Transaction
  • Economics
    • PSC Token Economics
    • PSC Token Effectiveness
  • Developer
    • Virtual Machine(EVM)
    • Deploy the First Contract
    • Release PRC-20 Token
    • Release PRC-721 Token
  • Node
    • RPC Node
    • Deploy
    • private chain
    • Developer Tools
    • Infrastructure
    • Smart Contract Libraries
  • Explorer
    • Explorer
  • Wallet
    • Supported Wallets
    • Using Metamask
    • Using TokenPocket
    • Using Imtoken
    • ImToken quick add network
  • Poly Bridge
    • PolyBridge Introduction
    • PolyBridge No-EVM Operation Tutorial
      • WDC to PSC(WDCSpace)
      • TRON to PSC(TronLink)
    • PolyBridge EVM Operation Tutorial
      • BNB Chain to PSC(MetaMask)
      • BNB Chain to PSC(Imtoken)
      • BNB Chain to PSC(TokenPocket)
    • PolyBridge Contracts
    • PolyBridge FAQ
  • DAPP
    • Swanswap
      • How to buy PSC tokens in Swanswap
      • How to Add PSC-USDT Liquidity in Swanswap
    • NFT Auction
      • Claim PolyJetClub
      • View PolyJetClub in the MetaMask Wallet
    • Social
      • Register Social
    • Mining Pool
      • Stake LP Token to Mining Pool
      • Mining Pool FAQ
    • Stake-in-farmV2
    • PolyDao Proposal Description
      • PolyDao Proposal FAQ
  • Resource
    • Resource
    • Contract
Powered by GitBook
On this page
  • From ledger to state machine
  • PolySmartChain State Transition Function
  • EVM Explanation
  • EVM Implementation
  1. Developer

Virtual Machine(EVM)

PreviousPSC Token EffectivenessNextDeploy the First Contract

Last updated 3 years ago

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 .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

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、 ADD、SUBetc. EVM also implements some blockchain specific stack operations such as ADDRESS、BALANCE、BLOCKHASH etc.

EVM Implementation

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

The EVM operates as a 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.

stack machine
state machine