mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-22 19:43:46 +00:00
Merge pull request #1186 from nspcc-dev/fix-astack-clearance-on-call-2.x
vm: clear altstack on CALL, fix #1158
This commit is contained in:
commit
dbbe57d11a
1 changed files with 14 additions and 4 deletions
18
pkg/vm/vm.go
18
pkg/vm/vm.go
|
@ -258,8 +258,9 @@ func (v *VM) Load(prog []byte) {
|
||||||
func (v *VM) LoadScript(b []byte) {
|
func (v *VM) LoadScript(b []byte) {
|
||||||
ctx := NewContext(b)
|
ctx := NewContext(b)
|
||||||
ctx.estack = v.estack
|
ctx.estack = v.estack
|
||||||
ctx.astack = v.astack
|
ctx.astack = v.newItemStack("alt")
|
||||||
v.istack.PushVal(ctx)
|
v.istack.PushVal(ctx)
|
||||||
|
v.astack = ctx.astack
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadScriptWithHash if similar to the LoadScript method, but it also loads
|
// loadScriptWithHash if similar to the LoadScript method, but it also loads
|
||||||
|
@ -1138,6 +1139,8 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
|
|
||||||
newCtx := ctx.Copy()
|
newCtx := ctx.Copy()
|
||||||
newCtx.rvcount = -1
|
newCtx.rvcount = -1
|
||||||
|
newCtx.astack = v.newItemStack("alt")
|
||||||
|
v.astack = newCtx.astack
|
||||||
v.istack.PushVal(newCtx)
|
v.istack.PushVal(newCtx)
|
||||||
|
|
||||||
offset := v.getJumpOffset(newCtx, parameter, 0)
|
offset := v.getJumpOffset(newCtx, parameter, 0)
|
||||||
|
@ -1202,8 +1205,15 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
newEstack.Push(elem)
|
newEstack.Push(elem)
|
||||||
}
|
}
|
||||||
v.estack = newEstack
|
v.estack = newEstack
|
||||||
v.astack = v.Context().astack
|
|
||||||
}
|
}
|
||||||
|
newAstack := v.Context().astack
|
||||||
|
if rvcount == -1 && newAstack != oldCtx.astack {
|
||||||
|
for i := oldCtx.astack.Len(); i > 0; i-- {
|
||||||
|
elem := oldCtx.astack.RemoveAt(i - 1)
|
||||||
|
newAstack.Push(elem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v.astack = newAstack
|
||||||
|
|
||||||
case opcode.CHECKSIG, opcode.VERIFY:
|
case opcode.CHECKSIG, opcode.VERIFY:
|
||||||
var hashToCheck []byte
|
var hashToCheck []byte
|
||||||
|
@ -1381,8 +1391,8 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
newCtx.hasDynamicInvoke = hasDynamicInvoke
|
newCtx.hasDynamicInvoke = hasDynamicInvoke
|
||||||
}
|
}
|
||||||
newCtx.rvcount = rvcount
|
newCtx.rvcount = rvcount
|
||||||
newCtx.estack = NewStack("evaluation")
|
newCtx.estack = v.newItemStack("evaluation")
|
||||||
newCtx.astack = NewStack("alt")
|
newCtx.astack = v.newItemStack("alt")
|
||||||
// Going backwards to naturally push things onto the new stack.
|
// Going backwards to naturally push things onto the new stack.
|
||||||
for i := pcount; i > 0; i-- {
|
for i := pcount; i > 0; i-- {
|
||||||
elem := v.estack.RemoveAt(i - 1)
|
elem := v.estack.RemoveAt(i - 1)
|
||||||
|
|
Loading…
Reference in a new issue