From 53cfde62deba4108eacf54cf5b48be8b8f99be8b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 2 Dec 2021 15:59:51 +0300 Subject: [PATCH] vm: don't allocate another stack for entry scripts vm.New() creates a new stack, then we load an entry script with LoadScriptWithFlags and it creates another one which doesn't make much sense. rvcount is -1 for it, so all elements are to be copied down anyway and it's clear so a new loaded script can't dig down to anything it shouldn't be able to. --- pkg/vm/vm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 33859b91c..5cc6b872a 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -317,7 +317,9 @@ func (v *VM) loadScriptWithCallingHash(b []byte, exe *nef.File, caller util.Uint v.checkInvocationStackSize() ctx := NewContextWithParams(b, rvcount, offset) - v.estack = newStack("evaluation", &v.refs) + if rvcount != -1 || v.estack.Len() != 0 { + v.estack = newStack("evaluation", &v.refs) + } ctx.estack = v.estack initStack(&ctx.tryStack, "exception", nil) ctx.callFlag = f