Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/compiler/syscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,22 @@ func TestOpcode(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/interop/math"
func Main() []int {
r := make([]int, 5)
r := make([]int, 6)
r[0] = math.ModMul(3, 4, 5)
r[1] = math.ModMul(-3, 4, 5)
r[2] = math.ModMul(3, 4, -5)
r[3] = math.ModMul(-3, 4, -5)
r[4] = math.ModMul(0, 4, 5)
r[5] = math.ModMul(100, -1, -91)
return r
}`
eval(t, src, []stackitem.Item{
stackitem.Make(2),
stackitem.Make(3),
stackitem.Make(-2),
stackitem.Make(2),
stackitem.Make(3),
stackitem.Make(-2),
stackitem.Make(0),
stackitem.Make(-9),
})
})
t.Run("MODPOW", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
x1 := v.estack.Pop().BigInt()

res := new(big.Int).Mul(x1, x2)
v.estack.PushItem(stackitem.NewBigInteger(res.Mod(res, modulus)))
v.estack.PushItem(stackitem.NewBigInteger(res.Rem(res, modulus)))

case opcode.MODPOW:
modulus := v.estack.Pop().BigInt()
Expand Down
5 changes: 3 additions & 2 deletions pkg/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,10 @@ func TestMODMUL(t *testing.T) {
t.Run("bad, zero mod", getTestFuncForVM(prog, nil, 1, 2, 0))
t.Run("good, positive base", getTestFuncForVM(prog, 2, 3, 4, 5))
t.Run("good, zero base", getTestFuncForVM(prog, 0, 0, 4, 5))
t.Run("good, negative base", getTestFuncForVM(prog, 3, -3, 4, 5))
t.Run("good, negative base", getTestFuncForVM(prog, -2, -3, 4, 5))
t.Run("good, positive base, negative mod", getTestFuncForVM(prog, 2, 3, 4, -5))
t.Run("good, negative base, negative mod", getTestFuncForVM(prog, 3, -3, 4, -5))
t.Run("good, negative base, negative mod", getTestFuncForVM(prog, -2, -3, 4, -5))
t.Run("good, positive base, negative multiplier, negative mod", getTestFuncForVM(prog, -9, 100, -1, -91))
}

func TestMODPOW(t *testing.T) {
Expand Down
Loading