neovm

package
v0.0.0-...-640f24c Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2018 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright 2016 The DNA Dev team

The go-vm library is free software: you can redistribute it and/or modify it under the terms of the APACHA License

package vm implemented a blockchain virtual machine, which provide following main functionaries:

- opcode VM support the logic of opcode script - apiservice for external interaction API with triggered by opcode - crypto for external crypto implementations with triggered by opcode -

Index

Constants

View Source
const (
	Stack_LIMIT               uint32 = 2 * 1024
	MAX_INVOCATION_STACK_SIZE        = 1024
	MAX_SIZE_FOR_BIGINTEGER          = 32
	MAX_ITEN_SIZE             uint32 = 1024 * 1024
	MAX_ARRAY_SIZE            uint32 = 1024
)

Variables

View Source
var (
	OpExecList = [256]OpExec{

		PUSH0:       {Opcode: PUSH0, Name: "PUSH0", Exec: opPushData},
		PUSHBYTES1:  {Opcode: PUSHBYTES1, Name: "PUSHBYTES1", Exec: opPushData},
		PUSHBYTES75: {Opcode: PUSHBYTES75, Name: "PUSHBYTES75", Exec: opPushData},
		PUSHDATA1:   {Opcode: PUSHDATA1, Name: "PUSHDATA1", Exec: opPushData},
		PUSHDATA2:   {Opcode: PUSHDATA2, Name: "PUSHDATA2", Exec: opPushData},
		PUSHDATA4:   {Opcode: PUSHDATA4, Name: "PUSHDATA4", Exec: opPushData, Validator: validatorPushData4},
		PUSHM1:      {Opcode: PUSHM1, Name: "PUSHM1", Exec: opPushData},
		PUSH1:       {Opcode: PUSH1, Name: "PUSH1", Exec: opPushData},
		PUSH2:       {Opcode: PUSH2, Name: "PUSH2", Exec: opPushData},
		PUSH3:       {Opcode: PUSH3, Name: "PUSH3", Exec: opPushData},
		PUSH4:       {Opcode: PUSH4, Name: "PUSH4", Exec: opPushData},
		PUSH5:       {Opcode: PUSH5, Name: "PUSH5", Exec: opPushData},
		PUSH6:       {Opcode: PUSH6, Name: "PUSH6", Exec: opPushData},
		PUSH7:       {Opcode: PUSH7, Name: "PUSH7", Exec: opPushData},
		PUSH8:       {Opcode: PUSH8, Name: "PUSH8", Exec: opPushData},
		PUSH9:       {Opcode: PUSH9, Name: "PUSH9", Exec: opPushData},
		PUSH10:      {Opcode: PUSH10, Name: "PUSH10", Exec: opPushData},
		PUSH11:      {Opcode: PUSH11, Name: "PUSH11", Exec: opPushData},
		PUSH12:      {Opcode: PUSH12, Name: "PUSH12", Exec: opPushData},
		PUSH13:      {Opcode: PUSH13, Name: "PUSH13", Exec: opPushData},
		PUSH14:      {Opcode: PUSH14, Name: "PUSH14", Exec: opPushData},
		PUSH15:      {Opcode: PUSH15, Name: "PUSH15", Exec: opPushData},
		PUSH16:      {Opcode: PUSH16, Name: "PUSH16", Exec: opPushData},

		NOP:      {Opcode: NOP, Name: "NOP", Exec: opNop},
		JMP:      {Opcode: JMP, Name: "JMP", Exec: opJmp},
		JMPIF:    {Opcode: JMPIF, Name: "JMPIF", Exec: opJmp},
		JMPIFNOT: {Opcode: JMPIFNOT, Name: "JMPIFNOT", Exec: opJmp},
		CALL:     {Opcode: CALL, Name: "CALL", Exec: opCall, Validator: validateCall},
		RET:      {Opcode: RET, Name: "RET", Exec: opRet},
		APPCALL:  {Opcode: APPCALL, Name: "APPCALL", Exec: opAppCall, Validator: validateAppCall},
		TAILCALL: {Opcode: TAILCALL, Name: "TAILCALL", Exec: opAppCall},
		SYSCALL:  {Opcode: SYSCALL, Name: "SYSCALL", Exec: opSysCall, Validator: validateSysCall},

		DUPFROMALTSTACK: {Opcode: DUPFROMALTSTACK, Name: "DUPFROMALTSTACK", Exec: opToDupFromAltStack},
		TOALTSTACK:      {Opcode: TOALTSTACK, Name: "TOALTSTACK", Exec: opToAltStack},
		FROMALTSTACK:    {Opcode: FROMALTSTACK, Name: "FROMALTSTACK", Exec: opFromAltStack},
		XDROP:           {Opcode: XDROP, Name: "XDROP", Exec: opXDrop, Validator: validateXDrop},
		XSWAP:           {Opcode: XSWAP, Name: "XSWAP", Exec: opXSwap, Validator: validateXSwap},
		XTUCK:           {Opcode: XTUCK, Name: "XTUCK", Exec: opXTuck, Validator: validateXTuck},
		DEPTH:           {Opcode: DEPTH, Name: "DEPTH", Exec: opDepth},
		DROP:            {Opcode: DROP, Name: "DROP", Exec: opDrop, Validator: validateCount1},
		DUP:             {Opcode: DUP, Name: "DUP", Exec: opDup},
		NIP:             {Opcode: NIP, Name: "NIP", Exec: opNip, Validator: validateCount2},
		OVER:            {Opcode: OVER, Name: "OVER", Exec: opOver, Validator: validateCount2},
		PICK:            {Opcode: PICK, Name: "PICK", Exec: opPick, Validator: validatePick},
		ROLL:            {Opcode: ROLL, Name: "ROLL", Exec: opRoll, Validator: validateRoll},
		ROT:             {Opcode: ROT, Name: "ROT", Exec: opRot, Validator: validateCount3},
		SWAP:            {Opcode: SWAP, Name: "SWAP", Exec: opSwap, Validator: validateCount2},
		TUCK:            {Opcode: TUCK, Name: "TUCK", Exec: opTuck, Validator: validateCount2},

		CAT:    {Opcode: CAT, Name: "CAT", Exec: opCat, Validator: validateCat},
		SUBSTR: {Opcode: SUBSTR, Name: "SUBSTR", Exec: opSubStr, Validator: validateSubStr},
		LEFT:   {Opcode: LEFT, Name: "LEFT", Exec: opLeft, Validator: validateLeft},
		RIGHT:  {Opcode: RIGHT, Name: "RIGHT", Exec: opRight, Validator: validateRight},
		SIZE:   {Opcode: SIZE, Name: "SIZE", Exec: opSize, Validator: validateCount1},

		INVERT: {Opcode: INVERT, Name: "INVERT", Exec: opInvert, Validator: validateCount1},
		AND:    {Opcode: AND, Name: "AND", Exec: opBigIntZip, Validator: validateCount2},
		OR:     {Opcode: OR, Name: "OR", Exec: opBigIntZip, Validator: validateCount2},
		XOR:    {Opcode: XOR, Name: "XOR", Exec: opBigIntZip, Validator: validateCount2},
		EQUAL:  {Opcode: EQUAL, Name: "EQUAL", Exec: opEqual, Validator: validateCount2},

		INC:         {Opcode: INC, Name: "INC", Exec: opBigInt, Validator: validateInc},
		DEC:         {Opcode: DEC, Name: "DEC", Exec: opBigInt, Validator: validateDec},
		SIGN:        {Opcode: SIGN, Name: "SIGN", Exec: opSign, Validator: validateSign},
		NEGATE:      {Opcode: NEGATE, Name: "NEGATE", Exec: opBigInt, Validator: validateCount1},
		ABS:         {Opcode: ABS, Name: "ABS", Exec: opBigInt, Validator: validateCount1},
		NOT:         {Opcode: NOT, Name: "NOT", Exec: opNot, Validator: validateCount1},
		NZ:          {Opcode: NZ, Name: "NZ", Exec: opNz, Validator: validateCount1},
		ADD:         {Opcode: ADD, Name: "ADD", Exec: opBigIntZip, Validator: validateAdd},
		SUB:         {Opcode: SUB, Name: "SUB", Exec: opBigIntZip, Validator: validateSub},
		MUL:         {Opcode: MUL, Name: "MUL", Exec: opBigIntZip, Validator: validateMul},
		DIV:         {Opcode: DIV, Name: "DIV", Exec: opBigIntZip, Validator: validateDiv},
		MOD:         {Opcode: MOD, Name: "MOD", Exec: opBigIntZip, Validator: validateMod},
		SHL:         {Opcode: SHL, Name: "SHL", Exec: opBigIntZip, Validator: validateShiftLeft},
		SHR:         {Opcode: SHR, Name: "SHR", Exec: opBigIntZip, Validator: validateShift},
		BOOLAND:     {Opcode: BOOLAND, Name: "BOOLAND", Exec: opBoolZip, Validator: validateCount2},
		BOOLOR:      {Opcode: BOOLOR, Name: "BOOLOR", Exec: opBoolZip, Validator: validateCount2},
		NUMEQUAL:    {Opcode: NUMEQUAL, Name: "NUMEQUAL", Exec: opBigIntComp, Validator: validateCount2},
		NUMNOTEQUAL: {Opcode: NUMNOTEQUAL, Name: "NUMNOTEQUAL", Exec: opBigIntComp, Validator: validateCount2},
		LT:          {Opcode: LT, Name: "LT", Exec: opBigIntComp, Validator: validateCount2},
		GT:          {Opcode: GT, Name: "GT", Exec: opBigIntComp, Validator: validateCount2},
		LTE:         {Opcode: LTE, Name: "LTE", Exec: opBigIntComp, Validator: validateCount2},
		GTE:         {Opcode: GTE, Name: "GTE", Exec: opBigIntComp, Validator: validateCount2},
		MIN:         {Opcode: MIN, Name: "MIN", Exec: opBigIntZip, Validator: validateCount2},
		MAX:         {Opcode: MAX, Name: "MAX", Exec: opBigIntZip, Validator: validateCount2},
		WITHIN:      {Opcode: WITHIN, Name: "WITHIN", Exec: opWithIn, Validator: validateCount3},

		SHA1:          {Opcode: SHA1, Name: "SHA1", Exec: opHash, Validator: validateCount1},
		SHA256:        {Opcode: SHA256, Name: "SHA256", Exec: opHash, Validator: validateCount1},
		HASH160:       {Opcode: HASH160, Name: "HASH160", Exec: opHash, Validator: validateCount1},
		HASH256:       {Opcode: HASH256, Name: "HASH256", Exec: opHash, Validator: validateCount1},
		CHECKSIG:      {Opcode: CHECKSIG, Name: "CHECKSIG", Exec: opCheckSig, Validator: validateCount2},
		CHECKMULTISIG: {Opcode: CHECKMULTISIG, Name: "CHECKMULTISIG", Exec: opCheckMultiSig, Validator: validateCount2},

		ARRAYSIZE: {Opcode: ARRAYSIZE, Name: "ARRAYSIZE", Exec: opArraySize, Validator: validateCount1},
		PACK:      {Opcode: PACK, Name: "PACK", Exec: opPack, Validator: validatePack},
		UNPACK:    {Opcode: UNPACK, Name: "UNPACK", Exec: opUnpack, Validator: validateUnpack},
		PICKITEM:  {Opcode: PICKITEM, Name: "PICKITEM", Exec: opPickItem, Validator: validatePickItem},
		SETITEM:   {Opcode: SETITEM, Name: "SETITEM", Exec: opSetItem, Validator: validatorSetItem},
		NEWARRAY:  {Opcode: NEWARRAY, Name: "NEWARRAY", Exec: opNewArray, Validator: validateNewArray},
		NEWSTRUCT: {Opcode: NEWSTRUCT, Name: "NEWSTRUCT", Exec: opNewStruct, Validator: validateNewStruct},
		APPEND:    {Opcode: APPEND, Name: "APPEND", Exec: opAppend, Validator: validateAppend},
		REVERSE:   {Opcode: REVERSE, Name: "REVERSE", Exec: opReverse, Validator: validatorReverse},

		THROW:      {Opcode: THROW, Name: "THROW", Exec: opThrow},
		THROWIFNOT: {Opcode: THROWIFNOT, Name: "THROWIFNOT", Exec: opThrowIfNot, Validator: validatorThrowIfNot},
	}
)

