Status: Phase 2 In Progress - FHE Infrastructure Layer
Build a truly metadata-private messaging system where the server performs blind algebraic routing on fully encrypted polynomials. No plaintext polynomial IDs, no plaintext mailbox addresses - the server sees only encrypted blobs and computes homomorphically.
β What We DON'T Want (Phase 1 - Current State):
Alice β Server: {plaintext_polynomial_id: "9902", message}
Server sees: Polynomial ID 9902 goes to mailbox 15072
β Server knows metadata!
β
What We DO Want (Phase 2+ - Target State):
Alice β Server: {Enc(P_alice), Enc(P_bob), Enc(message)}
Server sees: Three encrypted blobs
Server computes: Routing on encrypted data using wreath-sheaf algebra
Server stores: Enc(message) at Enc(mailbox_location)
β
Server learns NOTHING!
Status: 32 tests passing, 1,340 lines of code
- β Polynomial ring operations (Z_p[x]/(x^n + 1))
- β Polynomial identities (device-held, unlinkable)
- β Algebraic routing (polynomial encoding/decoding)
- β Sheaf router (Algorithm 2.1 from paper)
- β Alice β Bob integration test
- β Wreath product attention (character projections)
Limitation: Server sees plaintext polynomial IDs - not true FHE!
Status: 9 FHE tests passing (stubs), infrastructure in place
- β OpenFHE dependency added to MODULE.bazel
- β
FHEContext wrapper (
lib/crypto/fhe_context.{h,cc}) - β
EncryptedPolynomial class (
lib/crypto/encrypted_polynomial.{h,cc}) - β Homomorphic operations (Add, Subtract, Rotate, MultiplyScalar)
- β Test structure for FHE operations
- β Build system configured
// lib/crypto/fhe_context.cc - Lines 35-62
// Current: UnimplementedError stubs
// Needed: Replace with actual OpenFHE BGV implementation
absl::StatusOr<FHEContext> FHEContext::Create() {
// TODO: Initialize OpenFHE crypto context
// CCParams<CryptoContextBGVRNS> parameters;
// parameters.SetMultiplicativeDepth(0); // Depth-0 only!
// parameters.SetPlaintextModulus(RingParams::kModulus);
// parameters.SetRingDim(RingParams::kDegree);
// CryptoContext cc = GenCryptoContext(parameters);
// cc->Enable(PKE);
// cc->Enable(KEYSWITCH);
// cc->Enable(LEVELEDSHE);
// return FHEContext(cc);
}- β
lib/crypto/fhe_context.cc- Fill in OpenFHE calls - β
lib/crypto/encrypted_polynomial.cc:ProjectToCharacter()- Homomorphic DFT - β
Update
third_party/openfhe.BUILDfor actual OpenFHE build - β Benchmarking for FHE Operations (TODO: add stable benchmark results)
Goal: Server stores messages at encrypted mailbox locations
// lib/network/encrypted_mailbox.{h,cc} - TO BE CREATED
class EncryptedMailbox {
// Compute mailbox ID from encrypted polynomial
static EncryptedPolynomial ComputeMailboxID_FHE(
const EncryptedPolynomial& enc_dest_poly,
const FHEContext& fhe_ctx);
// Server's blind storage:
// map<EncryptedPolynomial, vector<EncryptedPolynomial>> mailboxes;
// Server cannot decrypt keys or values!
};Tasks:
- Create
lib/network/encrypted_mailbox.{h,cc} - Implement homomorphic mailbox ID computation
- Update server to use encrypted storage
- Test: Server cannot determine which mailbox
Goal: Apply wreath-sheaf routing on encrypted polynomials
// lib/crypto/routing_polynomial.h - NEW METHOD
class RoutingPolynomial {
// Current: EncodeRoute() on plaintext
// Needed: HomomorphicEncodeRoute() on encrypted data
static EncryptedPolynomial HomomorphicEncodeRoute(
const EncryptedPolynomial& enc_source,
const EncryptedPolynomial& enc_destination,
const EncryptedPolynomial& enc_message,
const FHEContext& fhe_ctx);
};Tasks:
- Implement
HomomorphicEncodeRoute() - Update
lib/network/patch.{h,cc}for encrypted character projections - Update
lib/network/sheaf_router.{h,cc}for encrypted routing - Test: Decrypt(ServerRoute(Enc(msg))) == msg
Goal: Bob retrieves messages without revealing his mailbox
// lib/network/pir_client.{h,cc} - TO BE CREATED
// lib/network/pir_server.{h,cc} - TO BE CREATED
class PIRClient {
// Generate oblivious query for mailbox
PIRQuery GenerateQuery(
const EncryptedPolynomial& my_enc_mailbox_id);
};
class PIRServer {
// Process query without learning mailbox ID
PIRResponse ProcessQuery(
const PIRQuery& query,
const EncryptedMailboxStorage& storage);
};Options:
- Integrate SealPIR (Microsoft Research, BFV-based)
- Use SimplePIR (lattice-based, might be lighter)
- Implement custom PIR using OpenFHE primitives
Tasks:
- Research: SealPIR vs SimplePIR vs custom
- Add PIR dependency to MODULE.bazel
- Implement PIR client/server
- Test: Server learns nothing about query
Goal: Full Alice β Bob flow with zero server knowledge
// test/integration/alice_to_bob_fhe_test.cc - TO BE CREATED
TEST(AliceToBobFHETest, TrueBlindRouting) {
// 1. Alice and Bob generate FHE key pairs
// 2. Alice encrypts: Enc(P_alice), Enc(P_bob), Enc("Hello")
// 3. Server routes: HomomorphicEncodeRoute(...)
// 4. Server stores: At encrypted mailbox location
// 5. Bob queries: Via PIR (server doesn't know which mailbox)
// 6. Bob decrypts: Gets "Hello"
// 7. VERIFY: Server never decrypted anything!
}Success Criteria:
- β Server never calls Decrypt()
- β Server never sees plaintext polynomial IDs
- β Server never sees plaintext mailbox IDs
- β All routing operations are depth-0 (no bootstrapping!)
- β Cohomological obstruction = 0 (routing still perfect!)
Alice Device:
ββ Real ID: "[email protected]" (never sent)
ββ Polynomial ID: P_alice = [9902, ...] (PLAINTEXT - β Server sees this!)
ββ Message: M = [72, 101, 108, 108, 111] ("Hello")
Server:
ββ Sees: P_alice, P_bob (plaintext polynomial IDs) β
ββ Routes: R = M + P_bob (plaintext algebra)
ββ Stores: At plaintext mailbox location β
Bob Device:
ββ Retrieves: Routed polynomial R
ββ Decrypts: M = R - P_bob
Alice Device:
ββ Real ID: "[email protected]" (never sent)
ββ FHE Keys: (pk_alice, sk_alice)
ββ Encrypts:
β ββ Enc(P_alice) using pk_alice
β ββ Enc(P_bob) using pk_bob (Bob's public key)
β ββ Enc(M) using pk_bob
ββ Sends: {Enc(P_alice), Enc(P_bob), Enc(M)} β
Server (Blind Computation):
ββ Sees: Three encrypted blobs (cannot decrypt!) β
ββ Computes: Enc(R) = Enc(M) + Enc(P_bob) (homomorphically!)
ββ Computes: Enc(mailbox_id) = f(Enc(P_bob))
ββ Stores: Enc(R) at encrypted location β
Bob Device:
ββ Generates: PIR query for Enc(my_mailbox_id)
ββ Receives: Enc(R) (via PIR, server doesn't know which mailbox!) β
ββ Decrypts: M = Decrypt(Enc(R), sk_bob)
ββ Gets: "Hello" β
lib/crypto/
βββ polynomial.{h,cc} # Ring operations (Z_p[x]/(x^n+1))
βββ polynomial_params.h # SafeParams/MediumParams/ProductionParams
βββ polynomial_identity.{h,cc} # Device-held identities
βββ routing_polynomial.{h,cc} # Plaintext routing (Phase 1)
lib/network/
βββ patch.{h,cc} # Network regions (wreath product)
βββ gluing.{h,cc} # Boundary constraints (sheaf gluing)
βββ sheaf_router.{h,cc} # Algorithm 2.1 (unified sheaf learner)
test/
βββ crypto/
β βββ polynomial_test.cc # 15 tests β
β βββ polynomial_identity_test.cc # 12 tests β
β βββ encrypted_polynomial_test.cc # 9 tests β
(stubs)
βββ integration/
βββ simple_routing_test.cc # 3 tests β
βββ alice_to_bob_test.cc # 2 tests β
(plaintext routing)
lib/crypto/
βββ fhe_context.{h,cc} # β
CREATED - OpenFHE wrapper (stubs)
βββ encrypted_polynomial.{h,cc} # β
CREATED - FHE polynomial (stubs)
lib/network/ # π TODO
βββ encrypted_mailbox.{h,cc} # Blind mailbox addressing
βββ pir_client.{h,cc} # PIR query generation
βββ pir_server.{h,cc} # PIR response (blind)
test/integration/ # π TODO
βββ alice_to_bob_fhe_test.cc # End-to-end FHE routing
βββ privacy_analysis_test.cc # Verify server learns nothing
third_party/
βββ openfhe.BUILD # β
CREATED - OpenFHE build config
# Build all libraries
bazel build //lib/...
# Run all tests (32 passing)
bazel test //test/...
# Run AliceβBob demo (plaintext routing)
bazel test //test/integration:alice_to_bob_test --test_output=all# Test encrypted polynomial (9 tests - all return UnimplementedError)
bazel test //test/crypto:encrypted_polynomial_test --test_output=all
# Expected output: All tests pass (they verify UnimplementedError is returned)This project implements:
"An Algebraic Theory of Learnability: Solving Diverse Problems with a Unified Sheaf-Wreath Attention" bon-cdp ([email protected]), November 2025: https://github.com/bon-cdp/notes/blob/main/c.pdf
Wreath Product (Position-Dependent Routing):
- Network positions have character distributions (DFT basis)
- Routing weights:
w[position][character] - Learned via closed-form solve:
w* = (A^H A)^{-1} A^H b(Theorem 2.1)
Sheaf (Global Consistency):
- Network divided into patches (geographic regions)
- Each patch has local routing algebra
- Gluing constraints ensure message delivery
- Zero cohomological obstruction = guaranteed delivery
FHE Application (Novel Contribution):
- Server applies wreath-sheaf routing to encrypted polynomials
- Position-dependent weights applied homomorphically
- Character projections computed via homomorphic DFT
- Depth-0 operations only (no bootstrapping!)
-
Implement OpenFHE Integration (
lib/crypto/fhe_context.cc)- Replace UnimplementedError stubs with OpenFHE BGV calls
- File: Lines 35-180
- Estimated: 4-6 hours
-
Implement Homomorphic Character Projection (
lib/crypto/encrypted_polynomial.cc)- ProjectToCharacter() - Line 96
- Homomorphic DFT on encrypted polynomials
- Estimated: 6-8 hours
-
Verify Depth-0 Operations
- Audit all operations for multiplicative depth
- Ensure no bootstrapping needed
- Estimated: 2 hours
-
Encrypted Mailbox Addressing (Phase 3)
- Create
lib/network/encrypted_mailbox.{h,cc} - Homomorphic mailbox ID computation
- Server-side blind storage
- Estimated: 3-4 days
- Create
-
Homomorphic Routing (Phase 4)
- Implement
HomomorphicEncodeRoute() - Update patch/sheaf router for encrypted data
- Estimated: 4-5 days
- Implement
-
PIR Integration (Phase 5)
- Research: SealPIR vs SimplePIR
- Implement client/server
- Estimated: 5-7 days
- β Full Alice β Bob FHE routing test passing
- β Server performs zero decryptions
- β Depth-0 operations verified
- β Ready for Cloudflare Workers deployment
- Main docs: https://openfhe-development.readthedocs.io/
- BGV examples:
openfhe-development/src/pke/examples/ - API reference: https://openfhe-development.readthedocs.io/en/latest/api.html
- OpenFHE library paper: https://eprint.iacr.org/2022/915.pdf
- SealPIR: https://github.com/microsoft/SealPIR
- BGV scheme: https://eprint.iacr.org/2011/277.pdf
- Prerequisite Reading List: Essential reading for new contributors.
- See:
docs/sheaf_wreath_theory.pdf(LaTeX source included) - Key insight: Optimization replaced by algebra when problem has right symmetry
- β Server sees plaintext polynomial IDs (not true metadata privacy)
- β No actual encryption (just "unlinkable" pseudonyms)
- β But: Routing algebra is correct (ready for FHE!)
β οΈ OpenFHE integration incomplete (stubs return UnimplementedError)β οΈ Homomorphic character projection not implementedβ οΈ No encrypted mailbox addressing yet- β But: Infrastructure is in place!
- Author: bon-cdp
- Email: [email protected]
- GitHub: https://github.com/bon-cdp/f2chat
Apache 2.0 - See LICENSE
This project builds on:
- OpenFHE team for the incredible FHE library
- Microsoft Research for SealPIR
- Sheaf theory (algebraic topology)
- Wreath product theory (group representation)
- Discrete Fourier Transform (character theory)
Core Insight: When routing has the right algebraic structure (position-dependent + global consistency), we can replace neural network optimization with a single linear solve - and it works on encrypted data too!
Status: Phase 2 infrastructure complete, OpenFHE integration next β
Last Updated: 2025-11-11
Build Status: β All libraries compile, 41 tests passing (32 functional + 9 FHE stubs)