feat: complete 4×64-bit LongArray migration — 167/167 secp256k1 tests pass

All secp256k1 tests pass with the new 4×64-bit limb representation:
- U256: 25/25 pass (mulWide, sqrWide with unsignedMultiplyHigh)
- FieldP: 27/27 pass (reduceWide using unsignedMultiplyHigh for C-multiply)
- ScalarN: 19/19 pass (reduceWide with correct unsigned overflow handling)
- Glv: 14/14 pass (wNAF encoding with 64-bit limb bit manipulation)
- Point: 22/22 pass (comb method, Strauss, all scalar mul strategies)
- Schnorr: 22/22 pass (all BIP-340 test vectors)
- Secp256k1: 20/20 pass (key ops, ECDH, sign/verify)
- KeyCodec: 18/18 pass

One downstream failure: NIP-44 conversation key vector 32 (scalar n-8)
needs investigation — likely a ScalarN edge case in GLV decomposition.

https://claude.ai/code/session_01BhU63WUe9AhikZxRdw3Lpg
This commit is contained in:
Claude
2026-04-06 02:12:36 +00:00
parent f1d7125fac
commit cb1e8be529
4 changed files with 122 additions and 59 deletions
@@ -70,7 +70,7 @@ class GlvTest {
val k = hex("67e56582298859ddae725f972992a07c6c4fb9f62a8fff58ce3ca926a1063530")
val split = Glv.splitScalar(k)
// Upper 4 limbs should be zero for a proper 128-bit half-scalar
for (i in 4 until 8) {
for (i in 2 until 4) {
assertEquals(0, split.k1[i], "k1 limb $i should be 0")
assertEquals(0, split.k2[i], "k2 limb $i should be 0")
}
@@ -137,7 +137,7 @@ class GlvTest {
val k = hex("e907831f80848d1069a5371b402410364bdf1c5f8307b0084c55f1ce2dca8215")
val digits = Glv.wnaf(k, 5, 256)
val reconstructed = reconstructWnaf(digits)
for (i in 0 until 8) assertEquals(k[i], reconstructed[i], "Limb $i mismatch")
for (i in 0 until 4) assertEquals(k[i], reconstructed[i], "Limb $i mismatch")
}
@Test
@@ -147,7 +147,7 @@ class GlvTest {
val k = hex("944946c56e0d133f326db0b0645544a04bfcc5a0f447ad6d0227958414d8ba73")
val digits = Glv.wnaf(k, 5, 256)
val reconstructed = reconstructWnaf(digits)
for (i in 0 until 8) assertEquals(k[i], reconstructed[i], "Limb $i mismatch for carry test")
for (i in 0 until 4) assertEquals(k[i], reconstructed[i], "Limb $i mismatch for carry test")
}
@Test
@@ -227,12 +227,22 @@ class GlvTest {
val s = acc[0] + d.toLong()
val c = if (s.toULong() < acc[0].toULong()) 1L else 0L
acc[0] = s
if (c != 0L) for (j in 1 until 4) { acc[j]++; if (acc[j] != 0L) break }
if (c != 0L) {
for (j in 1 until 4) {
acc[j]++
if (acc[j] != 0L) break
}
}
} else if (d < 0) {
val s = acc[0] - (-d).toLong()
val b = if (acc[0].toULong() < (-d).toULong()) 1L else 0L
acc[0] = s
if (b != 0L) for (j in 1 until 4) { acc[j]--; if (acc[j] != -1L) break }
if (b != 0L) {
for (j in 1 until 4) {
acc[j]--
if (acc[j] != -1L) break
}
}
}
}
return acc