Documentation ¶
Overview ¶
Package vm implements the vite virtual machine
Index ¶
- Constants
- func ContainsStatusCode(code []byte) bool
- func GasRequiredForBlock(db vm_db.VmDb, block *ledger.AccountBlock) (uint64, error)
- func InitVMConfig(isTest bool, isTestParam bool, isDebug bool, datadir string)
- func IsTest() bool
- type NodeConfig
- type VM
- func (context *VM) AppendBlock(block *ledger.AccountBlock)
- func (vm *VM) Cancel()
- func (vm *VM) ConsensusReader() util.ConsensusReader
- func (vm *VM) GlobalStatus() util.GlobalStatus
- func (vm *VM) OffChainReader(db vm_db.VmDb, code []byte, data []byte) (result []byte, err error)
- func (vm *VM) RunV2(db vm_db.VmDb, block *ledger.AccountBlock, sendBlock *ledger.AccountBlock, ...) (vmAccountBlock *vm_db.VmAccountBlock, isRetry bool, err error)
Constants ¶
const ( STOP opCode = iota ADD MUL SUB DIV SDIV MOD SMOD ADDMOD MULMOD EXP SIGNEXTEND )
0x0 range - arithmetic ops.
const ( LT opCode = iota + 0x10 GT SLT SGT EQ ISZERO AND OR XOR NOT BYTE SHL SHR SAR )
0x10 range - comparison ops.
const ( ADDRESS opCode = 0x30 + iota BALANCE ORIGIN CALLER CALLVALUE CALLDATALOAD CALLDATASIZE CALLDATACOPY CODESIZE CODECOPY GASPRICE EXTCODESIZE EXTCODECOPY RETURNDATASIZE RETURNDATACOPY EXTCODEHASH )
0x30 range - closure state.
const ( BLOCKHASH opCode = 0x40 + iota COINBASE TIMESTAMP HEIGHT DIFFICULTY GASLIMIT TOKENID ACCOUNTHEIGHT PREVHASH FROMHASH SEED )
0x40 range - block operations.
const ( POP opCode = 0x50 + iota MLOAD MSTORE MSTORE8 SLOAD SSTORE JUMP JUMPI PC MSIZE GAS JUMPDEST )
0x50 range - 'storage' and execution.
const ( PUSH1 opCode = 0x60 + iota PUSH2 PUSH3 PUSH4 PUSH5 PUSH6 PUSH7 PUSH8 PUSH9 PUSH10 PUSH11 PUSH12 PUSH13 PUSH14 PUSH15 PUSH16 PUSH17 PUSH18 PUSH19 PUSH20 PUSH21 PUSH22 PUSH23 PUSH24 PUSH25 PUSH26 PUSH27 PUSH28 PUSH29 PUSH30 PUSH31 PUSH32 DUP1 DUP2 DUP3 DUP4 DUP5 DUP6 DUP7 DUP8 DUP9 DUP10 DUP11 DUP12 DUP13 DUP14 DUP15 DUP16 SWAP1 SWAP2 SWAP3 SWAP4 SWAP5 SWAP6 SWAP7 SWAP8 SWAP9 SWAP10 SWAP11 SWAP12 SWAP13 SWAP14 SWAP15 SWAP16 )
0x60 range.
const ( LOG0 opCode = 0xa0 + iota LOG1 LOG2 LOG3 LOG4 )
0xa0 range - logging ops.
const ( CREATE opCode = 0xf0 + iota CALL CALLCODE RETURN DELEGATECALL STATICCALL = 0xfa REVERT = 0xfd SELFDESTRUCT = 0xff )
0xf0 range - closures.
const (
BLAKE2B opCode = 0x21
)
0x20 range - hash ops.
Variables ¶
This section is empty.
Functions ¶
func ContainsStatusCode ¶
ContainsStatusCode checks whether code includes status reading opcode.
func GasRequiredForBlock ¶
GasRequiredForBlock calculates gas required for a user account block.
func InitVMConfig ¶
InitVMConfig init global status of vm. It should be called when the node started.
Types ¶
type NodeConfig ¶
type NodeConfig struct { IsDebug bool // contains filtered or unexported fields }
NodeConfig holds the global status of vm.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM holds the runtime information of vite vm and provides the necessary tools to run a transfer transaction of a call contract transaction. It also provides an offchain getter method to read contract storage without a transaction. The VM instance should never be reused and is not thread safe.
func (*VM) AppendBlock ¶
func (context *VM) AppendBlock(block *ledger.AccountBlock)
AppendBlock method append a send block to send block list of a contract receive block
func (*VM) ConsensusReader ¶
func (vm *VM) ConsensusReader() util.ConsensusReader
ConsensusReader getter
func (*VM) OffChainReader ¶ added in v1.3.0
OffChainReader read contract storage without tx
func (*VM) RunV2 ¶
func (vm *VM) RunV2(db vm_db.VmDb, block *ledger.AccountBlock, sendBlock *ledger.AccountBlock, status util.GlobalStatus) (vmAccountBlock *vm_db.VmAccountBlock, isRetry bool, err error)
RunV2 method executes an account block, performs balance change and storage change, returns execution result