Functions

func BigIntComp

func BigIntComp(bigint *big.Int, op OpCode) bool

func BigIntMultiComp

func BigIntMultiComp(ints1 *big.Int, ints2 *big.Int, op OpCode) bool

func BigIntOp

func BigIntOp(bi *big.Int, op OpCode) *big.Int

func BigIntZip

func BigIntZip(ints1 *big.Int, ints2 *big.Int, op OpCode) *big.Int

func BoolZip

func BoolZip(bi1 bool, bi2 bool, op OpCode) bool

func CheckBigInteger

func CheckBigInteger(value *big.Int) bool

func Concat

func Concat(array1 []byte, array2 []byte) []byte

func Count

func Count(e *ExecutionEngine) int

func EvaluationStackCount

func EvaluationStackCount(e *ExecutionEngine) int

func Hash

func Hash(b []byte, e *ExecutionEngine) []byte

func LogStackTrace

func LogStackTrace(e *ExecutionEngine, needStackCount int, desc string) error

func NewStackItemInterface

func NewStackItemInterface(data interface{}) types.StackItems

func NewStackItems

func NewStackItems() []types.StackItems

func PeekArray

func PeekArray(e *ExecutionEngine) []types.StackItems

func PeekBigInteger

func PeekBigInteger(e *ExecutionEngine) *big.Int

