Repository navigation
CROSS v2.0.0
This release adds a layer of higher-level CKKS infrastructure on top of the
HPCA'26 paper artifact: a context-level operator API, scan-fused BSGS
matrix-vector multiplication, NumPy-vectorized encrypt/decrypt, an end-to-end
encrypted-CNN MNIST demo, a bootstrap kernel, a standalone Polynomial
primitive, and composite-degree CKKS (composite_degree > 1).
The seven sections below document what was added. The original kernel
(NTT, BConv, BAT, Add/Sub) is unchanged. Refer to its source
files and the API reference (jaxite_word/API_REFERENCE.md) for low-level
details. HE-Mul, HE-Rot are improved by 30% from engineering optimizations
Quickstart
conda create --name jaxite python=3.13 && conda activate jaxite
pip install -U "jax[tpu]" xprof absl-py pandas gmpy2A ciphertext is a 3-D jax.Array of (num_elements, num_towers, degree).
Fresh ciphertexts live at max_level = (num_q - 1) // composite_degree; each
rescale consumes one level.
1. Context-level HE operator API
jaxite_word/he_ops.py, jaxite_word/he_params.py, jaxite_word/ptct_mul.py,
plus extensions to ckks_ctx.py, hemul.py, finite_field.py, ntt_mm.py,
ciphertext.py. Documented in jaxite_word/API_REFERENCE.md.
CKKSContext.program_initialization(...) is an offline step that builds a
shared HEParameterCache (NTT / Barrett / per-level BConv / pre-allocated
ciphertext helpers) and exposes level-indexed accessors.
ctx = CKKSContext(params)
ctx.program_initialization(
total_hemul_levels=3,
total_rotation_indices=[1, 2],
dnum=3, r=4, c=4, batch=1)
result = ctx.he_mul[level].mul(ct1, ct2) # ct × ct (rescale + relin)
ct3 = ctx.he_mul[level].hemul_no_relin(ct1, ct2) # 3-element output
ct2 = ctx.he_mul[level].relinearize(ct3) # back to 2-element
rot = ctx.he_rot[level, k].rotate(ct)
op = ctx.ptct_mul[level]; op.set_plaintext(pt_ntt); ct_out = op.mul(ct_in)
ct_lo = ctx.he_rescale[src, dst](ct)Underlying classes added: HEMulAtLevel, HERotAtLevel, HERescaleOp,
HEPtCtMulAtLevel, HEBsgsMatVecAtLevel, plus SlicedNTTContext and
SlicedBarrettContext that share parent twiddle/Barrett tables.
Tests: ckks_ctx_test.py, hemul_test.py, herot_test.py, ptct_mul_test.py.
2. BSGS matrix-vector multiplication
jaxite_word/bsgs.py, jaxite_word/bsgs_test.py, jaxite_word/bsgs_perf_test.py.
Underlying primitives in jaxite_word/matvec.py (+ matvec_test.py,
matvec_perf_test.py).
A scan-fused Baby-Step Giant-Step diagonal matvec. The diagonal method writes
A·v = Σ_k Rot_k(v) · diag_k(A); BSGS with n1·n2 = n cuts this from n to
n1 + n2 rotations (e.g. n=1024 → 64). Two zero-skip levels are implemented:
- Whole-giant-step skip drops any
jwhere every baby diagonal in
[j·n1, (j+1)·n1)is zero. - Per-diagonal skip groups active giant steps by their non-zero baby
count so the inner scan iterates only over non-zero diagonals.
Rectangular m × k matrices (m, k ≤ n) are zero-padded to n × n before
diagonal extraction. One rescale per mul.
bsgs = ctx.bsgs_matvec[level, n] # auto-split n1, n2
# or: ctx.bsgs_matvec[level, n, n1, n2] # explicit
bsgs.encode_matrix(W) # rectangular OK; zero-padded
ct_out = bsgs.mul(ct_in) # consumes 1 level3. Vectorized encrypt / decrypt
jaxite_word/encrypt_fast.py, jaxite_word/decrypt_fast.py, paired tests
(encrypt_fast_test.py, decrypt_fast_test.py), and the combined gate
jaxite_word/run_fast_path_tests.py.
NumPy-vectorized uint64 paths replace the pure-Python triple-loop forward NTT
- sample/NTT(v, e0, e1) (encrypt) and SK-multiply + per-tower INTT (decrypt).
Bit-equal to the reference paths inckks_ctx.CKKSContext.encrypt/decryptat
every level.
encrypt: ≈770 ms → ≈30 ms (~28× speedup at 9Q)decrypt: ≈155 ms → ≈5 ms (~30× speedup at L3, 4 moduli)
Run before any change to the fast paths or to LoLAHE.encrypt/decrypt:
python3 jaxite_word/run_fast_path_tests.py4. End-to-end LoLA-MNIST encrypted CNN demo
demos/lola_he.py (+ demos/lola_he_test.py, demos/lola_he_perf_test.py).
Full encrypted LoLA-MNIST inference (Conv → Square → FC1 → Square → FC2) at
CKKS degree=2048, num_slots=1024. The single LoLAHE class bundles every
optimization the codebase offers:
- per-level JIT-compiled
ptct_mul + rescale, - cached
Polynomialtemplates + encoded bias plaintexts, - fast
he_mulsquaring via_FastHEMulPath, - JIT-compiled pure rotation per
(level, rot_idx), - scan-fused
sum_reduce_all, - BSGS diagonal matmul for FC1 and FC2,
- JIT-compiled bias-add and conv1 mod-add (one fused closure per
nq), - vectorized NumPy
encrypt + encodeanddecrypt + decode.
Canonical config: 7 Q-towers + 3 P-towers, dnum=3, max_level=6, depth-5
schedule. Level budget:
L6 → conv1 BSGS → L5 → square → L4 → FC1 BSGS → L3 → bias+square → L2 → FC2 BSGS → L1 → bias → decrypt.
Run a single image:
cd CROSS/demos
python3 lola_he.py --n 1Each inference prints [i] label=<true digit> pt=<plaintext argmax> he=<ciphertext argmax> |he-pt|=<L∞ distance> wall=<seconds>. A correctly
working model matches he == pt and keeps |he-pt| inside the CKKS noise
budget (≤ 5e-2 at the scaling factor used here).
lola_he_test.py is the single-image correctness gate (argmax + max-error
vs cleartext); lola_he_perf_test.py writes per-image wall+accuracy to
demos/log/lola_he_perf.csv.
5. Bootstrap kernel
jaxite_word/bootstrap.py, jaxite_word/bootstrap_test.py,
jaxite_word/bootstrap_perf_test.py.
CKKS bootstrapping kernel built on the context-level operator API.
Known issue: on some JAX/TPU runtimes
bootstrap_test.pytriggers
xprecision_rewriter.cc:2100 ("Unsupported CVT X{64,128} expansion from f64 to c128")inside the JAX TPU compiler. This is unrelated to the kernel
itself; functional correctness should be verified on CPU until the runtime
issue is resolved.
6. Polynomial primitive surface
jaxite_word/polynomial.py, jaxite_word/polynomial_test.py.
Reusable Polynomial template separated from ciphertext logic, used by the
context-level API, BSGS matvec, and the LoLA demo for cached encoded plaintexts.
7. Composite-degree CKKS
jaxite_word/rescale.py, plus ckks_composite_ctx_test.py,
hemul_double_rescaling_test.py, rescale_double_rescaling_test.py.
CKKSContext now accepts composite_degree > 1: the last composite_degree
moduli form the per-level scale factor and one rescale drops
composite_degree towers at once. program_initialization and the
level-indexed accessors above all respect this. Double-rescaling correctness
is gated by the new *_double_rescaling_test.py files.