Path: blob/main/frontier/11-homomorphic-encryption/sage/11c-bgv-scheme.ipynb
483 views
Notebook 11c: The BGV Scheme
Module 11: Homomorphic Encryption
Motivating Question. Paillier gives us unlimited additions but no multiplications. How do we get both? The BGV scheme (Brakerski-Gentry-Vaikuntanathan, 2011) is built on Ring-LWE and supports both addition and multiplication, but each operation adds noise. The key innovation: modulus switching controls this noise by scaling down the ciphertext modulus, trading precision for reduced noise.
Prerequisites. You should be comfortable with:
Partial homomorphism and why both operations are needed (Notebook 11b)
Ring-LWE and polynomial rings (Module 08)
Noise growth concepts (Notebook 11a)
Learning objectives. By the end of this notebook you will be able to:
Set up the polynomial ring for BGV encryption.
Encrypt and decrypt messages using the BGV scheme.
Perform homomorphic addition and observe linear noise growth.
Perform homomorphic multiplication and observe quadratic noise growth.
Apply modulus switching to reduce noise after multiplication.
1. The BGV Setup: Polynomial Rings
Bridge from Notebook 11b. Paillier and ElGamal work with integers. BGV works with polynomials, specifically, polynomials in the ring . Why the switch? Two reasons. First, security: each polynomial encodes coefficients, giving us a lattice of dimension , much harder to attack than the 1-dimensional integer LWE from Module 08. This is exactly the Ring-LWE assumption from Notebook 08e. Second, efficiency: polynomial multiplication in can be done in via NTT/FFT, making operations on values nearly as fast as on one. The noise encoding is analogous to Paillier's , both hide the message inside an algebraic structure that supports homomorphic operations.
Parameters:
: ring dimension (power of 2)
: plaintext modulus (messages live in )
: ciphertext modulus (ciphertexts live in , with )
: noise standard deviation
2. BGV Encryption and Decryption
Key Generation:
Secret key: with small coefficients
Public key: where , (small noise),
Encrypt message :
Sample small
Decrypt ciphertext :
Compute
Return
Why does this work? , so as long as the noise is small enough.
Checkpoint 1. The noise in a fresh BGV ciphertext is roughly where is the noise bound. Decryption works as long as the total noise stays below . Every homomorphic operation increases the noise.
3. Homomorphic Addition
Adding two BGV ciphertexts is simple: add component-wise.
The noise adds: .
4. Homomorphic Multiplication (Simplified)
Multiplication is harder. The product of two degree-1 ciphertexts gives a degree-2 ciphertext:
If decrypts as and decrypts as , then:
This gives a "degree-2" ciphertext that decrypts with .
Relinearization converts this back to a standard degree-1 ciphertext (using a special evaluation key).
Misconception alert. "Multiplication noise is just ." It's more complex in the ring setting, cross terms and the ring dimension contribute. The key takeaway: multiplication noise grows quadratically while addition noise grows linearly.
5. Modulus Switching: The BGV Innovation
BGV's key insight: after a multiplication, scale down the ciphertext from modulus to a smaller modulus . This reduces the noise (at the cost of a smaller modulus for future operations).
Idea: If has noise under modulus , then has noise roughly under modulus .
By choosing a chain of decreasing moduli , each multiplication's noise is managed before the next operation.
Checkpoint 2. Modulus switching trades modulus size for noise reduction. After multiplications, we need a chain of moduli. This is why BGV is called a leveled scheme, the number of multiplications is fixed at setup time by the modulus chain length.
6. Putting It Together: A Mini-Computation
Let's compute on encrypted data.
Checkpoint 3. Even with our simplified implementation, you can see the BGV pipeline: encrypt → multiply (noise grows) → modulus switch (noise shrinks) → add (noise grows a little) → decrypt. A full implementation would include relinearization keys and modulus switching on polynomial ciphertexts.
Crypto foreshadowing. The next notebook covers BFV, a closely related scheme with a simpler noise management approach: instead of modulus switching, BFV scales the message into the upper bits of the modulus, giving "scale-invariant" noise behavior.
7. Exercises
Exercise 1 (Worked): Addition Chain
Problem. Encrypt the values 1, 2, 3, 4, 5 (as constant polynomials) and compute their sum homomorphically. Verify the result is .
Solution:
Exercise 2 (Guided): Noise Budget Tracking
Problem. Encrypt a message and repeatedly add it to itself. Track the noise after each addition. At what point does the noise exceed ?
Fill in the TODOs:
Exercise 3 (Independent): Modulus Chain Design
Problem.
For a circuit that requires 3 multiplications and 10 additions, design a modulus chain (choose the initial and the scaling factors).
If initial noise is and each multiplication increases noise by a factor of , what is the minimum initial modulus needed?
How does increasing the ring dimension affect the noise growth per multiplication?
Summary
| Concept | Key Fact |
|---|---|
| BGV encryption | Ciphertext decrypts as |
| Noise encoding | Noise is a multiple of : |
| Addition | Add components; noise adds: (linear) |
| Multiplication | Tensor product; noise multiplies: (quadratic) |
| Modulus switching | Scale from to ; noise drops by factor |
| Leveled FHE | Pre-set modulus chain for multiplications; no bootstrapping needed |
BGV achieves both addition and multiplication by building on Ring-LWE. The price is noise growth, managed by modulus switching. For circuits of known depth, this is very efficient, and avoids the expense of bootstrapping.
Next: 11d: The BFV Scheme