func PeekInt

func PeekInt(e *ExecutionEngine) int

func PeekInteropInterface

func PeekInteropInterface(e *ExecutionEngine) interfaces.Interop

func PeekNBigInt

func PeekNBigInt(i int, e *ExecutionEngine) *big.Int

func PeekNByteArray

func PeekNByteArray(i int, e *ExecutionEngine) []byte

func PeekNInt

func PeekNInt(i int, e *ExecutionEngine) int

func PeekNStackItem

func PeekNStackItem(i int, e *ExecutionEngine) types.StackItems

func PeekStackItem

func PeekStackItem(e *ExecutionEngine) types.StackItems

func PopArray

func PopArray(e *ExecutionEngine) []types.StackItems

func PopBigInt

func PopBigInt(e *ExecutionEngine) *big.Int

func PopBoolean

func PopBoolean(e *ExecutionEngine) bool

func PopByteArray

func PopByteArray(e *ExecutionEngine) []byte

func PopInt

func PopInt(e *ExecutionEngine) int

func PopInteropInterface

func PopInteropInterface(e *ExecutionEngine) interfaces.Interop

func PopStackItem

func PopStackItem(e *ExecutionEngine) types.StackItems

func Push

func Push(e *ExecutionEngine, element Element)

func PushData

func PushData(e *ExecutionEngine, data interface{})

