vm

package
v2.1.4+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2019 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package vm implements the vite virtual machine

Index

Constants

View Source
const (
	STOP opCode = iota
	ADD
	MUL
	SUB
	DIV
	SDIV
	MOD
	SMOD
	ADDMOD
	MULMOD
	EXP
	SIGNEXTEND
)

0x0 range - arithmetic ops.

View Source
const (
	LT opCode = iota + 0x10
	GT
	SLT
	SGT
	EQ
	ISZERO
	AND
	OR
	XOR
	NOT
	BYTE
	SHL
	SHR
	SAR
)

0x10 range - comparison ops.

View Source
const (
	ADDRESS opCode = 0x30 + iota
	BALANCE
	ORIGIN
	CALLER
	CALLVALUE
	CALLDATALOAD
	CALLDATASIZE
	CALLDATACOPY
	CODESIZE
	CODECOPY
	GASPRICE
	EXTCODESIZE
	EXTCODECOPY
	RETURNDATASIZE
	RETURNDATACOPY
	EXTCODEHASH
)

0x30 range - closure state.

View Source
const (
	BLOCKHASH opCode = 0x40 + iota
	COINBASE
	TIMESTAMP
	HEIGHT
	DIFFICULTY
	GASLIMIT
	TOKENID
	ACCOUNTHEIGHT
	PREVHASH
	FROMHASH
	SEED
)

0x40 range - block operations.

View Source
const (
	POP opCode = 0x50 + iota
	MLOAD
	MSTORE
	MSTORE8
	SLOAD
	SSTORE
	JUMP
	JUMPI
	PC
	MSIZE
	GAS
	JUMPDEST
)

0x50 range - 'storage' and execution.

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

View Source
const (
	LOG0 opCode = 0xa0 + iota
	LOG1
	LOG2
	LOG3
	LOG4
)

0xa0 range - logging ops.

View Source
const (
	CREATE opCode = 0xf0 + iota
	CALL
	CALLCODE
	RETURN
	DELEGATECALL
	STATICCALL = 0xfa

	REVERT       = 0xfd
	SELFDESTRUCT = 0xff
)

0xf0 range - closures.

View Source
const (
	BLAKE2B opCode = 0x21
)

0x20 range - hash ops.

Variables

This section is empty.

Functions

func ContainsStatusCode

func ContainsStatusCode(code []byte) bool

ContainsStatusCode checks whether code includes status reading opcode.

func GasRequiredForBlock

func GasRequiredForBlock(db vm_db.VmDb, block *ledger.AccountBlock) (uint64, error)

GasRequiredForBlock calculates gas required for a user account block.

func InitVMConfig

func InitVMConfig(isTest bool, isTestParam bool, isDebug bool, datadir string)

InitVMConfig init global status of vm. It should be called when the node started.

func IsTest added in v1.2.0

func IsTest() bool

IsTest returns whether node is currently running under a test mode or not.

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 NewVM

func NewVM(cr util.ConsensusReader) *VM

NewVM constructor of VM

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) Cancel

func (vm *VM) Cancel()

Cancel method stops the running contract receive

func (*VM) ConsensusReader

func (vm *VM) ConsensusReader() util.ConsensusReader

ConsensusReader getter

func (*VM) GlobalStatus

func (vm *VM) GlobalStatus() util.GlobalStatus

GlobalStatus getter

func (*VM) OffChainReader added in v1.3.0

func (vm *VM) OffChainReader(db vm_db.VmDb, code []byte, data []byte) (result []byte, err error)

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

Directories

Path Synopsis
abi

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL