Hanzo AI fbe1648f8a LP-107 Phase 7: cross-runtime KAT release gate
codec/kat.go: KATEntry + KATBundle types with canonical JSON
serialization. Header field embeds params.KATHeader so every entry
carries (parameter_set, modulus_id, backend_id, hash_suite_id,
implementation, version) — required by LP-107 §"Parameter registry"
for cross-runtime equality.

codec/cmd/emit_codec_kat/main.go: emits 5 canonical entries:
  1. ReadUint64Slice/happy-path/3-elements
  2. ReadUint64Slice/empty
  3. ReadUint64Slice/reject/lattice-issue-4-70T  (regression: huge
     length must be rejected by both runtimes)
  4. ReadUint16Slice/happy-path/5-elements
  5. ReadUint32Slice/happy-path/4-elements

Each entry records:
  - InputHex: the wire-format bytes the Reader consumes
  - OutputHex: the canonical output byte stream (or "REJECTED")
  - OutputSHA256: commitment for fast cross-runtime equality

codec/kat_test.go: TestKATBundle_RoundTrip replays every bundle
entry through the Go Reader and asserts byte-equality + SHA-256
commitment match. PASS in 0.29s.

codec/testdata/codec_kat.json: the Go-emitted bundle. The C++ side
at luxcpp/crypto/math/test/codec_cross_runtime_test.cpp loads the
same file and replays every entry; in this commit, all 5 entries
PASS byte-equal between runtimes.

This closes LP-107 Phase 7 for codec/. Subsequent commits extend the
gate to modarith/, ntt/, poly/, sample/ KATs.
2026-05-04 09:43:59 -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%