func ToBigInt

func ToBigInt(data interface{}) *big.Int

func WithInOp

func WithInOp(int1 *big.Int, int2 *big.Int, int3 *big.Int) bool

Types

type BigIntSorter

type BigIntSorter []big.Int

func (BigIntSorter) Len

func (c BigIntSorter) Len() int

func (BigIntSorter) Less

func (c BigIntSorter) Less(i, j int) bool

func (BigIntSorter) Swap

func (c BigIntSorter) Swap(i, j int)

type ECDsaCrypto

type ECDsaCrypto struct {
}

func (*ECDsaCrypto) Hash160

func (c *ECDsaCrypto) Hash160(message []byte) []byte

func (*ECDsaCrypto) Hash256

func (c *ECDsaCrypto) Hash256(message []byte) []byte

func (*ECDsaCrypto) VerifySignature

func (c *ECDsaCrypto) VerifySignature(message []byte, signature []byte, pubkey []byte) (bool, error)

type Element

type Element interface {
	GetStackItem() types.StackItems
	GetExecutionContext() *ExecutionContext
}

func Peek

func Peek(e *ExecutionEngine) Element

func PeekN

func PeekN(i int, e *ExecutionEngine) Element

func Pop

func Pop(e *ExecutionEngine) Element

type ExecutionContext

