forked from bon-cdp/f2chat
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(FHE): create fhe context and encrypted polynomial implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d7b1fe
build(bazel): add compile commands extractor and update config
cryptus-neoxys 7771e9f
docs: add agent context file and updated README
cryptus-neoxys c435ed8
docs: add prerequisite reading list for f2chat contributors
cryptus-neoxys 894f3d4
feat(crypto): integrate OpenFHE library using CMake with Bazel
cryptus-neoxys 7784646
feat(crypto): implement OpenFHE integration for BGV scheme
cryptus-neoxys 0f43de4
feat(crypto): implement homomorphic character projection in encrypted…
cryptus-neoxys 9b76603
feat(benchmark): add performance benchmarks for FHE operations
cryptus-neoxys 8404b2b
docs: remove benchmark results table from README.
cryptus-neoxys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # f2chat AI Coding Instructions | ||
|
|
||
| ## Project Overview | ||
|
|
||
| f2chat is a metadata-private messaging system using **Fully Homomorphic Encryption (FHE)**. | ||
| The core innovation is **Blind Routing**: the server routes encrypted messages using **Sheaf-Wreath Attention** without ever decrypting them. | ||
|
|
||
| ## Architecture | ||
|
|
||
| - **Client**: Holds private keys. Encrypts polynomials (IDs, messages) and decrypts results. | ||
| - **Server**: Performs **blind algebraic routing** on encrypted data. | ||
| - **Input**: Encrypted polynomials (`Enc(P_alice)`, `Enc(P_bob)`, `Enc(message)`). | ||
| - **Operation**: Homomorphic addition, subtraction, scalar multiplication, and rotation. | ||
| - **Output**: Encrypted routed message stored at an encrypted mailbox location. | ||
| - **Constraint**: All server-side operations must be **Depth-0** (no bootstrapping). | ||
|
|
||
| ## Key Components | ||
|
|
||
| - **`lib/crypto/fhe_context.h`**: Manages OpenFHE BGV context. | ||
| - Use `FHEContext::Create()` to initialize. | ||
| - Supports `HomomorphicAdd`, `HomomorphicSubtract`, `HomomorphicRotate`, `HomomorphicMultiplyScalar`. | ||
| - **`lib/crypto/encrypted_polynomial.h`**: Wrapper for FHE ciphertexts. | ||
| - **Server-Safe**: `Add`, `Subtract`, `Rotate`, `MultiplyScalar`, `ProjectToCharacter`. | ||
| - **Client-Only**: `Encrypt`, `Decrypt`. | ||
| - **`lib/crypto/polynomial.h`**: Plaintext polynomial arithmetic (Ring $Z_p[x]/(x^n+1)$). | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| - **Build System**: Bazel | ||
| - Build all: `bazel build //lib/...` | ||
| - Run tests: `bazel test //test/...` | ||
| - Run specific test: `bazel test //test/crypto:encrypted_polynomial_test --test_output=all` | ||
| - **Dependencies**: OpenFHE (via `third_party/openfhe.BUILD`), Abseil, Eigen, GoogleTest. | ||
|
|
||
| ## Local Setup & Running | ||
|
|
||
| - **Prerequisites**: | ||
| - Bazel (latest version) | ||
| - C++ Compiler (Clang/GCC with C++17 support) | ||
| - Git | ||
| - **Setup**: | ||
| 1. Clone the repository. | ||
| 2. Run `bazel build //lib/...` to fetch dependencies (including OpenFHE) and build the core library. | ||
| - **Running Tests**: | ||
| - Run all tests: `bazel test //test/...` | ||
| - Run Alice→Bob integration test: `bazel test //test/integration:alice_to_bob_test --test_output=all` | ||
| - Run FHE stub tests: `bazel test //test/crypto:encrypted_polynomial_test --test_output=all` | ||
|
|
||
| ## Coding Conventions | ||
|
|
||
| - **Language**: C++ (modern standards). | ||
| - **Style**: Google C++ Style (use `absl::StatusOr` for error handling). | ||
| - **FHE Patterns**: | ||
| - **NEVER** decrypt on the server. | ||
| - **ALWAYS** check for Depth-0 compatibility (avoid complex multiplications). | ||
| - Use `EncryptedPolynomial` for all high-level FHE logic. | ||
| - Use `FHEContext` for low-level OpenFHE interactions. | ||
|
|
||
| ## Current Status (Phase 2) | ||
|
|
||
| - **Focus**: Implementing FHE infrastructure. | ||
| - **Active Tasks**: | ||
| - Implement OpenFHE integration in `lib/crypto/fhe_context.cc`. | ||
| - Implement `ProjectToCharacter` in `lib/crypto/encrypted_polynomial.cc`. | ||
| - Create `lib/network/encrypted_mailbox.{h,cc}`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,13 @@ | ||
| # f2chat root BUILD file | ||
|
|
||
| load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands") | ||
|
|
||
| refresh_compile_commands( | ||
| name = "refresh_compile_commands", | ||
| targets = [ | ||
| "//lib/...", | ||
| "//test/...", | ||
| ], | ||
| exclude_headers = "external", | ||
| exclude_external_sources = True, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ version inconsistency.
This states "C++17 support" but
.bazelrcconfigures--cxxopt=-std=c++20. Update for consistency.📝 Committable suggestion
🤖 Prompt for AI Agents