/ GrothCurves / test / test_line_vanishing.jl
test_line_vanishing.jl
 1  using GrothCurves
 2  
 3  println("Testing that lines vanish at the correct points...")
 4  
 5  Q = g2_generator()
 6  T = 2 * Q  # Some other point
 7  
 8  # Test addition line
 9  T_plus_Q, line_add = GrothCurves.addition_step(T, Q)
10  
11  # Get affine coordinates
12  xQ, yQ = GrothCurves.to_affine(Q)
13  xT, yT = GrothCurves.to_affine(T)
14  
15  # Check that the line vanishes at both Q and T
16  at_Q = line_add.a * xQ + line_add.b * yQ + line_add.c
17  at_T = line_add.a * xT + line_add.b * yT + line_add.c
18  
19  println("\nAddition line (T + Q):")
20  println("At Q: ", at_Q, " (should be zero)")
21  println("At T: ", at_T, " (should be zero)")
22  println("Both zero? ", iszero(at_Q) && iszero(at_T))
23  
24  # Test doubling line
25  T2, line_double = GrothCurves.doubling_step(T)
26  
27  # Check that the tangent line vanishes at T
28  at_T_double = line_double.a * xT + line_double.b * yT + line_double.c
29  
30  println("\nDoubling line (tangent at T):")
31  println("At T: ", at_T_double, " (should be zero)")
32  println("Is zero? ", iszero(at_T_double))
33  
34  # Also test with the generator
35  Q2, line_double_Q = GrothCurves.doubling_step(Q)
36  at_Q_double = line_double_Q.a * xQ + line_double_Q.b * yQ + line_double_Q.c
37  
38  println("\nDoubling line (tangent at Q):")
39  println("At Q: ", at_Q_double, " (should be zero)")
40  println("Is zero? ", iszero(at_Q_double))
41  
42  if iszero(at_Q) && iszero(at_T) && iszero(at_T_double) && iszero(at_Q_double)
43      println("\n✅ All lines vanish at the correct points!")
44  else
45      println("\n❌ Some lines don't vanish where they should")
46  end