mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-10 16:33:27 +00:00
Major cleanup of the pure-Kotlin secp256k1 implementation for readability: Documentation: - Added file-level architecture comments explaining representation choices (why 8×32-bit limbs, why not 5×52-bit like C), field reduction strategy, and performance approach (mutable output params, thread-local scratch) - Added single-paragraph explainers for domain jargon: Jacobian coordinates, Fermat inversion vs safegcd, windowed scalar multiplication, Shamir's trick, GLV endomorphism, wNAF encoding - Documented every public function with purpose, cost, and usage context - Added inline comments explaining the math in point doubling/addition formulas Removed dead code (-400 lines): - straussGlvGP: GLV-accelerated Strauss method (had sign-handling bug) - scalarSplitLambda, SplitResult, isHigh: GLV scalar decomposition - wnaf, getBitsVar, addBitTo: wNAF encoding functions - mulLambdaAffine, addMixedWithSign, buildOddMultiplesTable: GLV support - All GLV constants (BETA, LAMBDA, MINUS_LAMBDA, G1, G2, MINUS_B1, MINUS_B2) - U256.mulShift: used only by GLV scalar decomposition These are preserved in git history and can be restored once the wNAF interaction bug with the verify path is understood and fixed. Structure: - Field.kt: Clear sections (U256 → FieldP → ScalarN) with headers - Point.kt: Sections (types → doubling → mixed add → full add → scalar mul → conversion → serialization) with formula documentation - Secp256k1.kt: Grouped by purpose (keys → BIP-340 → tweaks) with algorithm steps documented in KDoc https://claude.ai/code/session_01BhU63WUe9AhikZxRdw3Lpg