debug_double_test.go raw
1 package avx
2
3 import (
4 "bytes"
5 "encoding/hex"
6 "testing"
7 )
8
9 func TestDebugDouble(t *testing.T) {
10 // Known value: 2G for secp256k1 (verified using Python)
11 expectedX := "c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5"
12 expectedY := "1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a"
13
14 var g, doubled JacobianPoint
15 var affineResult AffinePoint
16
17 g.FromAffine(&Generator)
18 doubled.Double(&g)
19 doubled.ToAffine(&affineResult)
20
21 xBytes := affineResult.X.Bytes()
22 yBytes := affineResult.Y.Bytes()
23
24 t.Logf("Generator X: %x", Generator.X.Bytes())
25 t.Logf("Generator Y: %x", Generator.Y.Bytes())
26 t.Logf("2G X: %x", xBytes)
27 t.Logf("2G Y: %x", yBytes)
28
29 expectedXBytes, _ := hex.DecodeString(expectedX)
30 expectedYBytes, _ := hex.DecodeString(expectedY)
31
32 t.Logf("Expected X: %s", expectedX)
33 t.Logf("Expected Y: %s", expectedY)
34
35 if !bytes.Equal(xBytes[:], expectedXBytes) {
36 t.Errorf("2G X coordinate mismatch")
37 }
38 if !bytes.Equal(yBytes[:], expectedYBytes) {
39 t.Errorf("2G Y coordinate mismatch")
40 }
41
42 // Check if 2G is on curve
43 if !affineResult.IsOnCurve() {
44 // Let's verify manually
45 var y2, x2, x3, rhs FieldElement
46 y2.Sqr(&affineResult.Y)
47 x2.Sqr(&affineResult.X)
48 x3.Mul(&x2, &affineResult.X)
49 var seven FieldElement
50 seven.N[0].Lo = 7
51 rhs.Add(&x3, &seven)
52
53 y2Bytes := y2.Bytes()
54 rhsBytes := rhs.Bytes()
55 t.Logf("y^2 = %x", y2Bytes)
56 t.Logf("x^3 + 7 = %x", rhsBytes)
57 t.Logf("y^2 == x^3+7: %v", y2.Equal(&rhs))
58 }
59 }
60