type ExecutionContext struct {
	Code               []byte
	OpReader           *utils.VmReader
	PushOnly           bool
	BreakPoints        []uint
	InstructionPointer int
	CodeHash           common.Address
	// contains filtered or unexported fields
}

func NewExecutionContext

func NewExecutionContext(engine *ExecutionEngine, code []byte, pushOnly bool, breakPoints []uint) *ExecutionContext

func (*ExecutionContext) Clone

func (ec *ExecutionContext) Clone() *ExecutionContext

func (*ExecutionContext) GetCodeHash

func (ec *ExecutionContext) GetCodeHash() (common.Address, error)

func (*ExecutionContext) GetExecutionContext

func (ec *ExecutionContext) GetExecutionContext() *ExecutionContext

func (*ExecutionContext) GetInstructionPointer

func (ec *ExecutionContext) GetInstructionPointer() int

func (*ExecutionContext) GetStackItem

func (ec *ExecutionContext) GetStackItem() types.StackItems

func (*ExecutionContext) NextInstruction

func (ec *ExecutionContext) NextInstruction() OpCode

func (*ExecutionContext) SetInstructionPointer

func (ec *ExecutionContext) SetInstructionPointer(offset int64)

type ExecutionEngine

type ExecutionEngine struct {
	// contains filtered or unexported fields
}

func NewExecutionEngine

func NewExecutionEngine(container interfaces.CodeContainer, crypto interfaces.Crypto, table interfaces.CodeTable, service InteropServices) *ExecutionEngine

func (*ExecutionEngine) AddBreakPoint

func (e *ExecutionEngine) AddBreakPoint(position uint)

func (*ExecutionEngine) Call

func (e *ExecutionEngine) Call(caller common.Address, code, input []byte) ([]byte, error)

func (*ExecutionEngine) CallingContext

func (e *ExecutionEngine) CallingContext() (*ExecutionContext, error)

func (*ExecutionEngine) Create

func (e *ExecutionEngine) Create(caller common.Address, code []byte) ([]byte, error)

func (*ExecutionEngine) CurrentContext

func (e *ExecutionEngine) CurrentContext() (*ExecutionContext, error)

func (*ExecutionEngine) EntryContext

func (e *ExecutionEngine) EntryContext() (*ExecutionContext, error)

func (*ExecutionEngine) Execute

func (e *ExecutionEngine) Execute() error

func (*ExecutionEngine) ExecuteOp

func (e *ExecutionEngine) ExecuteOp() (VMState, error)

func (*ExecutionEngine) GetCodeContainer

func (e *ExecutionEngine) GetCodeContainer() interfaces.CodeContainer

func (*ExecutionEngine) GetEvaluationStack

func (e *ExecutionEngine) GetEvaluationStack() *RandomAccessStack

func (*ExecutionEngine) GetEvaluationStackCount

func (e *ExecutionEngine) GetEvaluationStackCount() int

func (*ExecutionEngine) GetExecuteResult

func (e *ExecutionEngine) GetExecuteResult() bool

func (*ExecutionEngine) GetState

func (e *ExecutionEngine) GetState() VMState

func (*ExecutionEngine) LoadCode

func (e *ExecutionEngine) LoadCode(script []byte, pushOnly bool)

func (*ExecutionEngine) RemoveBreakPoint

func (e *ExecutionEngine) RemoveBreakPoint(position uint) bool

func (*ExecutionEngine) StepInto

func (e *ExecutionEngine) StepInto() error

func (*ExecutionEngine) StepOut

func (e *ExecutionEngine) StepOut()

func (*ExecutionEngine) StepOver

func (e *ExecutionEngine) StepOver()

type InteropService

type InteropService struct {
	// contains filtered or unexported fields
}

func NewInteropService

func NewInteropService() *InteropService

