Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when using multiply #127

Open
Popeyef5 opened this issue Jul 4, 2022 · 0 comments
Open

Segmentation fault when using multiply #127

Popeyef5 opened this issue Jul 4, 2022 · 0 comments

Comments

@Popeyef5
Copy link

Popeyef5 commented Jul 4, 2022

  • OS: linux
  • Python Version (python --version): Python 3.8.13
  • Environment (output of pip freeze):
    argcomplete==1.12.3
    attrs==21.4.0
    cached-property==1.5.2
    certifi==2022.5.18.1
    cytoolz==0.11.2
    eth-hash==0.3.2
    eth-typing==3.0.0
    eth-utils==2.0.0
    hypothesis==6.46.11
    iniconfig==1.1.1
    mypy-extensions==0.4.3
    numpy==1.22.4
    packaging==21.3
    pandas==1.4.2
    pipx==0.16.4
    pluggy==1.0.0
    py==1.11.0
    py-ecc==6.0.0
    pyparsing==3.0.9
    pytest==7.1.2
    python-dateutil==2.8.2
    pytz==2022.1
    six==1.16.0
    sortedcontainers==2.4.0
    tomli==2.0.1
    toolz==0.11.2
    userpath==1.7.0

What is wrong?

'Segmentation fault (core dumped)' error when doing

multiply(G1, -1)

On bn128. Happened with the few other negative numbers I tried. Did not try with other curves, I assume the problem persists because -1 // 2 = -1 and the recursive nature of the multiply function.

How can it be fixed

This fixes it:

def multiply(pt: Point2D[Field], n: int) -> Point2D[Field]:
    m = abs(n)
    if m == 0:
        ret = None
    elif m == 1:
        ret = pt
    elif not m % 2:
        ret = multiply(double(pt), m // 2)
    else:
        ret = add(multiply(double(pt), int(m // 2)), pt)
    if n < 0:
        ret = neg(ret)
    return ret

alternatively this should work as well but might be less efficient:

def multiply(pt: Point2D[Field], n: int) -> Point2D[Field]:
    n = n % field_modulus
   # rest of the function still the same

Could write up a quick PR if this indeed works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant