Merge pull request #1492 from nspcc-dev/minor-vm-fixes

Minor VM fixes
This commit is contained in:
Roman Khimov 2020-10-15 18:10:41 +03:00 committed by GitHub
commit 07770ea4a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -351,10 +351,11 @@ func (s *Stack) ReverseTop(n int) error {
return nil return nil
} }
for i, j := 0, n-1; i < j; { a, b := s.Peek(0), s.Peek(n-1)
s.swap(i, j) for i := 0; i < n/2; i++ {
i++ a.value, b.value = b.value, a.value
j-- a = a.Next()
b = b.Prev()
} }
return nil return nil
} }

View file

@ -273,6 +273,7 @@ func (v *VM) LoadScript(b []byte) {
// LoadScriptWithFlags loads script and sets call flag to f. // LoadScriptWithFlags loads script and sets call flag to f.
func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag) { func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag) {
v.checkInvocationStackSize()
ctx := NewContext(b) ctx := NewContext(b)
v.estack = v.newItemStack("estack") v.estack = v.newItemStack("estack")
ctx.estack = v.estack ctx.estack = v.estack
@ -1226,7 +1227,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
} }
case opcode.CALL, opcode.CALLL: case opcode.CALL, opcode.CALLL:
v.checkInvocationStackSize()
// Note: jump offset must be calculated regarding to new context, // Note: jump offset must be calculated regarding to new context,
// but it is cloned and thus has the same script and instruction pointer. // but it is cloned and thus has the same script and instruction pointer.
v.call(ctx, v.getJumpOffset(ctx, parameter)) v.call(ctx, v.getJumpOffset(ctx, parameter))
@ -1476,6 +1476,7 @@ func (v *VM) Call(ctx *Context, offset int) {
// affect the invocation counter and is only being used by vm // affect the invocation counter and is only being used by vm
// package. // package.
func (v *VM) call(ctx *Context, offset int) { func (v *VM) call(ctx *Context, offset int) {
v.checkInvocationStackSize()
newCtx := ctx.Copy() newCtx := ctx.Copy()
newCtx.CheckReturn = NoCheck newCtx.CheckReturn = NoCheck
newCtx.local = nil newCtx.local = nil
@ -1520,7 +1521,8 @@ func (v *VM) calcJumpOffset(ctx *Context, parameter []byte) (int, int, error) {
func (v *VM) handleException() { func (v *VM) handleException() {
pop := 0 pop := 0
ictx := v.istack.Peek(0).Value().(*Context) ictxv := v.istack.Peek(0)
ictx := ictxv.Value().(*Context)
for ictx != nil { for ictx != nil {
e := ictx.tryStack.Peek(0) e := ictx.tryStack.Peek(0)
for e != nil { for e != nil {
@ -1546,7 +1548,8 @@ func (v *VM) handleException() {
return return
} }
pop++ pop++
ictx = v.istack.Peek(pop).Value().(*Context) ictxv = ictxv.Next()
ictx = ictxv.Value().(*Context)
} }
} }