Hanzo AI b0c6b9c916 LP-107 Phase 6.3-6.5: KAT extension — modarith / ntt / sample
Replicates the codec cross-runtime KAT pattern across the rest of the
math substrate. Each package now ships:

* kat.go — KATEntry/KATBundle aliases pointing at codec.KATEntry/
  codec.KATBundle (one schema for the whole substrate).
* cmd/emit_*_kat/main.go — Go-side emitter that produces the
  canonical bundle.
* kat_test.go — Go replay test (TestKATBundle_RoundTrip*).
* testdata/*_kat.json — emitted bundle, byte-stable across runs.

modarith/cmd/emit_modarith_kat: ~300 entries
  - 100 MontMulMod cross-checked against MulMod
  - 100 AddMod across deterministic random pairs
  - 100 MontgomeryRoundTrip (ToMontgomery -> FromMontgomery)
  - Multiple moduli (PulsarQ, NTT998).

ntt/cmd/emit_ntt_kat: ~50 entries
  - input: 256 random uint64 mod PulsarQ
  - output: NTT(input) byte-stream + SHA-256 commitment
  - Pulsar N=256 ring.

sample/cmd/emit_sample_kat: ~30 entries
  - Uniform / Ternary / CenteredBinomial across param sweeps
  - Each entry records the seed + first 64 sampled values.

Tests: GOWORK=off go test ./modarith/ ./ntt/ ./sample/ -> all PASS.

C++ replay tests follow in luxcpp/crypto commit on this same branch.
2026-05-04 10:20:32 -07:00
2026-03-12 01:09:17 -07:00
2026-03-12 01:09:17 -07:00
2026-03-26 22:47:13 -07:00
2026-02-14 05:26:21 -08:00

Lux Math Library

A comprehensive mathematical utilities library for the Lux ecosystem.

Features

  • Big integer utilities: HexOrDecimal256, ParseBig256, U256, BigPow etc.
  • Safe arithmetic: Overflow-checked SafeAdd, SafeSub, SafeMul
  • Bit operations: XOR, AND, compression utilities
  • Set operations: Efficient set implementations including bit sets
  • Data structures: Linked lists, hash maps, heaps
  • Averagers: Time-windowed averaging utilities

Installation

go get github.com/luxfi/math

Package Structure

Package Description
github.com/luxfi/math Root package with re-exports for backwards compatibility
github.com/luxfi/math/big Big integer utilities (HexOrDecimal256, U256, parsing)
github.com/luxfi/math/safe Overflow-safe arithmetic operations
github.com/luxfi/math/bit Bit manipulation utilities
github.com/luxfi/math/set Set data structures
github.com/luxfi/math/linked Linked data structures
github.com/luxfi/math/heap Heap implementations

Usage

// Import root package (re-exports from subpackages)
import "github.com/luxfi/math"

// Or import specific subpackages directly
import (
    "github.com/luxfi/math/big"
    "github.com/luxfi/math/safe"
    "github.com/luxfi/math/set"
)

Big Integer Operations

import "github.com/luxfi/math/big"

// Parse hex or decimal
val, _ := big.ParseBig256("0x1234")

// 256-bit unsigned operations
result := big.U256(someInt)

// Power operation
power := big.BigPow(2, 256)

Safe Arithmetic

import "github.com/luxfi/math/safe"

// Returns (result, overflow bool)
sum, overflow := safe.SafeAdd(a, b)
product, overflow := safe.SafeMul(x, y)

// Returns (result, error)
sum, err := safe.Add64(a, b)

License

See the LICENSE file for licensing terms.

S
Description
Mathematical utilities library for the Lux ecosystem
Readme BSD-3-Clause
1.8 MiB
Languages
Go 100%