Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build --cxxopt=-Wextra
build --cxxopt=-Werror

# Suppress GCC false positives in Abseil (known issue with InlinedVector)
build --cxxopt=-Wno-unknown-warning-option
build --cxxopt=-Wno-error=maybe-uninitialized

# No exceptions needed (pure polynomial algebra, no OpenFHE)
Expand All @@ -18,7 +19,7 @@ build --cxxopt=-O2
build --cxxopt=-g

# Fast math for polynomial operations
build --cxxopt=-ffast-math
# build --cxxopt=-ffast-math

# Test configuration
test --test_output=errors
Expand Down
65 changes: 65 additions & 0 deletions .github/copilot-instructions.md
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

C++ version inconsistency.

This states "C++17 support" but .bazelrc configures --cxxopt=-std=c++20. Update for consistency.

-  - C++ Compiler (Clang/GCC with C++17 support)
+  - C++ Compiler (Clang/GCC with C++20 support)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- C++ Compiler (Clang/GCC with C++17 support)
- C++ Compiler (Clang/GCC with C++20 support)
🤖 Prompt for AI Agents
.github/copilot-instructions.md around line 39: the doc states "C++17 support"
but the repository's .bazelrc sets --cxxopt=-std=c++20 causing an inconsistency;
update the instruction text to reference C++20 (or change .bazelrc to C++17 if
the project requires C++17) so they match, and ensure any other docs or CI
configs are aligned to the chosen standard.

- 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}`.
12 changes: 12 additions & 0 deletions BUILD.bazel
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,
)
24 changes: 24 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module(name = "f2chat", version = "2.0.0")
# Core dependencies
bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "com_google_absl")
bazel_dep(name = "googletest", version = "1.15.2")
bazel_dep(name = "google_benchmark", version = "1.8.3")
bazel_dep(name = "eigen", version = "3.4.0")
bazel_dep(name = "rules_foreign_cc", version = "0.12.0")
bazel_dep(name = "rules_cc", version = "0.0.2")

# OpenFHE for homomorphic encryption
# Note: OpenFHE is added via git_repository since it's not in BCR
Expand All @@ -17,3 +20,24 @@ git_repository(
tag = "v1.2.1", # Last stable version with Bazel support
build_file = "//third_party:openfhe.BUILD",
)

# Cereal for serialization (required by OpenFHE)
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "cereal",
urls = ["https://github.com/USCiLab/cereal/archive/refs/tags/v1.3.2.tar.gz"],
sha256 = "16a7ad9b31ba5880dac55d62b5d6f243c3ebc8d46a3514149e56b5e7ea81f85f",
strip_prefix = "cereal-1.3.2",
build_file = "//third_party:cereal.BUILD",
)

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)

git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "abb61a688167623088f8768cc9264798df6a9d10",
)
Loading