diff --git a/pkg/vm/vm_ops_bitwise.go b/pkg/vm/vm_ops_bitwise.go index 8c73ce25e..350543fa2 100644 --- a/pkg/vm/vm_ops_bitwise.go +++ b/pkg/vm/vm_ops_bitwise.go @@ -6,7 +6,7 @@ import "github.com/CityOfZion/neo-go/pkg/vm/stack" // EQUAL pushes true to the stack // If the two top items on the stack are equal -func EQUAL(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { +func EQUAL(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) { itemA, itemB, err := popTwoByteArrays(ctx) if err != nil { diff --git a/pkg/vm/vm_ops_exceptions.go b/pkg/vm/vm_ops_exceptions.go index bdf45dbfa..dd09cfb60 100644 --- a/pkg/vm/vm_ops_exceptions.go +++ b/pkg/vm/vm_ops_exceptions.go @@ -12,7 +12,7 @@ import ( // does not evaluate to true // For specific logic on how a number of bytearray is evaluated can be seen // from the boolean conversion methods on the stack items -func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { +func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) { // Pop item from top of stack item, err := ctx.Estack.Pop() @@ -27,7 +27,7 @@ func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocati // If false, throw if !ok.Value() { - return FAULT, errors.New("Item on top of stack evaluates to false") + return FAULT, errors.New("item on top of stack evaluates to false") } return NONE, nil } diff --git a/pkg/vm/vm_ops_flow.go b/pkg/vm/vm_ops_flow.go index 7a90638b0..67ca4f825 100644 --- a/pkg/vm/vm_ops_flow.go +++ b/pkg/vm/vm_ops_flow.go @@ -8,17 +8,19 @@ import ( // RET Returns from the current context // Returns HALT if there are nomore context's to run -func RET(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { +func RET(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) { // Pop current context from the Inovation stack - err := istack.RemoveCurrentContext() + ctx, err := istack.PopCurrentContext() if err != nil { return FAULT, err } - - // If there are no-more context's left to ran, then we HALT + // If this was the last context, then we copy over the evaluation stack to the resultstack + // As the program is about to terminate, once we remove the context if istack.Len() == 0 { - return HALT, nil + + err = ctx.Estack.CopyTo(rstack) + return HALT, err } return NONE, nil diff --git a/pkg/vm/vm_ops_maths.go b/pkg/vm/vm_ops_maths.go index 6085dccb8..a15596a30 100644 --- a/pkg/vm/vm_ops_maths.go +++ b/pkg/vm/vm_ops_maths.go @@ -7,7 +7,7 @@ import ( // Add adds two stack Items together. // Returns an error if either items cannot be casted to an integer // or if integers cannot be added together -func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { +func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) { operandA, operandB, err := popTwoIntegers(ctx) if err != nil { @@ -26,7 +26,7 @@ func Add(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vm // Sub subtracts two stack Items. // Returns an error if either items cannot be casted to an integer // or if integers cannot be subtracted together -func Sub(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { +func Sub(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) { operandA, operandB, err := popTwoIntegers(ctx) if err != nil { diff --git a/pkg/vm/vm_ops_stackmani.go b/pkg/vm/vm_ops_stackmani.go index 366beb15b..f5e2ddc24 100644 --- a/pkg/vm/vm_ops_stackmani.go +++ b/pkg/vm/vm_ops_stackmani.go @@ -7,7 +7,7 @@ import ( // Stack Manipulation Opcodes // PushNBytes will Read N Bytes from the script and push it onto the stack -func PushNBytes(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { +func PushNBytes(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) { val, err := ctx.ReadBytes(int(op)) if err != nil {