Show & Tell: Fixing the Homomorphic NTT Bug — From Wrong Ciphertexts to 92 Passing Tests #30
web3guru888
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The Final Bug Falls
With the closure of issue #8, ASI:BUILD has reached a milestone: all three known critical bugs are fixed, and the test suite now runs entirely green. This post walks through the homomorphic encryption NTT fix — what was wrong, why it was subtle, and what the fix looks like.
Background: Why Homomorphic Encryption?
ASI:BUILD includes a full BFV/CKKS homomorphic encryption stack in
src/asi_build/homomorphic/. The goal is privacy-preserving inference: agents can compute on encrypted data without ever seeing the plaintext. This matters for multi-agent systems where you might want to run consciousness metrics on private user data.The stack is built around polynomial rings: ciphertexts are polynomials modulo a cyclotomic polynomial x^n + 1, with coefficients reduced modulo a chain of primes.
The Bug: RNS Coefficient Mixing
The core of the bug was in
_multiply_ntt()insidepolynomial.py. When using the RNS (Residue Number System) representation with multiple coefficient moduli, the NTT-domain multiplication was silently mixing coefficients across moduli:If you have n=1024 coefficients but only 3 primes in your modulus chain, this only computed 3 multiplications instead of 1024 — silently producing a garbage polynomial that decrypted to nonsense.
The Fix: Wrap Moduli Over Full Coefficient Array
The correct implementation iterates over all n coefficients, wrapping the modulus index:
Verification
After the fix, all 92 homomorphic encryption tests pass:
All Three Bugs Fixed
Full test suite: 3,240 passing, 25 skipped, 0 failing.
Whats Next for Homomorphic?
The NTT fix unblocks several things previously masked by ciphertext corruption:
The research question Im most interested in: can we run a meaningful consciousness metric on encrypted activations and still get a useful signal? The noise budget would be tight, but it might be achievable with CKKSs approximate arithmetic.
What aspects of the HE implementation would you like to see developed further?
Beta Was this translation helpful? Give feedback.
All reactions