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
- Variables
- func BigUint64(v *big.Int) (uint64, bool)
- func RunPrecompiledContract(context inter.ChainContext, p PrecompiledContract, input []byte, ...) (ret []byte, err error)
- type AccountRef
- type CanTransferFunc
- type Config
- type Context
- type ContractRef
- type DebugLog
- type GetHashFunc
- type LogConfig
- type OPCode
- type PrecompiledContract
- type Storage
- type StructLog
- type Tracer
- type TransferFunc
- type VM
Constants ¶
Variables ¶
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") )
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 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 ¶
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 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 ¶
ContractRef is a reference to the contract's backing object
type GetHashFunc ¶
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 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 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 ¶
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 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 }