sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.37k stars 462 forks source link

Segfault in ...elliptic_curves.descent_two_isogeny.Qp_soluble #35066

Open tornaria opened 1 year ago

tornaria commented 1 year ago

Is there an existing issue for this?

Did you read the documentation and troubleshoot guide?

Environment

- **OS**: void linux i686
- **Sage Version**: 9.7

Steps To Reproduce

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.7, Release Date: 2022-09-19                     │
│ Using Python 3.11.2. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: from sage.schemes.elliptic_curves.descent_two_isogeny import test_qpls
sage: test_qpls(455,50,17,96,541,681692926869431)

Expected Behavior

1

Actual Behavior

------------------------------------------------------------------------
/usr/lib/python3.11/site-packages/cysignals/signals.so(+0x641f)[0xf6fb341f]
/usr/lib/python3.11/site-packages/cysignals/signals.so(+0x6514)[0xf6fb3514]
/usr/lib/python3.11/site-packages/cysignals/signals.so(+0x89af)[0xf6fb59af]
linux-gate.so.1(__kernel_sigreturn+0x0)[0xf7f5d560]
/usr/lib32/libc.so.6(__libc_malloc+0x4e)[0xf7949b6e]
/usr/lib/python3.11/site-packages/sage/rings/integer.so(+0x1654a)[0xf4ffd54a]
/usr/lib/python3.11/site-packages/sage/rings/integer.so(+0x1778b)[0xf4ffe78b]
/usr/lib/python3.11/site-packages/sage/rings/integer.so(+0x1f3cb)[0xf50063cb]
/usr/lib/python3.11/site-packages/sage/structure/parent.so(+0x26533)[0xf6095533]
/usr/lib/python3.11/site-packages/sage/rings/integer_ring.so(+0xad94)[0xf4e99d94]
/usr/lib/python3.11/site-packages/sage/rings/integer_ring.so(+0x1d2c2)[0xf4eac2c2]
/usr/lib/python3.11/site-packages/sage/rings/integer_ring.so(+0xf399)[0xf4e9e399]
/usr/lib32/libpython3.11.so.1.0(+0x10ff95)[0xf7bdff95]
/usr/lib/python3.11/site-packages/sage/misc/randstate.so(+0x4bb4)[0xf5180bb4]
/usr/lib/python3.11/site-packages/sage/misc/randstate.so(+0xb43d)[0xf518743d]
/usr/lib/python3.11/site-packages/sage/libs/ntl/ntl_ZZ_pX.so(+0x14ede)[0xb3d74ede]
/usr/lib32/libpython3.11.so.1.0(+0x10ff95)[0xf7bdff95]
/usr/lib/python3.11/site-packages/sage/schemes/elliptic_curves/descent_two_isogeny.so(+0x83f1)[0x9e5a43f1]
/usr/lib/python3.11/site-packages/sage/schemes/elliptic_curves/descent_two_isogeny.so(+0x116b6)[0x9e5ad6b6]
/usr/lib/python3.11/site-packages/sage/schemes/elliptic_curves/descent_two_isogeny.so(+0x13762)[0x9e5af762]
/usr/lib/python3.11/site-packages/sage/schemes/elliptic_curves/descent_two_isogeny.so(+0x1b00e)[0x9e5b700e]
/usr/lib32/libpython3.11.so.1.0(+0x10ff95)[0xf7bdff95]
/usr/lib32/libpython3.11.so.1.0(_PyObject_MakeTpCall+0xa0)[0xf7b946a0]
/usr/lib32/libpython3.11.so.1.0(PyObject_Vectorcall+0xb3)[0xf7b94e93]
/usr/lib32/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x6a03)[0xf7b3b563]
/usr/lib32/libpython3.11.so.1.0(+0x1aebc9)[0xf7c7ebc9]
/usr/lib32/libpython3.11.so.1.0(PyEval_EvalCode+0xc7)[0xf7c7ec97]
/usr/lib32/libpython3.11.so.1.0(+0x1a62eb)[0xf7c762eb]
/usr/lib32/libpython3.11.so.1.0(+0x1100d1)[0xf7be00d1]
/usr/lib32/libpython3.11.so.1.0(PyObject_Vectorcall+0x5a)[0xf7b94e3a]
/usr/lib32/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x6a03)[0xf7b3b563]
/usr/lib32/libpython3.11.so.1.0(+0xdcec4)[0xf7bacec4]
/usr/lib32/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x752c)[0xf7b3c08c]
/usr/lib32/libpython3.11.so.1.0(+0xdcec4)[0xf7bacec4]
/usr/lib32/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x752c)[0xf7b3c08c]
/usr/lib32/libpython3.11.so.1.0(+0xdcec4)[0xf7bacec4]
/usr/lib32/libpython3.11.so.1.0(+0xdd91b)[0xf7bad91b]
/usr/lib32/libpython3.11.so.1.0(+0xd1bfe)[0xf7ba1bfe]
/usr/lib32/libpython3.11.so.1.0(PyObject_Vectorcall+0x5a)[0xf7b94e3a]
/usr/lib32/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x6a03)[0xf7b3b563]
/usr/lib32/libpython3.11.so.1.0(+0x1aebc9)[0xf7c7ebc9]
/usr/lib32/libpython3.11.so.1.0(PyEval_EvalCode+0xc7)[0xf7c7ec97]
/usr/lib32/libpython3.11.so.1.0(+0x1f38da)[0xf7cc38da]
/usr/lib32/libpython3.11.so.1.0(+0x1f3b5d)[0xf7cc3b5d]
/usr/lib32/libpython3.11.so.1.0(+0x1f3c4d)[0xf7cc3c4d]
/usr/lib32/libpython3.11.so.1.0(_PyRun_SimpleFileObject+0x135)[0xf7cc68b5]
/usr/lib32/libpython3.11.so.1.0(_PyRun_AnyFileObject+0x5c)[0xf7cc6e7c]
/usr/lib32/libpython3.11.so.1.0(Py_RunMain+0x882)[0xf7ce6a82]
/usr/lib32/libpython3.11.so.1.0(+0x217069)[0xf7ce7069]
/usr/lib32/libpython3.11.so.1.0(Py_BytesMain+0x35)[0xf7ce7165]
/usr/bin/python3(+0x1087)[0x56569087]
/usr/lib32/libc.so.6(+0x213df)[0xf78ca3df]
/usr/lib32/libc.so.6(__libc_start_main+0x94)[0xf78ca4b4]
/usr/bin/python3(_start+0x27)[0x565690b7]
------------------------------------------------------------------------
Segmentation fault

