Good morning,

When importing this file in a python script, http://ed25519.cr.yp.to/python/ed25519.py

I get the following error:

Traceback (most recent call last):
  File "XMR.py", line 1, in <module>
    import ed25519 as ed25519
  File "ed25519.py", line 19, in <module>
    d = -121665 * inv(121666)
  File "ed25519.py", line 17, in inv
    return expmod(x,q-2,q)
  File "ed25519.py", line 12, in expmod
    t = expmod(b,e/2,m)**2 % m
  File "ed25519.py", line 12, in expmod
    t = expmod(b,e/2,m)**2 % m
  File "ed25519.py", line 12, in expmod

    t = expmod(b,e/2,m)**2 % m
  [Previous line repeated 986 more times]
  File "ed25519.py", line 11, in expmod
    if e == 0: return 1
RecursionError: maximum recursion depth exceeded in comparison

Do you know what could be going on ?


closed as off-topic by user36303, 254123179 Jul 25 '18 at 4:09

  • This question does not appear to be about Monero cryptocurrency, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I'm voting to close this question as off-topic because this is not about monero but an EC python library. – user36303 Jul 19 '18 at 12:26

The reference ed25519.py implementation uses old Python 2 notation for integer math that has a new meaning in Python 3. I have an updated version as part of MoneroPy that is both Python 2 and 3 compatible at https://github.com/bigreddmachine/MoneroPy. Check in "moneropy>crypto" in the library.

Simply changing the recursion limit will not fix the problem. It's not a recursion issue, but an integer division issue.

More details:

You can see the bulk of the changes that needed to be made here: https://github.com/bigreddmachine/MoneroPy/commit/20e6dbda9224436da7b537a5b062d60cefb7a04d

As you'll see, the primary culprit is that Python 2's definition of "/" is like C/C++, truncating for integer division, while Python 3 has redefined that symbol to mean true division. To prove to yourself that this is the issue, in Python 2.7 you can from __future__ import divison and see what happens.

More details on the switch here: http://www.informit.com/articles/article.aspx?p=1439189

  • I've added more detail above. Hope it helps. – bigreddmachine Jul 26 '18 at 10:45

This python script should work fine with python2.

If you want to use it with python3, you will have to increase the recursion limit (e.g. sys.setrecursionlimit(2000)), and some code fixes might be necessary...

  • Thank you sir, indeed it was due to python3. With python2, it is now working. – lapwat Jul 20 '18 at 14:42
  • This is not correct. It's not a recursion issue, it is a change to how Python 3 does integer math. See my answer for a more complete answer. – bigreddmachine Jul 24 '18 at 17:30
  • The risen exception was a RecursionError. When I say that is is working, it means that sys.setrecursionlimit(2000) removed the RecursionError (even if other exceptions pumped out). – lapwat Jul 26 '18 at 10:04
  • That may be the exception that is raised, but the cause of the exception is that the behavior of division in Python 3 has changed. If you simply raise the recursion limit, all your doing is giving an incorrect math statement more time to try to pretend to be correct. This answer should not be accepted. – bigreddmachine Jul 26 '18 at 10:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.