Merge pull request #2052 from nspcc-dev/fix-state-276
vm: copy integers for unary operations, fix #2051
This commit is contained in:
commit
fc83b34d02
2 changed files with 15 additions and 3 deletions
|
@ -831,7 +831,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
// inplace
|
// inplace
|
||||||
e := v.estack.Peek(0)
|
e := v.estack.Peek(0)
|
||||||
i := e.BigInt()
|
i := e.BigInt()
|
||||||
e.value = stackitem.Make(i.Not(i))
|
e.value = stackitem.Make(new(big.Int).Not(i))
|
||||||
|
|
||||||
case opcode.AND:
|
case opcode.AND:
|
||||||
b := v.estack.Pop().BigInt()
|
b := v.estack.Pop().BigInt()
|
||||||
|
@ -866,11 +866,11 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
|
|
||||||
case opcode.ABS:
|
case opcode.ABS:
|
||||||
x := v.estack.Pop().BigInt()
|
x := v.estack.Pop().BigInt()
|
||||||
v.estack.PushVal(x.Abs(x))
|
v.estack.PushVal(new(big.Int).Abs(x))
|
||||||
|
|
||||||
case opcode.NEGATE:
|
case opcode.NEGATE:
|
||||||
x := v.estack.Pop().BigInt()
|
x := v.estack.Pop().BigInt()
|
||||||
v.estack.PushVal(x.Neg(x))
|
v.estack.PushVal(new(big.Int).Neg(x))
|
||||||
|
|
||||||
case opcode.INC:
|
case opcode.INC:
|
||||||
x := v.estack.Pop().BigInt()
|
x := v.estack.Pop().BigInt()
|
||||||
|
|
|
@ -2050,6 +2050,18 @@ func TestDupInt(t *testing.T) {
|
||||||
assert.Equal(t, int64(-1), vm.estack.Pop().BigInt().Int64())
|
assert.Equal(t, int64(-1), vm.estack.Pop().BigInt().Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNegateCopy(t *testing.T) {
|
||||||
|
prog := makeProgram(opcode.NEGATE)
|
||||||
|
v := load(prog)
|
||||||
|
bi := stackitem.Make(-1)
|
||||||
|
v.estack.PushVal(bi)
|
||||||
|
v.estack.PushVal(bi)
|
||||||
|
runVM(t, v)
|
||||||
|
assert.Equal(t, 2, v.estack.Len())
|
||||||
|
assert.Equal(t, int64(1), v.estack.Pop().BigInt().Int64())
|
||||||
|
assert.Equal(t, int64(-1), v.estack.Pop().BigInt().Int64())
|
||||||
|
}
|
||||||
|
|
||||||
func TestDupByteArray(t *testing.T) {
|
func TestDupByteArray(t *testing.T) {
|
||||||
prog := makeProgram(opcode.PUSHDATA1, 2, 1, 0,
|
prog := makeProgram(opcode.PUSHDATA1, 2, 1, 0,
|
||||||
opcode.DUP,
|
opcode.DUP,
|
||||||
|
|
Loading…
Reference in a new issue