func (*InteropService) GetCallingCodeHash

func (i *InteropService) GetCallingCodeHash(engine *ExecutionEngine) (bool, error)

func (*InteropService) GetCodeContainer

func (i *InteropService) GetCodeContainer(engine *ExecutionEngine) (bool, error)

func (*InteropService) GetEntryCodeHash

func (i *InteropService) GetEntryCodeHash(engine *ExecutionEngine) (bool, error)

func (*InteropService) GetExecutingCodeHash

func (i *InteropService) GetExecutingCodeHash(engine *ExecutionEngine) (bool, error)

func (*InteropService) GetServiceMap

func (i *InteropService) GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)

func (*InteropService) Invoke

func (i *InteropService) Invoke(methodName string, engine *ExecutionEngine) (bool, error)

func (*InteropService) MergeMap

func (i *InteropService) MergeMap(dictionary map[string]func(*ExecutionEngine) (bool, error))

func (*InteropService) Register

func (is *InteropService) Register(methodName string, handler func(*ExecutionEngine) (bool, error)) bool

type InteropServices

type InteropServices interface {
	Register(method string, handler func(*ExecutionEngine) (bool, error)) bool
	GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)
}

type OpCode

type OpCode byte
const (
	// Constants
	PUSH0       OpCode = 0x00 // An empty array of bytes is pushed onto the stack.
	PUSHF       OpCode = PUSH0
	PUSHBYTES1  OpCode = 0x01 // 0x01-0x4B The next opcode bytes is data to be pushed onto the stack
	PUSHBYTES75 OpCode = 0x4B
	PUSHDATA1   OpCode = 0x4C // The next byte contains the number of bytes to be pushed onto the stack.
	PUSHDATA2   OpCode = 0x4D // The next two bytes contain the number of bytes to be pushed onto the stack.
	PUSHDATA4   OpCode = 0x4E // The next four bytes contain the number of bytes to be pushed onto the stack.
	PUSHM1      OpCode = 0x4F // The number -1 is pushed onto the stack.
	PUSH1       OpCode = 0x51 // The number 1 is pushed onto the stack.
	PUSHT       OpCode = PUSH1
	PUSH2       OpCode = 0x52 // The number 2 is pushed onto the stack.
	PUSH3       OpCode = 0x53 // The number 3 is pushed onto the stack.
	PUSH4       OpCode = 0x54 // The number 4 is pushed onto the stack.
	PUSH5       OpCode = 0x55 // The number 5 is pushed onto the stack.
	PUSH6       OpCode = 0x56 // The number 6 is pushed onto the stack.
	PUSH7       OpCode = 0x57 // The number 7 is pushed onto the stack.
	PUSH8       OpCode = 0x58 // The number 8 is pushed onto the stack.
	PUSH9       OpCode = 0x59 // The number 9 is pushed onto the stack.
	PUSH10      OpCode = 0x5A // The number 10 is pushed onto the stack.
	PUSH11      OpCode = 0x5B // The number 11 is pushed onto the stack.
	PUSH12      OpCode = 0x5C // The number 12 is pushed onto the stack.
	PUSH13      OpCode = 0x5D // The number 13 is pushed onto the stack.
	PUSH14      OpCode = 0x5E // The number 14 is pushed onto the stack.
	PUSH15      OpCode = 0x5F // The number 15 is pushed onto the stack.
	PUSH16      OpCode = 0x60 // The number 16 is pushed onto the stack.

	// Flow control
	NOP      OpCode = 0x61 // Does nothing.
	JMP      OpCode = 0x62
	JMPIF    OpCode = 0x63
	JMPIFNOT OpCode = 0x64
	CALL     OpCode = 0x65
	RET      OpCode = 0x66
	APPCALL  OpCode = 0x67
	SYSCALL  OpCode = 0x68
	TAILCALL OpCode = 0x69

	// Stack
	DUPFROMALTSTACK OpCode = 0x6A
	TOALTSTACK      OpCode = 0x6B // Puts the input onto the top of the alt stack. Removes it from the main stack.
	FROMALTSTACK    OpCode = 0x6C // Puts the input onto the top of the main stack. Removes it from the alt stack.
	XDROP           OpCode = 0x6D
	XSWAP           OpCode = 0x72
	XTUCK           OpCode = 0x73
	DEPTH           OpCode = 0x74 // Puts the number of stack items onto the stack.
	DROP            OpCode = 0x75 // Removes the top stack item.
	DUP             OpCode = 0x76 // Duplicates the top stack item.
	NIP             OpCode = 0x77 // Removes the second-to-top stack item.
	OVER            OpCode = 0x78 // Copies the second-to-top stack item to the top.
	PICK            OpCode = 0x79 // The item n back in the stack is copied to the top.
	ROLL            OpCode = 0x7A // The item n back in the stack is moved to the top.
	ROT             OpCode = 0x7B // The top three items on the stack are rotated to the left.
	SWAP            OpCode = 0x7C // The top two items on the stack are swapped.
	TUCK            OpCode = 0x7D // The item at the top of the stack is copied and inserted before the second-to-top item.

	// Splice
	CAT    OpCode = 0x7E // Concatenates two strings.
	SUBSTR OpCode = 0x7F // Returns a section of a string.
	LEFT   OpCode = 0x80 // Keeps only characters left of the specified point in a string.
	RIGHT  OpCode = 0x81 // Keeps only characters right of the specified point in a string.
	SIZE   OpCode = 0x82 // Returns the length of the input string.

	// Bitwise logic
	INVERT OpCode = 0x83 // Flips all of the bits in the input.
	AND    OpCode = 0x84 // Boolean and between each bit in the inputs.
	OR     OpCode = 0x85 // Boolean or between each bit in the inputs.
	XOR    OpCode = 0x86 // Boolean exclusive or between each bit in the inputs.
	EQUAL  OpCode = 0x87 // Returns 1 if the inputs are exactly equal, 0 otherwise.

	// Arithmetic
	// Note: Arithmetic inputs are limited to signed 32-bit integers, but may overflow their output.
	INC         OpCode = 0x8B // 1 is added to the input.
	DEC         OpCode = 0x8C // 1 is subtracted from the input.
	SIGN        OpCode = 0x8D
	NEGATE      OpCode = 0x8F // The sign of the input is flipped.
	ABS         OpCode = 0x90 // The input is made positive.
	NOT         OpCode = 0x91 // If the input is 0 or 1, it is flipped. Otherwise the output will be 0.
	NZ          OpCode = 0x92 // Returns 0 if the input is 0. 1 otherwise.
	ADD         OpCode = 0x93 // a is added to b.
	SUB         OpCode = 0x94 // b is subtracted from a.
	MUL         OpCode = 0x95 // a is multiplied by b.
	DIV         OpCode = 0x96 // a is divided by b.
	MOD         OpCode = 0x97 // Returns the remainder after dividing a by b.
	SHL         OpCode = 0x98 // Shifts a left b bits, preserving sign.
	SHR         OpCode = 0x99 // Shifts a right b bits, preserving sign.
	BOOLAND     OpCode = 0x9A // If both a and b are not 0, the output is 1. Otherwise 0.
	BOOLOR      OpCode = 0x9B // If a or b is not 0, the output is 1. Otherwise 0.
	NUMEQUAL    OpCode = 0x9C // Returns 1 if the numbers are equal, 0 otherwise.
	NUMNOTEQUAL OpCode = 0x9E // Returns 1 if the numbers are not equal, 0 otherwise.
	LT          OpCode = 0x9F // Returns 1 if a is less than b, 0 otherwise.
	GT          OpCode = 0xA0 // Returns 1 if a is greater than b, 0 otherwise.
	LTE         OpCode = 0xA1 // Returns 1 if a is less than or equal to b, 0 otherwise.
	GTE         OpCode = 0xA2 // Returns 1 if a is greater than or equal to b, 0 otherwise.
	MIN         OpCode = 0xA3 // Returns the smaller of a and b.
	MAX         OpCode = 0xA4 // Returns the larger of a and b.
	WITHIN      OpCode = 0xA5 // Returns 1 if x is within the specified range (left-inclusive), 0 otherwise.

	// Crypto
	//RIPEMD160 = 0xA6 // The input is hashed using RIPEMD-160.
	SHA1          OpCode = 0xA7 // The input is hashed using SHA-1.
	SHA256        OpCode = 0xA8 // The input is hashed using SHA-256.
	HASH160       OpCode = 0xA9
	HASH256       OpCode = 0xAA
	CHECKSIG      OpCode = 0xAC // The entire transaction's outputs inputs and script (from the most recently-executed CODESEPARATOR to the end) are hashed. The signature used by CHECKSIG must be a valid signature for this hash and public key. If it is 1 is returned 0 otherwise.
	CHECKMULTISIG OpCode = 0xAE // For each signature and public key pair CHECKSIG is executed. If more public keys than signatures are listed some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid 1 is returned 0 otherwise. Due to a bug one extra unused value is removed from the stack.

	// Array
	ARRAYSIZE OpCode = 0xC0
	PACK      OpCode = 0xC1
	UNPACK    OpCode = 0xC2
	PICKITEM  OpCode = 0xC3
	SETITEM   OpCode = 0xC4
	NEWARRAY  OpCode = 0xC5
	NEWSTRUCT        = 0xC6
	APPEND    OpCode = 0xC8
	REVERSE   OpCode = 0xC9

	//Exception
	THROW      = 0xF0
	THROWIFNOT = 0xF1
)

