forked from TrueCloudLab/neoneo-go
vm: fix INITSSLOT, it's context-wide, not VM-wide
It's tied to the current contract, not to VM.
This commit is contained in:
parent
2a16df8db1
commit
1bb26dcdc1
3 changed files with 8 additions and 9 deletions
|
@ -35,6 +35,7 @@ type Context struct {
|
|||
// Alt stack pointer.
|
||||
astack *Stack
|
||||
|
||||
static *Slot
|
||||
local *Slot
|
||||
arguments *Slot
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ func testFile(t *testing.T, filename string) {
|
|||
require.Equal(t, op, opcode.Opcode(ctx.prog[ctx.nextip]))
|
||||
}
|
||||
compareStacks(t, s.EStack, vm.estack)
|
||||
compareSlots(t, s.StaticFields, vm.static)
|
||||
compareSlots(t, s.StaticFields, ctx.static)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
pkg/vm/vm.go
14
pkg/vm/vm.go
|
@ -71,8 +71,6 @@ type VM struct {
|
|||
estack *Stack // execution stack.
|
||||
astack *Stack // alt stack.
|
||||
|
||||
static *Slot
|
||||
|
||||
// Hash to verify in CHECKSIG/CHECKMULTISIG.
|
||||
checkhash []byte
|
||||
|
||||
|
@ -585,13 +583,13 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
v.estack.PushVal(result)
|
||||
|
||||
case opcode.INITSSLOT:
|
||||
if v.static != nil {
|
||||
if ctx.static != nil {
|
||||
panic("already initialized")
|
||||
}
|
||||
if parameter[0] == 0 {
|
||||
panic("zero argument")
|
||||
}
|
||||
v.static = v.newSlot(int(parameter[0]))
|
||||
ctx.static = v.newSlot(int(parameter[0]))
|
||||
|
||||
case opcode.INITSLOT:
|
||||
if ctx.local != nil || ctx.arguments != nil {
|
||||
|
@ -612,20 +610,20 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
}
|
||||
|
||||
case opcode.LDSFLD0, opcode.LDSFLD1, opcode.LDSFLD2, opcode.LDSFLD3, opcode.LDSFLD4, opcode.LDSFLD5, opcode.LDSFLD6:
|
||||
item := v.static.Get(int(op - opcode.LDSFLD0))
|
||||
item := ctx.static.Get(int(op - opcode.LDSFLD0))
|
||||
v.estack.PushVal(item)
|
||||
|
||||
case opcode.LDSFLD:
|
||||
item := v.static.Get(int(parameter[0]))
|
||||
item := ctx.static.Get(int(parameter[0]))
|
||||
v.estack.PushVal(item)
|
||||
|
||||
case opcode.STSFLD0, opcode.STSFLD1, opcode.STSFLD2, opcode.STSFLD3, opcode.STSFLD4, opcode.STSFLD5, opcode.STSFLD6:
|
||||
item := v.estack.Pop().Item()
|
||||
v.static.Set(int(op-opcode.STSFLD0), item)
|
||||
ctx.static.Set(int(op-opcode.STSFLD0), item)
|
||||
|
||||
case opcode.STSFLD:
|
||||
item := v.estack.Pop().Item()
|
||||
v.static.Set(int(parameter[0]), item)
|
||||
ctx.static.Set(int(parameter[0]), item)
|
||||
|
||||
case opcode.LDLOC0, opcode.LDLOC1, opcode.LDLOC2, opcode.LDLOC3, opcode.LDLOC4, opcode.LDLOC5, opcode.LDLOC6:
|
||||
item := ctx.local.Get(int(op - opcode.LDLOC0))
|
||||
|
|
Loading…
Reference in a new issue