# Cifer's Fully Homomorphic Encryption

Cifer’s FHE is our privacy-first encryption framework designed to enable secure computation on **encrypted data and encrypted models** without ever exposing the raw inputs. This approach guarantees data confidentiality throughout the entire machine learning pipeline.

As the next generation of privacy-preserving AI technology, Cifer’s FHE allows you to perform computations directly on encrypted data without the need for decryption. Models trained on encrypted datasets are also protected against reverse engineering, ensuring that adversaries cannot infer or reconstruct the original inputs.

This documentation will guide you through the principles of FHE, demonstrate its key features and benefits, benchmark and performance validation, and explore practical applications. By following these guidelines, you will be equipped to implement encrypted computation in your workflows, ensuring trust, transparency, and compliance with regulatory standards from end to end.

## Table of Contents

1. [Preparation](1.-preparation)
2. [Setup Environment](2.-setup-environment)
3. [Install FHE](3.-install-fhe)
4. [Dataset and Model Preparation](4.-dataset-and-model-preparation)
5. [Encryption](5.-encryption)
6. [Running Federated Learning with Encrypted Assets](6.-federated-learning-with-encrypted-assets)

## How FHE Works <a href="#how-fedlearn-works" id="how-fedlearn-works"></a>

1. **Key Generation:** The public/private key pair is generated.
   * The **public key** is used for encryption and enable computations on the encrypted data. This means anyone who holds the encrypted data—created via the public key—can perform allowed homomorphic operations on that data without needing the private key.
   * The **private key** is exclusively used for decryption of the encrypted data.
2. **Encryption:** The plaintext (raw data or machine learning model parameters) is encrypted using the public key, transforming it into ciphertext. This ciphertext is completely unreadable without the private key.
3. **Secure Computation:** Computations can be performed directly on ciphertexts representing encrypted data, encrypted models, or both, without decryption. This enables privacy-preserving training and inference workflows.
4. **Decryption:** Once computations are complete, the resulting ciphertext is decrypted using the private key, yielding the plaintext output. This output matches exactly what would have been obtained had the operations been performed on the original unencrypted data.
5. **Verification:** The decrypted result can be compared with a direct computation on the plaintext data to verify correctness.

## Key Features of FHE <a href="#key-features-of-fedlearn" id="key-features-of-fedlearn"></a>

* **Privacy Preservation:** Data remains encrypted and inaccessible throughout storage, transfer, and computation, ensuring confidentiality at all times.
* **Secure Computation:** Enables computations directly on encrypted data and encrypted models without decryption, protecting both data privacy and model confidentiality.
* **Accuracy without Distortion:** Unlike differential privacy, FHE does not add noise to data or results; computations produce exact outputs after decryption.
* **End-to-End Encryption:** Supports encryption across the entire AI pipeline—inputs, computations, and outputs remain protected until final decryption.
* **Integrated Privacy Stack:** Combines Federated Learning with FHE to securely compute on encrypted data and encrypted models in distributed machine learning workflows, enhancing overall privacy.

## Benefits of Using FHE <a href="#benefits-of-using-fedlearn" id="benefits-of-using-fedlearn"></a>

1. **Data Privacy and Control:** Sensitive data is encrypted locally before sharing, keeping it confidential throughout storage, transfer, and computation.
2. **Intellectual Property Protection:** Models trained or used in encrypted form are protected against reverse engineering, ensuring confidentiality of intellectual property as well as sensitive data.
3. **Uncompromised Model Accuracy:** Performing computations on encrypted data produces output that is mathematically equivalent to running the same computations on the raw data, ensuring no loss in accuracy.
4. **Compliance-Ready:** By keeping data encrypted throughout processing—including storage, transfer, and computation—FHE supports adherence to strict privacy laws such as GDPR and HIPAA without sacrificing data utility.
5. **Secure Multi-Party Collaboration:** Enables federated learning on encrypted data and models without exposing sensitive information to any party.
6. **Zero Trust Security:** Eliminates trust requirements on infrastructure or intermediaries by keeping data and models encrypted during all computations.

> In summary, FHE ensures robust privacy and accurate encrypted computations, supports compliance with data protection regulations, enables secure collaboration among multiple parties, and minimizes the need to trust external systems in distributed computing environments.

## Benchmark and Performance Validation <a href="#benchmark-and-performance-validation" id="benchmark-and-performance-validation"></a>

This section presents evaluation results using the **Cifer Fraud Detection Model** trained on a subset of 6 million records (1.5 million per node across 4 nodes) from the full 21 million-row **Cifer Fraud Detection Dataset**.

* **Model:** [Cifer Fraud Detection K1-A](https://huggingface.co/CiferAI/cifer-fraud-detection-k1-a)
* **Dataset:** [Cifer Fraud Detection Dataset-AF](https://huggingface.co/datasets/CiferAI/Cifer-Fraud-Detection-Dataset-AF)
* **Total Dataset Size:** 6 million records
* **Training Setup:** Federated Learning across 4 nodes (1.5 million records each)
* **Task:** Fraud detection based on transaction data features

### Accuracy Results

| Data Type                        | Accuracy            |
| -------------------------------- | ------------------- |
| Raw Data                         | 0.9993 (**99.93%**) |
| Encrypted Data (FHE Computation) | 0.9993 (**99.93%**) |
| Decrypted Output                 | 0.9993 (**99.93%**) |

These results confirm that training and computation on encrypted data distributed across federated nodes achieve identical accuracy to training on raw or decrypted data. This demonstrates the framework’s capability to maintain model correctness and privacy simultaneously over a realistic distributed dataset.

## Use Cases <a href="#use-cases" id="use-cases"></a>

FHE is particularly valuable in industries dealing with sensitive data, including:

* **Healthcare:** Conduct encrypted medical research across hospitals while preserving patient confidentiality.
* **Finance:** Develop fraud detection or credit scoring models using customer data without revealing personal financial records.
* **Telecommunications:** Analyze user behavior patterns while ensuring that user data remains confidential.
* **Smart Cities:** Optimize infrastructure with encrypted data from multiple departments and agencies.
* **Legal & Compliance:** Audit, analyze, or train on confidential legal documents without exposing content.
* **Defense & Intelligence:** Enable secure AI operations on classified or high-sensitivity information.
