Documentation
¶
Index ¶
- Constants
- func CheckMultisigPar(v *VM, curve elliptic.Curve, h []byte, pkeys [][]byte, sigs [][]byte) bool
- func GetInteropID(parameter []byte) uint32
- func IsMultiSigContract(script []byte) bool
- func IsScriptCorrect(script []byte, methods bitfield.Field) error
- func IsSignatureContract(script []byte) bool
- func IsStandardContract(script []byte) bool
- func ParseMultiSigContract(script []byte) (int, [][]byte, bool)
- func ParseSignatureContract(script []byte) ([]byte, bool)
- type Context
- func (c *Context) Convert(_ stackitem.Type) (stackitem.Item, error)
- func (c *Context) CurrInstr() (int, opcode.Opcode)
- func (c *Context) DumpArgumentsSlot() string
- func (c *Context) DumpLocalSlot() string
- func (c *Context) DumpStaticSlot() string
- func (c *Context) Dup() stackitem.Item
- func (c *Context) Equals(s stackitem.Item) bool
- func (c *Context) Estack() *Stack
- func (c *Context) GetCallFlags() callflag.CallFlag
- func (c *Context) GetNEF() *nef.File
- func (c *Context) HasTryBlock() bool
- func (c *Context) IP() int
- func (c *Context) IsCalledByEntry() bool
- func (c *Context) IsDeployed() bool
- func (c *Context) Jump(pos int)
- func (c *Context) LenInstr() int
- func (c *Context) Next() (opcode.Opcode, []byte, error)
- func (c *Context) NextIP() int
- func (c *Context) NextInstr() (int, opcode.Opcode)
- func (c *Context) NumOfReturnVals() int
- func (c *Context) Program() []byte
- func (c *Context) ScriptHash() util.Uint160
- func (c *Context) String() string
- func (c *Context) TryBool() (bool, error)
- func (c *Context) TryBytes() ([]byte, error)
- func (c *Context) TryInteger() (*big.Int, error)
- func (c *Context) Type() stackitem.Type
- func (c *Context) Value() interface{}
- type ContextUnloadCallback
- type Element
- func (e Element) Array() []stackitem.Item
- func (e Element) BigInt() *big.Int
- func (e Element) Bool() bool
- func (e Element) Bytes() []byte
- func (e Element) BytesOrNil() []byte
- func (e Element) Interop() *stackitem.Interop
- func (e Element) Item() stackitem.Item
- func (e Element) String() string
- func (e Element) Value() interface{}
- type Stack
- func (s *Stack) Back() Element
- func (s *Stack) Clear()
- func (s *Stack) Dup(n int) Element
- func (s *Stack) InsertAt(e Element, n int)
- func (s *Stack) Iter(f func(Element))
- func (s *Stack) IterBack(f func(Element))
- func (s *Stack) Len() int
- func (s *Stack) MarshalJSON() ([]byte, error)
- func (s *Stack) Peek(n int) Element
- func (s *Stack) Pop() Element
- func (s *Stack) PopSigElements() ([][]byte, error)
- func (s *Stack) Push(e Element)
- func (s *Stack) PushItem(i stackitem.Item)
- func (s *Stack) PushVal(v interface{})
- func (s *Stack) RemoveAt(n int) Element
- func (s *Stack) ReverseTop(n int) error
- func (s *Stack) Roll(n int) error
- func (s *Stack) Swap(n1, n2 int) error
- func (s *Stack) ToArray() []stackitem.Item
- func (s *Stack) Top() Element
- type StateMessage
- type SyscallHandler
- type VM
- func (v *VM) AddBreakPoint(n int)
- func (v *VM) AddBreakPointRel(n int)
- func (v *VM) AddGas(gas int64) bool
- func (v *VM) AtBreakpoint() bool
- func (v *VM) Call(offset int)
- func (v *VM) Context() *Context
- func (v *VM) DumpEStack() string
- func (v *VM) DumpIStack() string
- func (v *VM) EnableInvocationTree()
- func (v *VM) Estack() *Stack
- func (v *VM) GasConsumed() int64
- func (v *VM) GetCallingScriptHash() util.Uint160
- func (v *VM) GetCurrentScriptHash() util.Uint160
- func (v *VM) GetEntryScriptHash() util.Uint160
- func (v *VM) GetInvocationTree() *invocations.Tree
- func (v *VM) HasFailed() bool
- func (v *VM) HasHalted() bool
- func (v *VM) HasStopped() bool
- func (v *VM) Istack() *Stack
- func (v *VM) Load(prog []byte)
- func (v *VM) LoadFileWithFlags(path string, f callflag.CallFlag) error
- func (v *VM) LoadNEFMethod(exe *nef.File, caller util.Uint160, hash util.Uint160, f callflag.CallFlag, ...)
- func (v *VM) LoadScript(b []byte)
- func (v *VM) LoadScriptWithFlags(b []byte, f callflag.CallFlag)
- func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160, f callflag.CallFlag)
- func (v *VM) LoadWithFlags(prog []byte, f callflag.CallFlag)
- func (v *VM) PopResult() interface{}
- func (v *VM) PrintOps(out io.Writer)
- func (v *VM) PushContextScriptHash(n int) error
- func (v *VM) Ready() bool
- func (v *VM) Reset(t trigger.Type)
- func (v *VM) Run() error
- func (v *VM) SetPriceGetter(f func(opcode.Opcode, []byte) int64)
- func (v *VM) State() vmstate.State
- func (v *VM) Step() error
- func (v *VM) StepInto() error
- func (v *VM) StepOut() error
- func (v *VM) StepOver() error
Constants ¶
const (
// MaxInvocationStackSize is the maximum size of an invocation stack.
MaxInvocationStackSize = 1024
// MaxTryNestingDepth is the maximum level of TRY nesting allowed,
// that is you can't have more exception handling contexts than this.
MaxTryNestingDepth = 16
// MaxStackSize is the maximum number of items allowed to be
// on all stacks at once.
MaxStackSize = 2 * 1024
)
const MaxMultisigKeys = 1024
MaxMultisigKeys is the maximum number of keys allowed for correct multisig contract.
Variables ¶
This section is empty.
Functions ¶
func CheckMultisigPar ¶ added in v0.90.0
func CheckMultisigPar(v *VM, curve elliptic.Curve, h []byte, pkeys [][]byte, sigs [][]byte) bool
CheckMultisigPar checks if the sigs contains sufficient valid signatures.
func GetInteropID ¶
func GetInteropID(parameter []byte) uint32
GetInteropID converts instruction parameter to an interop ID.
func IsMultiSigContract ¶
func IsMultiSigContract(script []byte) bool
IsMultiSigContract checks whether the passed script is a multi-signature contract.
func IsScriptCorrect ¶ added in v0.93.0
func IsScriptCorrect(script []byte, methods bitfield.Field) error
IsScriptCorrect checks the script for errors and mask provided for correctness wrt instruction boundaries. Normally, it returns nil, but it can return some specific error if there is any.
func IsSignatureContract ¶
func IsSignatureContract(script []byte) bool
IsSignatureContract checks whether the passed script is a signature check contract.
func IsStandardContract ¶
func IsStandardContract(script []byte) bool
IsStandardContract checks whether the passed script is a signature or multi-signature contract.
func ParseMultiSigContract ¶
func ParseMultiSigContract(script []byte) (int, [][]byte, bool)
ParseMultiSigContract returns the number of signatures and a list of public keys from the verification script of the contract.
func ParseSignatureContract ¶ added in v0.94.0
func ParseSignatureContract(script []byte) ([]byte, bool)
ParseSignatureContract parses a simple signature contract and returns a public key.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the current execution context of the VM.
func NewContextWithParams ¶ added in v0.93.0
func NewContextWithParams(b []byte, rvcount int, pos int) *Context
NewContextWithParams creates new Context objects using script, parameter count, return value count and initial position in script.
func (*Context) Convert ¶ added in v0.90.0
func (c *Context) Convert(_ stackitem.Type) (stackitem.Item, error)
Convert implements the stackitem.Item interface.
func (*Context) CurrInstr ¶
func (c *Context) CurrInstr() (int, opcode.Opcode)
CurrInstr returns the current instruction and opcode.
func (*Context) DumpArgumentsSlot ¶ added in v0.97.3
func (c *Context) DumpArgumentsSlot() string
DumpArgumentsSlot returns json formatted representation of the given slot.
func (*Context) DumpLocalSlot ¶ added in v0.97.3
func (c *Context) DumpLocalSlot() string
DumpLocalSlot returns json formatted representation of the given slot.
func (*Context) DumpStaticSlot ¶ added in v0.97.3
func (c *Context) DumpStaticSlot() string
DumpStaticSlot returns json formatted representation of the given slot.
func (*Context) Dup ¶
func (c *Context) Dup() stackitem.Item
Dup implements the stackitem.Item interface.
func (*Context) Equals ¶
func (c *Context) Equals(s stackitem.Item) bool
Equals implements the stackitem.Item interface.
func (*Context) Estack ¶ added in v0.92.0
func (c *Context) Estack() *Stack
Estack returns the evaluation stack of c.
func (*Context) GetCallFlags ¶ added in v0.90.0
func (c *Context) GetCallFlags() callflag.CallFlag
GetCallFlags returns the calling flags which the context was created with.
func (*Context) GetNEF ¶ added in v0.99.2
func (c *Context) GetNEF() *nef.File
GetNEF returns NEF structure used by this context if it's present.
func (*Context) HasTryBlock ¶ added in v0.99.0
func (c *Context) HasTryBlock() bool
func (*Context) IP ¶
func (c *Context) IP() int
IP returns the current instruction offset in the context script.
func (*Context) IsCalledByEntry ¶ added in v0.99.2
func (c *Context) IsCalledByEntry() bool
IsCalledByEntry checks parent script contexts and return true if the current one is an entry script (the first loaded into the VM) or one called by it.
func (*Context) IsDeployed ¶ added in v0.92.0
func (c *Context) IsDeployed() bool
IsDeployed returns whether this context contains a deployed contract.
func (*Context) Jump ¶ added in v0.98.0
func (c *Context) Jump(pos int)
Jump unconditionally moves the next instruction pointer to the specified location.
func (*Context) LenInstr ¶
func (c *Context) LenInstr() int
LenInstr returns the number of instructions loaded.
func (*Context) Next ¶
func (c *Context) Next() (opcode.Opcode, []byte, error)
Next returns the next instruction to execute with its parameter if any. The parameter is not copied and shouldn't be written to. After its invocation, the instruction pointer points to the instruction returned.
func (*Context) NextIP ¶
func (c *Context) NextIP() int
NextIP returns the next instruction pointer.
func (*Context) NextInstr ¶ added in v0.78.3
func (c *Context) NextInstr() (int, opcode.Opcode)
NextInstr returns the next instruction and opcode.
func (*Context) NumOfReturnVals ¶ added in v0.99.2
func (c *Context) NumOfReturnVals() int
NumOfReturnVals returns the number of return values expected from this context.
func (*Context) ScriptHash ¶
func (c *Context) ScriptHash() util.Uint160
ScriptHash returns a hash of the script in the current context.
func (*Context) TryBool ¶ added in v0.92.0
func (c *Context) TryBool() (bool, error)
TryBool implements the stackitem.Item interface.
func (*Context) TryBytes ¶
func (c *Context) TryBytes() ([]byte, error)
TryBytes implements the stackitem.Item interface.
func (*Context) TryInteger ¶ added in v0.90.0
func (c *Context) TryInteger() (*big.Int, error)
TryInteger implements the stackitem.Item interface.
type ContextUnloadCallback ¶ added in v0.99.0
type ContextUnloadCallback func(ctx *Context, commit bool) error
ContextUnloadCallback is a callback method used on context unloading from istack.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents an element on the stack. Technically, it's a wrapper around stackitem.Item interface to provide some API simplification for the VM.
func NewElement ¶
func NewElement(v interface{}) Element
NewElement returns a new Element object, with its underlying value inferred to the corresponding type.
func (Element) Array ¶
func (e Element) Array() []stackitem.Item
Array attempts to get the underlying value of the element as an array of other items. It will panic if the item type is different, which will be caught by the VM.
func (Element) BigInt ¶
func (e Element) BigInt() *big.Int
BigInt attempts to get the underlying value of the element as a big integer. It will panic if the assertion has failed, which will be caught by the VM.
func (Element) Bool ¶
func (e Element) Bool() bool
Bool converts the underlying value of the element to a boolean if it's possible to do so. Otherwise, it will panic.
func (Element) Bytes ¶
func (e Element) Bytes() []byte
Bytes attempts to get the underlying value of the element as a byte array. It will panic if the assertion has failed, which will be caught by the VM.
func (Element) BytesOrNil ¶ added in v0.92.0
func (e Element) BytesOrNil() []byte
BytesOrNil attempts to get the underlying value of the element as a byte array or nil. It will panic if the assertion has failed, which will be caught by the VM.
func (Element) Interop ¶
func (e Element) Interop() *stackitem.Interop
Interop attempts to get the underlying value of the element as an interop item.
func (Element) Item ¶
func (e Element) Item() stackitem.Item
Item returns the Item contained in the element.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents a Stack backed by a slice of Elements.
func (*Stack) Back ¶
func (s *Stack) Back() Element
Back returns the element at the end of the stack. Nil if the stack is empty.
func (*Stack) Clear ¶
func (s *Stack) Clear()
Clear clears all elements on the stack and set its length to 0.
func (*Stack) Dup ¶
func (s *Stack) Dup(n int) Element
Dup duplicates and returns the element at position n. Dup is used for copying elements on the top of its own stack.
s.Push(s.Peek(0)) // will result in unexpected behavior.
s.Push(s.Dup(0)) // is the correct approach.
func (*Stack) InsertAt ¶
func (s *Stack) InsertAt(e Element, n int)
InsertAt inserts the given item (n) deep on the stack. Be very careful using it and _always_ check n before invocation as it will panic otherwise.
func (*Stack) Iter ¶
func (s *Stack) Iter(f func(Element))
Iter iterates over all elements int the stack, starting from the top of the stack.
s.Iter(func(elem *Element) {
// do something with the element.
})
func (*Stack) IterBack ¶
func (s *Stack) IterBack(f func(Element))
IterBack iterates over all elements of the stack, starting from the bottom of the stack.
s.IterBack(func(elem *Element) {
// do something with the element.
})
func (*Stack) Len ¶
func (s *Stack) Len() int
Len returns the number of elements that are on the stack.
func (*Stack) MarshalJSON ¶
func (s *Stack) MarshalJSON() ([]byte, error)
MarshalJSON implements the JSON marshalling interface.
func (*Stack) Peek ¶
func (s *Stack) Peek(n int) Element
Peek returns the element (n) far in the stack beginning from the top of the stack. For n == 0 it's, effectively, the same as Top, but it'll panic if the stack is empty.
func (*Stack) Pop ¶
func (s *Stack) Pop() Element
Pop removes and returns the element on top of the stack. It panics if the stack is empty.
func (*Stack) PopSigElements ¶ added in v0.90.0
func (s *Stack) PopSigElements() ([][]byte, error)
PopSigElements pops keys or signatures from the stack as needed for CHECKMULTISIG.
func (*Stack) PushItem ¶ added in v0.97.3
func (s *Stack) PushItem(i stackitem.Item)
PushItem pushes an Item to the stack.
func (*Stack) PushVal ¶
func (s *Stack) PushVal(v interface{})
PushVal pushes the given value on the stack. It will infer the underlying Item to its corresponding type.
func (*Stack) RemoveAt ¶
func (s *Stack) RemoveAt(n int) Element
RemoveAt removes the element (n) deep on the stack beginning from the top of the stack. It panics if called with out of bounds n.
func (*Stack) ReverseTop ¶ added in v0.90.0
func (s *Stack) ReverseTop(n int) error
ReverseTop reverses top n items of the stack.
func (*Stack) Roll ¶
func (s *Stack) Roll(n int) error
Roll brings an item with the given index to the top of the stack moving all other elements down accordingly. It does all of that without popping and pushing elements.
func (*Stack) Swap ¶
func (s *Stack) Swap(n1, n2 int) error
Swap swaps two elements on the stack without popping and pushing them.
type StateMessage ¶
type StateMessage string
StateMessage is a vm state message which could be used as an additional info, for example by cli.
type SyscallHandler ¶ added in v0.91.0
type SyscallHandler = func(*VM, uint32) error
SyscallHandler is a type for syscall handler.
type VM ¶
type VM struct {
GasLimit int64
// SyscallHandler handles SYSCALL opcode.
SyscallHandler func(v *VM, id uint32) error
// LoadToken handles CALLT opcode.
LoadToken func(id int32) error
// contains filtered or unexported fields
}
VM represents the virtual machine.
func NewWithTrigger ¶ added in v0.90.0
func NewWithTrigger(t trigger.Type) *VM
NewWithTrigger returns a new VM for executions triggered by t.
func (*VM) AddBreakPoint ¶
func (v *VM) AddBreakPoint(n int)
AddBreakPoint adds a breakpoint to the current context.
func (*VM) AddBreakPointRel ¶
func (v *VM) AddBreakPointRel(n int)
AddBreakPointRel adds a breakpoint relative to the current instruction pointer.
func (*VM) AddGas ¶ added in v0.90.0
func (v *VM) AddGas(gas int64) bool
AddGas consumes the specified amount of gas. It returns true if gas limit wasn't exceeded.
func (*VM) AtBreakpoint ¶
func (v *VM) AtBreakpoint() bool
AtBreakpoint returns whether the VM is at breakpoint.
func (*VM) Call ¶ added in v0.91.0
func (v *VM) Call(offset int)
Call calls a method by offset using the new execution context.
func (*VM) Context ¶
func (v *VM) Context() *Context
Context returns the current executed context. Nil if there is no context, which implies no program is loaded.
func (*VM) DumpEStack ¶ added in v0.97.3
func (v *VM) DumpEStack() string
DumpEStack returns json formatted representation of the execution stack.
func (*VM) DumpIStack ¶ added in v0.97.3
func (v *VM) DumpIStack() string
DumpIStack returns json formatted representation of the invocation stack.
func (*VM) EnableInvocationTree ¶ added in v0.98.0
func (v *VM) EnableInvocationTree()
CollectInvocationTree enables collecting invocation tree data.
func (*VM) Estack ¶
func (v *VM) Estack() *Stack
Estack returns the evaluation stack, so interop hooks can utilize this.
func (*VM) GasConsumed ¶
func (v *VM) GasConsumed() int64
GasConsumed returns the amount of GAS consumed during execution.
func (*VM) GetCallingScriptHash ¶ added in v0.90.0
func (v *VM) GetCallingScriptHash() util.Uint160
GetCallingScriptHash implements the ScriptHashGetter interface.
func (*VM) GetCurrentScriptHash ¶ added in v0.90.0
func (v *VM) GetCurrentScriptHash() util.Uint160
GetCurrentScriptHash implements the ScriptHashGetter interface.
func (*VM) GetEntryScriptHash ¶ added in v0.90.0
func (v *VM) GetEntryScriptHash() util.Uint160
GetEntryScriptHash implements the ScriptHashGetter interface.
func (*VM) GetInvocationTree ¶ added in v0.98.0
func (v *VM) GetInvocationTree() *invocations.Tree
GetInvocationTree returns the current invocation tree structure.
func (*VM) HasFailed ¶
func (v *VM) HasFailed() bool
HasFailed returns whether the VM is in the failed state now. Usually, it's used to check status after Run.
func (*VM) HasHalted ¶
func (v *VM) HasHalted() bool
HasHalted returns whether the VM is in the Halt state.
func (*VM) HasStopped ¶
func (v *VM) HasStopped() bool
HasStopped returns whether the VM is in the Halt or Failed state.
func (*VM) Istack ¶
func (v *VM) Istack() *Stack
Istack returns the invocation stack, so interop hooks can utilize this.
func (*VM) LoadFileWithFlags ¶ added in v0.95.1
func (v *VM) LoadFileWithFlags(path string, f callflag.CallFlag) error
LoadFileWithFlags loads a program in NEF format from the given path, ready to execute it.
func (*VM) LoadNEFMethod ¶ added in v0.98.0
func (v *VM) LoadNEFMethod(exe *nef.File, caller util.Uint160, hash util.Uint160, f callflag.CallFlag,
hasReturn bool, methodOff int, initOff int, onContextUnload ContextUnloadCallback)
LoadNEFMethod allows to create a context to execute a method from the NEF file with the specified caller and executing hash, call flags, return value, method and _initialize offsets.
func (*VM) LoadScript ¶
func (v *VM) LoadScript(b []byte)
LoadScript loads a script from the internal script table. It will immediately push a new context created from this script to the invocation stack and starts executing it.
func (*VM) LoadScriptWithFlags ¶ added in v0.90.0
func (v *VM) LoadScriptWithFlags(b []byte, f callflag.CallFlag)
LoadScriptWithFlags loads script and sets call flag to f.
func (*VM) LoadScriptWithHash ¶ added in v0.90.0
func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160, f callflag.CallFlag)
LoadScriptWithHash is similar to the LoadScriptWithFlags method, but it also loads the given script hash directly into the Context to avoid its recalculations and to make it possible to override it for deployed contracts with special hashes (the function assumes that it is used for deployed contracts setting context's parameters accordingly). It's up to the user of this function to make sure the script and hash match each other.
func (*VM) LoadWithFlags ¶ added in v0.95.1
func (v *VM) LoadWithFlags(prog []byte, f callflag.CallFlag)
LoadWithFlags initializes the VM with the program and flags given.
func (*VM) PopResult ¶
func (v *VM) PopResult() interface{}
PopResult is used to pop the first item of the evaluation stack. This allows us to test the compiler and the vm in a bi-directional way.
func (*VM) PrintOps ¶
func (v *VM) PrintOps(out io.Writer)
PrintOps prints the opcodes of the current loaded program to stdout.
func (*VM) PushContextScriptHash ¶ added in v0.90.0
func (v *VM) PushContextScriptHash(n int) error
PushContextScriptHash pushes the script hash of the invocation stack element number n to the evaluation stack.
func (*VM) Ready ¶
func (v *VM) Ready() bool
Ready returns true if the VM is ready to execute the loaded program. It will return false if no program is loaded.
func (*VM) Reset ¶ added in v0.99.1
func (v *VM) Reset(t trigger.Type)
Reset allows to reuse existing VM for subsequent executions making them somewhat more efficient. It reuses invocation and evaluation stacks as well as VM structure itself.
func (*VM) SetPriceGetter ¶
func (v *VM) SetPriceGetter(f func(opcode.Opcode, []byte) int64)
SetPriceGetter registers the given PriceGetterFunc in v. f accepts vm's Context, current instruction and instruction parameter.
func (*VM) StepInto ¶
func (v *VM) StepInto() error
StepInto behaves the same as “step over” in case the line does not contain a function. Otherwise, the debugger will enter the called function and continue line-by-line debugging there.