feat: fix constants and types in ScalarN, KeyCodec, partial Glv fix (WIP — still broken)

Progress on the LongArray(4) migration:
- ScalarN: constants converted to 4×64-bit, loop bounds fixed
- KeyCodec: B constant fixed
- Glv: constants partially converted but regex left residual old values
- Point: types fixed, GX/GY constants converted
- Secp256k1: parameter types updated

Still needs: manual cleanup of Glv constants, ScalarN reduceWide internals,
test hex() helpers, test constant arrays, wNAF bit manipulation for 64-bit limbs.

https://claude.ai/code/session_01BhU63WUe9AhikZxRdw3Lpg
This commit is contained in:
Claude
2026-04-06 01:18:40 +00:00
parent 69f222c6d5
commit 689c52ed6f
11 changed files with 137 additions and 123 deletions
@@ -32,7 +32,7 @@ class FieldPTest {
s.chunked(2).map { it.toInt(16).toByte() }.toByteArray(),
)
private fun toHex(a: IntArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun toHex(a: LongArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
// ==================== Basic identities ====================
@@ -26,7 +26,7 @@ import kotlin.test.assertTrue
/** Comprehensive tests for GLV endomorphism and wNAF encoding. */
class GlvTest {
private fun toHex(a: IntArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun toHex(a: LongArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun hex(s: String) =
U256.fromBytes(
@@ -210,7 +210,7 @@ class GlvTest {
// ==================== Helpers ====================
/** Reconstruct a scalar from wNAF digits using Horner's method. */
private fun reconstructWnaf(digits: IntArray): IntArray {
private fun reconstructWnaf(digits: LongArray): LongArray {
var acc = LongArray(4)
for (bit in digits.size - 1 downTo 0) {
val doubled = LongArray(4)
@@ -27,7 +27,7 @@ import kotlin.test.assertTrue
/** Tests for KeyCodec: key parsing, serialization, liftX, hasEvenY. */
class KeyCodecTest {
private fun toHex(a: IntArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun toHex(a: LongArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
// ==================== liftX ====================
@@ -32,7 +32,7 @@ class PointTest {
s.chunked(2).map { it.toInt(16).toByte() }.toByteArray(),
)
private fun toHex(a: IntArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun toHex(a: LongArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
// ==================== Generator point ====================
@@ -32,7 +32,7 @@ class ScalarNTest {
s.chunked(2).map { it.toInt(16).toByte() }.toByteArray(),
)
private fun toHex(a: IntArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun toHex(a: LongArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
// ==================== isValid ====================
@@ -32,7 +32,7 @@ class U256Test {
s.chunked(2).map { it.toInt(16).toByte() }.toByteArray(),
)
private fun toHex(a: IntArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
private fun toHex(a: LongArray) = U256.toBytes(a).joinToString("") { "%02x".format(it) }
// ==================== isZero / cmp ====================