Skip to content

regression: tate_pairing fail on certain curves, caused by bb3583c #40764

@Jemmy1228

Description

@Jemmy1228

Steps To Reproduce

This piece of code will work in SageMath 9.5, but fails in 10.0+

Due to the regression caused by bb3583c

p = 886368969471450739924935101400677
a = 26392827536965106777121445123290
b = 372325368096095544195525883520589
n = 886368969471450710152985728350703

K = GF(p)
Kx.<x> = K[]
K3.<u> = K.extension(Kx([4, 1, 0, 1]))
K3y.<y> = K3[]
K6.<t> = K3.extension(K3y([2, 0, 1]))

E = EllipticCurve(K, [a, b])
E6 = EllipticCurve(K6, [a, b])

xs =  [
    365236101742748463929673543888206,
    858097895593939865996182272259769,
    148438159087534462792506738986740
]

ys = [
    776418047571862972603801173382237,
    873677028107508092012208744232957,
    622138327043805563266794621920098
]

G6 = E6(K3(xs) * t^-2, K3(ys) * t^-3)
G = E6((260732037218904468999251391282274, 269397224242388526901257227817926))

G6.tate_pairing(G, n, 6, q=p)

Expected Behavior

In SageMath 9.5

(265866953933808765410855411775197*u^2 + 70840727177606736287176107019990*u + 564974538044254187432914971954649)*t + 277110391100948289129710841920822*u^2 + 854033999039359627943594217781184*u + 866734209507928074923908713252876

Actual Behavior

In SageMath 10.7

sage: G6.tate_pairing(G, n, 6, q=p)
---------------------------------------------------------------------------
PariError                                 Traceback (most recent call last)
Cell In[50], line 1
----> 1 G6.tate_pairing(G, n, Integer(6), q=p)

File ~/sage/src/sage/schemes/elliptic_curves/ell_point.py:2399, in EllipticCurvePoint_field.tate_pairing(self, Q, n, k, q)
   2394     raise ValueError("The point P must be n-torsion")
   2396 # NOTE: Pari returns the non-reduced Tate pairing, so we
   2397 # must perform the exponentiation ourselves using the supplied
   2398 # k value
-> 2399 ePQ = pari.elltatepairing(E, P, Q, n)
   2400 exp = Integer((q**k - 1)/n)
   2401 return K(ePQ**exp)

File cypari2/auto_instance.pxi:11331, in cypari2.pari_instance.Pari_auto.elltatepairing()

File ~/sage/local/var/lib/sage/venv-python3.12.5/lib/python3.12/site-packages/cypari2/handle_error.pyx:211, in cypari2.handle_error._pari_err_handle()
    209     pari_error_string = s.decode('ascii') + ": " + pari_error_string
    210
--> 211 raise PariError(errnum, pari_error_string, clone_gen_noclear(E))
    212
    213

PariError: incorrect type in checkell over Fq (t_VEC)

Additional Information

Regression caused by commit bb3583c

That commit assumes that curves defined over finite fields would be supported by PARI/GP, and therefore directly uses pari.elltatepairing for Tate pairing.

If PARI indeed supports the algebraic structure in my example code

The issue might originate from cypari2:
Before performing the pairing, PARI performs a series of checks:
elltatepairing -> checkell_Fq -> ell_over_Fq

Among them, ell_get_type checks the 1st element of the 14th subelement of the GEN, which is expected to be either t_ELL_Fp (= 3) or t_ELL_Fq (= 4).

However, using pari(E6).debug() reveals that this value is 0 (this behavior is the same as v9.5, however v9.5 is not using PARI so not affected)

14th component = [&=00007311eb03a6a8] VECSMALL(lg=2):2c00000000000002 000000000000000

meaning that cypari2 might not have constructed the correct PARI GEN object corresponding to E6. (I’m not entirely sure how this conversion is implemented; perhaps there’s a missing step to inform cypari2 that it should set it as t_ELL_Fq?)

If PARI does not support it

Should we consider reverting to the previous implementation? Or perhaps adjust the implementation to choose whether to use PARI based on the type of algebraic structure?

Environment

OS: Latest Arch Linux in WSL
Sage Version: 10.7

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions