nspcc-dev / neo-go

Go Node and SDK for the Neo blockchain
MIT License
123 stars 79 forks source link

modpow operation returns wrong results when base is negative #3612

Closed Slava0135 closed 2 weeks ago

Slava0135 commented 1 month ago

Similar to #3598

Current Behavior

For negative numbers operation returns wrong results (compared to C#).

(-1 ^ 3) % 3 == 2

image

Expected Behavior

C# results:

(-1 ^ 3) % 3 == -1

Possible Solution

operation uses Go's Exp function that explicitly makes modulus result positive, which is different from BigInteger from C# image

Steps to Reproduce

  1. ./bin/neo-go vm
  2. loadbase64 DxMTpg==
  3. run

Your Environment