Path: blob/main/frontier/11-homomorphic-encryption/sage/11a-what-is-fhe.ipynb
483 views
Notebook 11a: What Is Fully Homomorphic Encryption?
Module 11: Homomorphic Encryption
Motivating Question. Can you compute on data you can't see? Imagine a hospital that wants a cloud server to run a machine-learning model on patient records, but the server should never see the records. Fully Homomorphic Encryption (FHE) makes this possible: you encrypt the data, the server computes on the ciphertexts, and the result decrypts to the correct answer. No one but the key holder ever sees the plaintext.
Prerequisites. You should be comfortable with:
Modular arithmetic (Module 01)
The Learning With Errors (LWE) problem (Module 08)
Learning objectives. By the end of this notebook you will be able to:
Explain the FHE dream: .
Build a toy symmetric encryption scheme with additive homomorphism.
Observe noise growth as operations accumulate and understand why it limits computation depth.
Describe bootstrapping as the key idea that makes FHE fully homomorphic.
Place FHE in context with a timeline of the four generations.
1. The FHE Dream
Bridge from Module 08. In Module 08 we saw that LWE gives us encryption that's hard to break even for quantum computers. Now we'll exploit the algebraic structure of LWE ciphertexts: adding two ciphertexts adds the underlying messages.
Homomorphic encryption lets you compute on ciphertexts:
If a scheme supports both addition and multiplication on ciphertexts, it's fully homomorphic, you can evaluate any function, because addition + multiplication = any arithmetic circuit.
2. A Toy Symmetric HE Scheme
Let's build the simplest possible homomorphic encryption scheme to see the idea in action.
Secret key: (a random secret modulus- integer)
Encrypt message (small integer, ):
Choose random and small noise
Output ciphertext
Decrypt ciphertext :
Compute (centered in )
Return (this equals , and if is small, we recover approximately)
Checkpoint 1. Decryption recovers (message plus noise). Since is tiny compared to , we can round to recover exactly, as long as the noise stays small. This "noise budget" is the central challenge of FHE.
3. Homomorphic Addition
The magic: if we add two ciphertexts component-wise, the result encrypts the sum of the messages!
This is a valid encryption of with noise .
4. The Noise Problem: Why Multiplication Is Hard
Addition adds noise linearly (). But multiplication makes noise grow multiplicatively. In a proper LWE-based scheme, multiplying two ciphertexts with noise produces noise roughly , which grows exponentially with the number of multiplications.
Let's simulate this with a simple noise-growth model.
Misconception alert. "FHE means unlimited computation on ciphertexts." Without bootstrapping, you can only do a limited number of operations before the noise overwhelms the message. A scheme that supports limited operations is called leveled FHE. True ("pure") FHE requires bootstrapping to reset the noise.
5. Bootstrapping: The Key to "Fully" Homomorphic
In 2009, Craig Gentry had a breakthrough idea: evaluate the decryption circuit homomorphically.
The trick:
You have a noisy ciphertext that's about to overflow.
Encrypt the secret key under a new key : publish .
Homomorphically evaluate using .
The result is , the same message encrypted under , with fresh (low) noise!
This "refreshes" the ciphertext, resetting the noise budget. You can then continue computing.
Checkpoint 2. Bootstrapping is what transforms a somewhat homomorphic scheme (limited operations) into a fully homomorphic one (unlimited operations). The requirement is that the scheme can homomorphically evaluate its own decryption circuit, Gentry called this "squashing" the decryption circuit.
6. Four Generations of FHE
FHE has evolved rapidly since Gentry's 2009 breakthrough:
| Gen | Year | Schemes | Key Innovation | Performance |
|---|---|---|---|---|
| 1st | 2009 | Gentry | Bootstrapping! First proof that FHE is possible | Minutes per gate |
| 2nd | 2011–12 | BGV, BFV | Modulus switching replaces expensive bootstrapping | Seconds per circuit |
| 3rd | 2013 | GSW | Approximate eigenvector technique, simpler design | Improved asymptotic |
| 4th | 2017 | CKKS | Approximate arithmetic for real numbers | Practical for ML |
7. FHE vs Other Privacy Technologies
FHE is one of several approaches to privacy-preserving computation:
| Technology | What it does | Trust model | Performance |
|---|---|---|---|
| FHE | Compute on encrypted data | Single key holder | Slow (10-1000x overhead) |
| MPC | Multiple parties compute together | Threshold trust | Moderate overhead, communication-heavy |
| ZK Proofs | Prove computation was correct | Prover knows witness | Fast verification |
| TEE (e.g., SGX) | Hardware-isolated computation | Trust hardware vendor | Near-native speed |
These are complementary, not competing:
FHE + ZK: FHE keeps inputs encrypted while computing; ZK proves the computation was done correctly. Together they give verifiable computation on private data.
FHE + MPC: distributed key generation, threshold decryption
FHE vs ZK: ZK hides the witness but the computation is public; FHE hides the data but the computation is known to the server. They solve different privacy problems.
All three together: verifiable computation on private, distributed data
Checkpoint 3. FHE is not a silver bullet, it's orders of magnitude slower than plaintext computation. But for applications where the alternative is not computing at all (because the data is too sensitive), even 10,000x overhead is acceptable. The field is rapidly closing the performance gap.
Crypto foreshadowing. The next notebook explores partially homomorphic schemes (RSA, Paillier) that support only one operation. These are much faster and already widely deployed. We'll then build up to the full BGV, BFV, and CKKS schemes in subsequent notebooks.
8. Exercises
Exercise 1 (Worked): Maximum Additions
Problem. Using our toy scheme with and , how many homomorphic additions can we perform before the accumulated noise exceeds ?
Solution:
Exercise 2 (Guided): Noise Growth Experiment
Problem. Encrypt 100 random messages with our toy scheme. Sum them homomorphically and verify the result matches the plaintext sum.
Fill in the TODOs:
Exercise 3 (Independent): Noise Budget Analysis
Problem.
In a scheme where multiplication noise grows as , starting from initial noise , how many sequential multiplications can you perform before exceeding a budget of ?
If each bootstrapping reduces noise back to but costs the equivalent of 100 multiplications in wall-clock time, how much does bootstrapping increase the total computation time for a circuit of depth 20?
Why might CKKS (approximate arithmetic) tolerate more noise than BFV (exact arithmetic)?
Summary
| Concept | Key Fact |
|---|---|
| Homomorphic encryption | Compute on ciphertexts: |
| Noise | Every operation adds noise; too much noise → decryption fails |
| Addition noise | Grows linearly: (cheap) |
| Multiplication noise | Grows multiplicatively: (expensive) |
| Leveled FHE | Supports a bounded number of operations (no bootstrapping) |
| Bootstrapping | Homomorphically decrypt to refresh noise → unlimited operations |
| Fully homomorphic | Leveled + bootstrapping = compute any circuit |
FHE is the most ambitious goal in cryptography: compute anything on encrypted data. The field has gone from theoretical curiosity (2009) to practical deployment (2020s). In the next notebooks, we'll build concrete schemes step by step.