type OpExec

type OpExec struct {
	Opcode    OpCode
	Name      string
	Exec      func(*ExecutionEngine) (VMState, error)
	Validator func(*ExecutionEngine) error
}

type ParamsBuilder

type ParamsBuilder struct {
	// contains filtered or unexported fields
}

func NewParamsBuilder

func NewParamsBuilder(buffer *bytes.Buffer) *ParamsBuilder

func (*ParamsBuilder) Emit

func (p *ParamsBuilder) Emit(op OpCode)

func (*ParamsBuilder) EmitPushBool

func (p *ParamsBuilder) EmitPushBool(data bool)

func (*ParamsBuilder) EmitPushByteArray

func (p *ParamsBuilder) EmitPushByteArray(data []byte)

func (*ParamsBuilder) EmitPushCall

func (p *ParamsBuilder) EmitPushCall(codeHash []byte)

func (*ParamsBuilder) EmitPushInteger

func (p *ParamsBuilder) EmitPushInteger(data *big.Int)

func (*ParamsBuilder) ToArray

func (p *ParamsBuilder) ToArray() []byte

type RandomAccessStack

type RandomAccessStack struct {
	// contains filtered or unexported fields
}

func NewRandAccessStack

func NewRandAccessStack() *RandomAccessStack

func (*RandomAccessStack) Count

