Documentation ¶
Index ¶
- Constants
- func Emit(w *bytes.Buffer, op Instruction, b []byte) error
- func EmitAppCall(w *bytes.Buffer, scriptHash util.Uint160, tailCall bool) error
- func EmitAppCallWithOperation(w *bytes.Buffer, scriptHash util.Uint160, operation string) error
- func EmitAppCallWithOperationAndData(w *bytes.Buffer, scriptHash util.Uint160, operation string, data []byte) error
- func EmitBool(w io.ByteWriter, ok bool) error
- func EmitBytes(w *bytes.Buffer, b []byte) error
- func EmitCall(w *bytes.Buffer, op Instruction, label int16) error
- func EmitInt(w *bytes.Buffer, i int64) error
- func EmitJmp(w *bytes.Buffer, op Instruction, label int16) error
- func EmitOpcode(w io.ByteWriter, op Instruction) error
- func EmitString(w *bytes.Buffer, s string) error
- func EmitSyscall(w *bytes.Buffer, api string) error
- func IsMultiSigContract(script []byte) bool
- func IsSignatureContract(script []byte) bool
- func IsStandardContract(script []byte) bool
- type ArrayItem
- type BigIntegerItem
- type BoolItem
- type ByteArrayItem
- type Context
- func (c *Context) Copy() *Context
- func (c *Context) CurrInstr() (int, Instruction)
- func (c *Context) IP() int
- func (c *Context) LenInstr() int
- func (c *Context) Next() (Instruction, []byte, error)
- func (c *Context) Program() []byte
- func (c *Context) String() string
- func (c *Context) Value() interface{}
- type Element
- type Instruction
- type InteropFunc
- type InteropFuncPrice
- type InteropItem
- type MapItem
- 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) *Element
- func (s *Stack) Iter(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) Push(e *Element)
- func (s *Stack) PushVal(v interface{})
- func (s *Stack) Remove(e *Element) *Element
- func (s *Stack) RemoveAt(n int) *Element
- func (s *Stack) Top() *Element
- type StackItem
- type State
- type StateMessage
- type StructItem
- type VM
- func (v *VM) AddBreakPoint(n int)
- func (v *VM) AddBreakPointRel(n int)
- func (v *VM) Astack() *Stack
- func (v *VM) AtBreakpoint() bool
- func (v *VM) Context() *Context
- func (v *VM) Estack() *Stack
- 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) LoadArgs(method []byte, args []StackItem)
- func (v *VM) LoadFile(path string) error
- func (v *VM) LoadScript(b []byte)
- func (v *VM) PopResult() interface{}
- func (v *VM) PrintOps()
- func (v *VM) Ready() bool
- func (v *VM) RegisterInteropFunc(name string, f InteropFunc, price int)
- func (v *VM) RegisterInteropFuncs(interops map[string]InteropFuncPrice)
- func (v *VM) Run() error
- func (v *VM) SetCheckedHash(h []byte)
- func (v *VM) SetScriptGetter(gs func(util.Uint160) []byte)
- func (v *VM) Stack(n string) string
- func (v *VM) State() string
- func (v *VM) Step() error
- func (v *VM) StepInto() error
- func (v *VM) StepOut() error
- func (v *VM) StepOver() error
Constants ¶
const ( // MaxArraySize is the maximum array size allowed in the VM. MaxArraySize = 1024 // MaxItemSize is the maximum item size allowed in the VM. MaxItemSize = 1024 * 1024 // MaxInvocationStackSize is the maximum size of an invocation stack. MaxInvocationStackSize = 1024 )
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
func Emit(w *bytes.Buffer, op Instruction, b []byte) error
Emit a VM Instruction with data to the given buffer.
func EmitAppCall ¶
EmitAppCall emits an appcall, if tailCall is true, tailCall opcode will be emitted instead.
func EmitAppCallWithOperation ¶
EmitAppCallWithOperation emits an appcall with the given operation.
func EmitAppCallWithOperationAndData ¶
func EmitAppCallWithOperationAndData(w *bytes.Buffer, scriptHash util.Uint160, operation string, data []byte) error
EmitAppCallWithOperationAndData emits an appcall with the given operation and data.
func EmitBool ¶
func EmitBool(w io.ByteWriter, ok bool) error
EmitBool emits a bool type the given buffer.
func EmitCall ¶
func EmitCall(w *bytes.Buffer, op Instruction, label int16) error
EmitCall emits a call Instruction with label to the given buffer.
func EmitJmp ¶
func EmitJmp(w *bytes.Buffer, op Instruction, label int16) error
EmitJmp emits a jump Instruction along with label to the given buffer.
func EmitOpcode ¶
func EmitOpcode(w io.ByteWriter, op Instruction) error
EmitOpcode emits a single VM Instruction the given buffer.
func EmitString ¶
EmitString emits a string to the given buffer.
func EmitSyscall ¶
EmitSyscall emits the syscall API to the given buffer. Syscall API string cannot be 0.
func IsMultiSigContract ¶ added in v0.51.0
IsMultiSigContract checks whether the passed script is a multi-signature contract.
func IsSignatureContract ¶ added in v0.51.0
IsSignatureContract checks whether the passed script is a signature check contract.
func IsStandardContract ¶ added in v0.51.0
IsStandardContract checks whether the passed script is a signature or multi-signature contract.
Types ¶
type ArrayItem ¶
type ArrayItem struct {
// contains filtered or unexported fields
}
ArrayItem represents a new ArrayItem object.
func NewArrayItem ¶
NewArrayItem returns a new ArrayItem object.
func (*ArrayItem) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type BigIntegerItem ¶
type BigIntegerItem struct {
// contains filtered or unexported fields
}
BigIntegerItem represents a big integer on the stack.
func NewBigIntegerItem ¶
func NewBigIntegerItem(value int) *BigIntegerItem
NewBigIntegerItem returns an new BigIntegerItem object.
func (*BigIntegerItem) MarshalJSON ¶
func (i *BigIntegerItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*BigIntegerItem) String ¶
func (i *BigIntegerItem) String() string
func (*BigIntegerItem) Value ¶
func (i *BigIntegerItem) Value() interface{}
Value implements StackItem interface.
type BoolItem ¶
type BoolItem struct {
// contains filtered or unexported fields
}
BoolItem represents a boolean StackItem.
func (*BoolItem) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type ByteArrayItem ¶
type ByteArrayItem struct {
// contains filtered or unexported fields
}
ByteArrayItem represents a byte array on the stack.
func NewByteArrayItem ¶
func NewByteArrayItem(b []byte) *ByteArrayItem
NewByteArrayItem returns an new ByteArrayItem object.
func (*ByteArrayItem) MarshalJSON ¶
func (i *ByteArrayItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*ByteArrayItem) String ¶
func (i *ByteArrayItem) String() string
func (*ByteArrayItem) Value ¶
func (i *ByteArrayItem) Value() interface{}
Value implements StackItem interface.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the current execution context of the VM.
func (*Context) CurrInstr ¶
func (c *Context) CurrInstr() (int, Instruction)
CurrInstr returns the current instruction and opcode.
func (*Context) IP ¶
IP returns the absolute instruction without taking 0 into account. If that program starts the ip = 0 but IP() will return 1, cause its the first instruction.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents an element in the double linked list (the stack), which will hold the underlying StackItem.
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 ¶
Array attempts to get the underlying value of the element as an array of other items. Will panic if the item type is different which will be caught by the VM.
func (*Element) BigInt ¶
BigInt attempts to get the underlying value of the element as a big integer. Will panic if the assertion failed which will be caught by the VM.
func (*Element) Bool ¶
Bool attempts to get the underlying value of the element as a boolean. Will panic if the assertion failed which will be caught by the VM.
func (*Element) Bytes ¶
Bytes attempts to get the underlying value of the element as a byte array. Will panic if the assertion failed which will be caught by the VM.
type Instruction ¶
type Instruction byte
Instruction represents an single operation for the NEO virtual machine.
const ( // Constants PUSH0 Instruction = 0x00 PUSHF Instruction = PUSH0 PUSHBYTES1 Instruction = 0x01 PUSHBYTES2 Instruction = 0x02 PUSHBYTES3 Instruction = 0x03 PUSHBYTES4 Instruction = 0x04 PUSHBYTES5 Instruction = 0x05 PUSHBYTES6 Instruction = 0x06 PUSHBYTES7 Instruction = 0x07 PUSHBYTES8 Instruction = 0x08 PUSHBYTES9 Instruction = 0x09 PUSHBYTES10 Instruction = 0x0A PUSHBYTES11 Instruction = 0x0B PUSHBYTES12 Instruction = 0x0C PUSHBYTES13 Instruction = 0x0D PUSHBYTES14 Instruction = 0x0E PUSHBYTES15 Instruction = 0x0F PUSHBYTES16 Instruction = 0x10 PUSHBYTES17 Instruction = 0x11 PUSHBYTES18 Instruction = 0x12 PUSHBYTES19 Instruction = 0x13 PUSHBYTES20 Instruction = 0x14 PUSHBYTES21 Instruction = 0x15 PUSHBYTES22 Instruction = 0x16 PUSHBYTES23 Instruction = 0x17 PUSHBYTES24 Instruction = 0x18 PUSHBYTES25 Instruction = 0x19 PUSHBYTES26 Instruction = 0x1A PUSHBYTES27 Instruction = 0x1B PUSHBYTES28 Instruction = 0x1C PUSHBYTES29 Instruction = 0x1D PUSHBYTES30 Instruction = 0x1E PUSHBYTES31 Instruction = 0x1F PUSHBYTES32 Instruction = 0x20 PUSHBYTES33 Instruction = 0x21 PUSHBYTES34 Instruction = 0x22 PUSHBYTES35 Instruction = 0x23 PUSHBYTES36 Instruction = 0x24 PUSHBYTES37 Instruction = 0x25 PUSHBYTES38 Instruction = 0x26 PUSHBYTES39 Instruction = 0x27 PUSHBYTES40 Instruction = 0x28 PUSHBYTES41 Instruction = 0x29 PUSHBYTES42 Instruction = 0x2A PUSHBYTES43 Instruction = 0x2B PUSHBYTES44 Instruction = 0x2C PUSHBYTES45 Instruction = 0x2D PUSHBYTES46 Instruction = 0x2E PUSHBYTES47 Instruction = 0x2F PUSHBYTES48 Instruction = 0x30 PUSHBYTES49 Instruction = 0x31 PUSHBYTES50 Instruction = 0x32 PUSHBYTES51 Instruction = 0x33 PUSHBYTES52 Instruction = 0x34 PUSHBYTES53 Instruction = 0x35 PUSHBYTES54 Instruction = 0x36 PUSHBYTES55 Instruction = 0x37 PUSHBYTES56 Instruction = 0x38 PUSHBYTES57 Instruction = 0x39 PUSHBYTES58 Instruction = 0x3A PUSHBYTES59 Instruction = 0x3B PUSHBYTES60 Instruction = 0x3C PUSHBYTES61 Instruction = 0x3D PUSHBYTES62 Instruction = 0x3E PUSHBYTES63 Instruction = 0x3F PUSHBYTES64 Instruction = 0x40 PUSHBYTES65 Instruction = 0x41 PUSHBYTES66 Instruction = 0x42 PUSHBYTES67 Instruction = 0x43 PUSHBYTES68 Instruction = 0x44 PUSHBYTES69 Instruction = 0x45 PUSHBYTES70 Instruction = 0x46 PUSHBYTES71 Instruction = 0x47 PUSHBYTES72 Instruction = 0x48 PUSHBYTES73 Instruction = 0x49 PUSHBYTES74 Instruction = 0x4A PUSHBYTES75 Instruction = 0x4B PUSHDATA1 Instruction = 0x4C PUSHDATA2 Instruction = 0x4D PUSHDATA4 Instruction = 0x4E PUSHM1 Instruction = 0x4F PUSH1 Instruction = 0x51 PUSHT Instruction = PUSH1 PUSH2 Instruction = 0x52 PUSH3 Instruction = 0x53 PUSH4 Instruction = 0x54 PUSH5 Instruction = 0x55 PUSH6 Instruction = 0x56 PUSH7 Instruction = 0x57 PUSH8 Instruction = 0x58 PUSH9 Instruction = 0x59 PUSH10 Instruction = 0x5A PUSH11 Instruction = 0x5B PUSH12 Instruction = 0x5C PUSH13 Instruction = 0x5D PUSH14 Instruction = 0x5E PUSH15 Instruction = 0x5F PUSH16 Instruction = 0x60 // Flow control NOP Instruction = 0x61 JMP Instruction = 0x62 JMPIF Instruction = 0x63 JMPIFNOT Instruction = 0x64 CALL Instruction = 0x65 RET Instruction = 0x66 APPCALL Instruction = 0x67 SYSCALL Instruction = 0x68 TAILCALL Instruction = 0x69 // Stack DUPFROMALTSTACK Instruction = 0x6A TOALTSTACK Instruction = 0x6B FROMALTSTACK Instruction = 0x6C XDROP Instruction = 0x6D XSWAP Instruction = 0x72 XTUCK Instruction = 0x73 DEPTH Instruction = 0x74 DROP Instruction = 0x75 DUP Instruction = 0x76 NIP Instruction = 0x77 OVER Instruction = 0x78 PICK Instruction = 0x79 ROLL Instruction = 0x7A ROT Instruction = 0x7B SWAP Instruction = 0x7C TUCK Instruction = 0x7D // Splice CAT Instruction = 0x7E SUBSTR Instruction = 0x7F LEFT Instruction = 0x80 RIGHT Instruction = 0x81 SIZE Instruction = 0x82 // Bitwise logic INVERT Instruction = 0x83 AND Instruction = 0x84 OR Instruction = 0x85 XOR Instruction = 0x86 EQUAL Instruction = 0x87 // Arithmetic INC Instruction = 0x8B DEC Instruction = 0x8C SIGN Instruction = 0x8D NEGATE Instruction = 0x8F ABS Instruction = 0x90 NOT Instruction = 0x91 NZ Instruction = 0x92 ADD Instruction = 0x93 SUB Instruction = 0x94 MUL Instruction = 0x95 DIV Instruction = 0x96 MOD Instruction = 0x97 SHL Instruction = 0x98 SHR Instruction = 0x99 BOOLAND Instruction = 0x9A BOOLOR Instruction = 0x9B NUMEQUAL Instruction = 0x9C NUMNOTEQUAL Instruction = 0x9E LT Instruction = 0x9F GT Instruction = 0xA0 LTE Instruction = 0xA1 GTE Instruction = 0xA2 MIN Instruction = 0xA3 MAX Instruction = 0xA4 WITHIN Instruction = 0xA5 // Crypto SHA1 Instruction = 0xA7 SHA256 Instruction = 0xA8 HASH160 Instruction = 0xA9 HASH256 Instruction = 0xAA CHECKSIG Instruction = 0xAC VERIFY Instruction = 0xAD CHECKMULTISIG Instruction = 0xAE // Advanced data structures (arrays, structures, maps) ARRAYSIZE Instruction = 0xC0 PACK Instruction = 0xC1 UNPACK Instruction = 0xC2 PICKITEM Instruction = 0xC3 SETITEM Instruction = 0xC4 NEWARRAY Instruction = 0xC5 NEWSTRUCT Instruction = 0xC6 NEWMAP Instruction = 0xC7 APPEND Instruction = 0xC8 REVERSE Instruction = 0xC9 REMOVE Instruction = 0xCA HASKEY Instruction = 0xCB KEYS Instruction = 0xCC VALUES Instruction = 0xCD // Stack isolation CALLI Instruction = 0xE0 CALLE Instruction = 0xE1 CALLED Instruction = 0xE2 CALLET Instruction = 0xE3 CALLEDT Instruction = 0xE4 // Exceptions THROW Instruction = 0xF0 THROWIFNOT Instruction = 0xF1 )
Viable list of supported instruction constants.
func (Instruction) String ¶
func (i Instruction) String() string
type InteropFuncPrice ¶ added in v0.51.0
type InteropFuncPrice struct { Func InteropFunc Price int }
InteropFuncPrice represents an interop function with a price.
type InteropItem ¶ added in v0.51.0
type InteropItem struct {
// contains filtered or unexported fields
}
InteropItem represents interop data on the stack.
func NewInteropItem ¶ added in v0.51.0
func NewInteropItem(value interface{}) *InteropItem
NewInteropItem returns new InteropItem object.
func (*InteropItem) MarshalJSON ¶ added in v0.51.0
func (i *InteropItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*InteropItem) String ¶ added in v0.51.0
func (i *InteropItem) String() string
String implements stringer interface.
func (*InteropItem) Value ¶ added in v0.51.0
func (i *InteropItem) Value() interface{}
Value implements StackItem interface.
type MapItem ¶ added in v0.51.0
type MapItem struct {
// contains filtered or unexported fields
}
MapItem represents Map object.
func NewMapItem ¶ added in v0.51.0
func NewMapItem() *MapItem
NewMapItem returns new MapItem object.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents a Stack backed by a double linked list.
func (*Stack) Clear ¶
func (s *Stack) Clear()
Clear clears all elements on the stack and set its length to 0.
func (*Stack) Dup ¶
Dup duplicates and returns the element at position n. Dup is used for copying elements on to the top of its own stack.
s.Push(s.Peek(0)) // will result in unexpected behaviour. s.Push(s.Dup(0)) // is the correct approach.
func (*Stack) InsertAt ¶
InsertAt inserts the given item (n) deep on the stack. Be very careful using it and _always_ check both e and n before invocation as it will silently do wrong things otherwise.
func (*Stack) Iter ¶
Iter iterates over all the elements int the stack, starting from the top of the stack.
s.Iter(func(elem *Element) { // do something with the element. })
func (*Stack) MarshalJSON ¶ added in v0.61.0
MarshalJSON implements JSON marshalling interface.
func (*Stack) Peek ¶
Peek returns the element (n) far in the stack beginning from the top of the stack.
n = 0 => will return the element on top of the stack.
func (*Stack) PushVal ¶
func (s *Stack) PushVal(v interface{})
PushVal pushes the given value on the stack. It will infer the underlying StackItem to its corresponding type.
type State ¶
type State uint8
State of the VM.
func StateFromString ¶
StateFromString converts string into the VM State.
func (State) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*State) UnmarshalJSON ¶
UnmarshalJSON implements the json.Marshaler interface.
type StateMessage ¶ added in v0.60.0
type StateMessage string
StateMessage is a vm state message which could be used as additional info for example by cli.
type StructItem ¶
type StructItem struct {
// contains filtered or unexported fields
}
StructItem represents a struct on the stack.
func NewStructItem ¶
func NewStructItem(items []StackItem) *StructItem
NewStructItem returns an new StructItem object.
func (*StructItem) Clone ¶ added in v0.51.0
func (i *StructItem) Clone() *StructItem
Clone returns a Struct with all Struct fields copied by value. Array fields are still copied by reference.
func (*StructItem) String ¶
func (i *StructItem) String() string
func (*StructItem) Value ¶
func (i *StructItem) Value() interface{}
Value implements StackItem interface.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM represents the virtual machine.
func (*VM) AddBreakPoint ¶
AddBreakPoint adds a breakpoint to the current context.
func (*VM) AddBreakPointRel ¶
AddBreakPointRel adds a breakpoint relative to the current instruction pointer.
func (*VM) AtBreakpoint ¶ added in v0.60.0
AtBreakpoint returns whether VM is at breakpoint.
func (*VM) Context ¶
Context returns the current executed context. Nil if there is no context, which implies no program is loaded.
func (*VM) HasFailed ¶ added in v0.51.0
HasFailed returns whether VM is in the failed state now. Usually used to check status after Run.
func (*VM) HasStopped ¶ added in v0.51.0
HasStopped returns whether VM is in Halt or Failed state.
func (*VM) LoadScript ¶
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) PopResult ¶
func (v *VM) PopResult() interface{}
PopResult is used to pop the first item of the evaluation stack. This allows us to test compiler and vm in a bi-directional way.
func (*VM) PrintOps ¶
func (v *VM) PrintOps()
PrintOps prints the opcodes of the current loaded program to stdout.
func (*VM) Ready ¶
Ready returns true if the VM ready to execute the loaded program. Will return false if no program is loaded.
func (*VM) RegisterInteropFunc ¶
func (v *VM) RegisterInteropFunc(name string, f InteropFunc, price int)
RegisterInteropFunc registers the given InteropFunc to the VM.
func (*VM) RegisterInteropFuncs ¶ added in v0.51.0
func (v *VM) RegisterInteropFuncs(interops map[string]InteropFuncPrice)
RegisterInteropFuncs registers all interop functions passed in a map in the VM. Effectively it's a batched version of RegisterInteropFunc.
func (*VM) SetCheckedHash ¶ added in v0.51.0
SetCheckedHash sets checked hash for CHECKSIG and CHECKMULTISIG instructions.
func (*VM) SetScriptGetter ¶ added in v0.51.0
SetScriptGetter sets the script getter for CALL instructions.
func (*VM) StepInto ¶ added in v0.51.0
StepInto behaves the same as “step over” in case if the line does not contain a function. Otherwise the debugger will enter the called function and continue line-by-line debugging there.