vm

package
v0.6.2 Latest Latest
Warning

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

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

Documentation

Overview

Package vm implements the VNT Virtual Machine.

The vm package implements one VM, a byte code VM. The BC (Byte Code) VM loops over a set of bytes and executes them according to the set of rules defined in the VNT yellow paper.

Index

Constants

View Source
const (
	GasQuickStep   uint64 = 2
	GasFastestStep uint64 = 3
	GasFastStep    uint64 = 5
	GasMidStep     uint64 = 8
	GasSlowStep    uint64 = 10
	GasExtStep     uint64 = 20

	GasReturn       uint64 = 0
	GasStop         uint64 = 0
	GasContractByte uint64 = 200
)

Variables

View Source
var (
	ErrOutOfGas                 = errors.New("out of gas")
	ErrCodeStoreOutOfGas        = errors.New("contract creation code storage out of gas")
	ErrDepth                    = errors.New("max call depth exceeded")
	ErrTraceLimitReached        = errors.New("the number of logs reached the specified limit")
	ErrInsufficientBalance      = errors.New("insufficient balance for transfer")
	ErrContractAddressCollision = errors.New("contract address collision")
	ErrExecutionReverted        = errors.New("wavm: execution reverted")
	ErrMaxCodeSizeExceeded      = errors.New("wavm: max code size exceeded")
	ErrExecutionAssert          = errors.New("wavm: execution assert")
	ErrMagicNumberMismatch      = errors.New("magic number mismatch")
	ErrMainnetActive            = errors.New("only support election transaction in main net startup")
)
View Source
var PrecompiledContractsHubble = map[common.Address]PrecompiledContract{
	common.BytesToAddress([]byte{9}): &election.Election{},
}

PrecompiledContractsHubble contains the default set of pre-compiled VNT contracts used in the Hubble release.

Functions

func BigUint64

func BigUint64(v *big.Int) (uint64, bool)

func RunPrecompiledContract

func RunPrecompiledContract(context inter.ChainContext, p PrecompiledContract, input []byte, contract inter.Contract) (ret []byte, err error)

RunPrecompiledContract runs and evaluates the output of a precompiled contract.

Types

type AccountRef

type AccountRef common.Address

AccountRef implements ContractRef.

Account references are used during VM initialisation and it's primary use is to fetch addresses. Removing this object proves difficult because of the cached jump destinations which are fetched from the parent contract (i.e. the caller), which is a ContractRef.

func (AccountRef) Address

func (ar AccountRef) Address() common.Address

Address casts AccountRef to a Address

type CanTransferFunc

type CanTransferFunc func(inter.StateDB, common.Address, *big.Int) bool

type Config

type Config struct {
	// Debug enabled debugging Interpreter options
	Debug bool
	// Tracer is the op code logger
	Tracer Tracer
	// NoRecursion disabled Interpreter call, callcode,
	// delegate call and create.
	NoRecursion bool
	// Enable recording of SHA3/keccak preimages
	EnablePreimageRecording bool
}

Config are the configuration options for the Interpreter

type Context

type Context struct {
	// CanTransfer returns whether the account contains
	// sufficient ether to transfer the value
	CanTransfer CanTransferFunc
	// Transfer transfers ether from one account to the other
	Transfer TransferFunc
	// GetHash returns the hash corresponding to n
	GetHash GetHashFunc

	// Message information
	Origin   common.Address // Provides information for ORIGIN
	GasPrice *big.Int       // Provides information for GASPRICE

	// Block information
	Coinbase    common.Address // Provides information for COINBASE
	GasLimit    uint64         // Provides information for GASLIMIT
	BlockNumber *big.Int       // Provides information for NUMBER
	Time        *big.Int       // Provides information for TIME
	Difficulty  *big.Int       // Provides information for DIFFICULTY
}

type ContractRef

type ContractRef interface {
	Address() common.Address
}

ContractRef is a reference to the contract's backing object

type DebugLog

type DebugLog struct {
	PrintMsg string `json:"printMsg"`
}

type GetHashFunc

type GetHashFunc func(uint64) common.Hash

GetHashFunc returns the nth block hash in the blockchain

type LogConfig

type LogConfig struct {
	DisableMemory  bool // disable memory capture
	DisableStack   bool // disable stack capture
	DisableStorage bool // disable storage capture
	Debug          bool // print output during capture end
	Limit          int  // maximum length of output, but zero means unlimited
}

LogConfig are the configuration options for structured logger the VM

type OPCode

type OPCode interface {
	String() string
	IsPush() bool
	Byte() byte
}

type PrecompiledContract

type PrecompiledContract interface {
	RequiredGas(input []byte) uint64                                              // RequiredPrice calculates the contract gas use
	Run(context inter.ChainContext, input []byte, value *big.Int) ([]byte, error) // Run runs the precompiled contract
}

PrecompiledContract is the basic interface for native Go contracts. The implementation requires a deterministic gas count based on the input size of the Run method of the contract.

type Storage

type Storage map[common.Hash]common.Hash

func (Storage) Copy

func (s Storage) Copy() Storage

type StructLog

type StructLog struct {
	Pc         uint64                      `json:"pc"`
	Op         OPCode                      `json:"op"`
	Gas        uint64                      `json:"gas"`
	GasCost    uint64                      `json:"gasCost"`
	Memory     []byte                      `json:"memory"`
	MemorySize int                         `json:"memSize"`
	Stack      []*big.Int                  `json:"stack"`
	Storage    map[common.Hash]common.Hash `json:"-"`
	Depth      int                         `json:"depth"`
	Err        error                       `json:"-"`
}

StructLog is emitted to the VM each cycle and lists information about the current internal state prior to the execution of the statement.

func (*StructLog) ErrorString

func (s *StructLog) ErrorString() string

func (*StructLog) OpName

func (s *StructLog) OpName() string

type Tracer

type Tracer interface {
	CaptureStart(from common.Address, to common.Address, call bool, input []byte, gas uint64, value *big.Int) error
	CaptureState(env VM, pc uint64, op OPCode, gas, cost uint64, contract inter.Contract, depth int, err error) error
	CaptureLog(env VM, msg string) error
	CaptureFault(env VM, pc uint64, op OPCode, gas, cost uint64, contract inter.Contract, depth int, err error) error
	CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error
}

Tracer is used to collect execution traces from an VM transaction execution. CaptureState is called for each step of the VM with the current VM state. Note that reference types are actual VM data structures; make copies if you need to retain them beyond the current call.

type TransferFunc

type TransferFunc func(inter.StateDB, common.Address, common.Address, *big.Int)

type VM

type VM interface {
	Cancel()
	Create(caller ContractRef, code []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error)
	Call(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)
	CallCode(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)
	DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
	StaticCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
	GetStateDb() inter.StateDB
	ChainConfig() *params.ChainConfig
	GetContext() Context
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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