Additional Information

Found while doctesting descent_two_isogeny for some random seed the doctest for test_els fails. Tracked it down to Qp_soluble() with some large p (681692926869431 > 2^32).

I have not been able to reproduce this on 64 bits. Maybe it's too hard to hit a polynomial of degree 4 with a large prime in the discriminant ( > 2^64) that it is globally solvable (because that is whattest_els() seems to check before indirectly calling Qp_solvable).

JohnCremona commented 1 year ago

I'll look into it. I cannot remember who wrote this -- not me!

JohnCremona commented 1 year ago

I had forgotten that Robert Miller had made this cython implementation -- it is a rewrite of my C++ code in eclib.

I don't know enough cython to debug and have little motivation. As far as I can tell the code here is not used anywhere -- I could find no reference to it in ell_rational_field where 2-descent (on elliptic curves over Q) is done either by calling eclib (as in the method two_descent) or Denis Simon's gp script (in simon_two_descent), the latter being now obsolete.

What is your interest in this, @tornaria ?

tornaria commented 1 year ago

I had forgotten that Robert Miller had made this cython implementation -- it is a rewrite of my C++ code in eclib.

I don't know enough cython to debug and have little motivation. As far as I can tell the code here is not used anywhere -- I could find no reference to it in ell_rational_field where 2-descent (on elliptic curves over Q) is done either by calling eclib (as in the method two_descent) or Denis Simon's gp script (in simon_two_descent), the latter being now obsolete.

What is your interest in this, @tornaria ?

None, other than making sure the testsuite passes as predictable as possible.

This bug strikes every once in a while, as far as I remember always on 32 bit (i686). The actual doctest failure is this:

sage: from sage.schemes.elliptic_curves.descent_two_isogeny import test_els ## line 921 ##
sage: for _ in range(1000):
    a,b,c,d,e = randint(1,1000), randint(1,1000), randint(1,1000), randint(1,1000), randint(1,1000)
    if pari.Pol([a,b,c,d,e]).hyperellratpoints(1000, 1):
        try:  
            if not test_els(a,b,c,d,e):
                print("This never happened", a, b, c, d, e) 
        except ValueError:
            continue ## line 922 ##
-----------------------------------------------------------------------
<backtrace for the segfault>
-----------------------------------------------------------------------

What I did is figure out what are some values of a, b, c, d, e that cause the failure, and track it down to that track_qpls().

Debugging is a pain, not helped by the fact that I only have a case that breaks on 32 bit (it is possible that the bug also affects 64 bits but it's much harder to trigger).

JohnCremona commented 1 year ago

Thanks for the explanation. I am going to unassign myself for reasons I already explained + not having a 32-bit machine.