func (r *RandomAccessStack) Count() int

func (*RandomAccessStack) Insert

func (r *RandomAccessStack) Insert(index int, t Element)

func (*RandomAccessStack) Peek

func (r *RandomAccessStack) Peek(index int) Element

func (*RandomAccessStack) Pop

func (r *RandomAccessStack) Pop() Element

func (*RandomAccessStack) Push

func (r *RandomAccessStack) Push(t Element)

func (*RandomAccessStack) Remove

func (r *RandomAccessStack) Remove(index int) Element

func (*RandomAccessStack) Set

func (r *RandomAccessStack) Set(index int, t Element)

func (*RandomAccessStack) Swap

func (r *RandomAccessStack) Swap(i, j int)

type StackItem

type StackItem struct {
	// contains filtered or unexported fields
}

func NewStackItem

func NewStackItem(object types.StackItems) *StackItem

func (*StackItem) GetExecutionContext

func (s *StackItem) GetExecutionContext() *ExecutionContext

func (*StackItem) GetStackItem

func (s *StackItem) GetStackItem() types.StackItems

type VMState

type VMState byte
const (
	NONE  VMState = 0
	HALT  VMState = 1 << 0
	FAULT VMState = 1 << 1
	BREAK VMState = 1 << 2

	INSUFFICIENT_RESOURCE VMState = 1 << 4
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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