D-4.7 Modulus Switch

- Reference 1: Design and implementation of HElib: a homomorphic encryption library [21]

- Reference 2: Fully Homomorphic Encryption without Bootstrapping [22]

- Reference 3: Homomorphic Evaluation of the AES Circuit [23]

Remember that the requirement of modulus switch is that while we change the ciphertext modulus from q to q^, it should decrypt to the same plaintext M. BGV’s modulus switch is similar to that of the RLWE modulus switch (§C-4.4), but there is an additional requirement, because BGV applies the scaling factor Δ not to plaintext M, but to noise E. In the case of BFV or CKKS, their decryption process only needs to round off the noise in the low-digit area. However, in the case of BGV, the plaintext is in the low-digit area and its decryption process has to remove the noise in the higher-bit area by modulo-t reduction (i.e., the plaintext modulus). More concretely, BGV’s modulus switch from (A,B) mod ql (A^,B^) mod q^ should satisfy the decryption relation such that ((A^ S + B^) mod q^) mod t = M. In BGV’s modulus switch, q^ does not have to be one of the multiplicative levels of the ciphertext, and q^ only needs to satisfy the relationship: q^ < ql and q^ 1 mod t. BGV’s modulus switch procedure is as follows:

1.
The input ciphertext is 𝖼𝗍 = (A,B) mod ql. We compute new polynomials A and B as follows:

(A,B) = (q^ ql A, q^ ql B)(𝑚𝑜𝑑q^)

And we compute the rounding error 𝜖A,𝜖B as follows:

𝜖A = q^ ql A A

𝜖B = q^ ql B B

, which we rewrite as follows:

q^A = qlA+ ql𝜖A = qlA+ 𝜖A # we denote 𝜖A = ql𝜖A, where 𝜖A ql

q^B = qlB+ ql𝜖B = qlB+ 𝜖B # we denote 𝜖B = ql𝜖B, where 𝜖B ql

2.
We compute new polynomials HA and HB as follows:

HA = ql1 𝜖Amod t

HB = ql1 𝜖Bmod t

3.
We compute the final mod-switched ciphertext 𝖼𝗍^ as follows:

𝖼𝗍^ = (A^,B^) = (A+ HA, B+ HB) mod q^

Note that the computation result of A+ HA and B+ HB alone can exceed the range q^, because A,B q^ and HA,HB t. Therefore, we need to reduce A+ HA and B+ HB modulo q^ to derive A^ q^ and B^ q^.

4.
From now on, we will verify that 𝖼𝗍^ is a valid ciphertext satisfying BGV’s required decryption relation. First, we can derive the relationship among 𝖼𝗍 = (A,B), A+ HA, and B+ HB as follows:

q^ 𝖼𝗍 mod t = (q^A,q^B) mod t

= (qlA+ 𝜖A, qlB+ 𝜖B) mod t # applying step 1’s result: q^A = qlA+ 𝜖A, q^B = qlB+ 𝜖B

= (qlA+ qlHA, qlB+ qlHB) mod t # applying step 2’s result: HA = ql1 𝜖Amod t, HB = ql1 𝜖Bmod t

= ql (A+ HA, B+ HB) mod t

So, q^ 𝖼𝗍 = ql (A+ HA, B+ HB) mod t. But in BGV, ql q2 qL 1 mod t. Thus, the following holds:

𝖼𝗍 = (A,B) = (A+ HA, B+ HB)(𝑚𝑜𝑑t)

5.
We can derive the decryption relation of 𝖼𝗍^ from the decryption relation of 𝖼𝗍 as follows:

M = (A S + B mod ql) mod t # The BGV decryption relation of 𝖼𝗍 = (A,B) mod ql

= (A S + B K ql) mod t # where K ql represents the modulo-ql reduction

= ((A+ HA) S + B+ HB K ql) mod t # applying step 4’s result: A A+ HA mod t, B B+ HB mod t

= ((A+ HA) S + B+ HB K q^) mod t # since in BGV, q1 q2 qL 1 mod t, and we chose q^ such that q^ 1 mod t

Now, if we can prove that (A+ HA) S + B+ HB K q^ = (A+ HA) S + B+ HB mod q^ (i.e., K q^ reduces (A+ HA) S + B+ HB modulo-q^), then this sufficiently leads to the conclusion that ((A+ HA) S + B+ HB mod q^) mod t = M.

6.
The following is also true:

(A+ HA) S + B+ HB mod q^

= |A+ HA|q^ S + |B+ HB|q^ mod q^

# where |A+ HA|q^ = A+ HA mod q^, |B+ HB|q^ = B+ HB mod q^

= A^ S + B^ mod q^ # applying step 3: A^ = A+ HA mod q^, B^ = B+ HB mod q^

Therefore, proving (A+ HA) S + B+ HB K q^ = (A+ HA) S + B+ HB mod q^ is equivalent to proving (A+ HA) S + B+ HB K q^ = A^ S + B^ mod q^.

7.
We will prove that (A+ HA) S + B+ HB K q^ = (A+ HA) S + B+ HB mod q^ as follows:

(A+ HA) S + B+ HB K q^

= (q^ ql A 𝜖A ql + HA) S + (q^ ql B 𝜖B ql + HB) K q^

# applying step 1’s result: A = q^ ql A 𝜖A ql , B = q^ ql B 𝜖B ql

= (q^ ql A S + q^ ql B K q^) + HA S + HB 𝜖A ql S 𝜖B ql # rearranging the terms

= q^ ql (A S + B K ql) + HA S + HB 𝜖A ql S 𝜖B ql # taking out the common factor q^ ql

= q^ ql (A S + B mod ql) + HA S + HB 𝜖AS + 𝜖B ql # since A S + B K ql = A S + B mod ql

For successful decryption, every coefficient of the resulting polynomial of the above expression has to be within the range q^ (which means that K q^ has successfully reduced (A+ HA) S + B+ HB modulo q^). The first term q^ ql (A S + B mod ql) can be viewed as the original ciphertext ct’s noise (with the plaintext message) scaled down by q^ ql . The coefficients of the second term HA S are also small, because HA t and S 3. The coefficients of the third term HB are also small, because HB t. The coefficients of the last term 𝜖AS + 𝜖B ql are also small, because 𝜖A ql and 𝜖B ql are ql q^ .

Therefore, (A+ HA) S + B+ HB K q^ = (A+ HA) S + B+ HB mod q^ (provided the above error thresholds hold).

8.
Finally, we combine the results of step 6 and 7 as follows:

(A^ S + B^) mod q^ mod t

= ((A+ HA) S + B+ HB mod q^) mod t # by applying step 6

= (A S + B mod ql) mod t # by applying step 7

= M

This means that decrypting (A^,B^) mod q^ outputs the message M.

We summarize BGV’s modulus switch as follows:

Summary D-4.7 BGV’s Modulus Switch

Suppose we have the current ciphertext modulus ql and new ciphertext modulus q^ where ql q^ 1 mod t and q^ < ql. Therefore, q^ may or may not be one of the ciphertext moduli comprising a BGV ciphertext’s multiplicative level moduli q0,q1,,qL.

BGV’s modulus switch from ql q^ is equivalent to updating (A,B) mod ql to (A^,B^) mod q^ as follows:

(A,B) = (q^ ql A, q^ ql B) Rn,q^2

𝜖A = q^ A ql A # where 𝜖A ql

𝜖B = q^ B ql B # where 𝜖B ql

HA = ql1 𝜖Amod t

HB = ql1 𝜖Bmod t

𝖼𝗍^ = (A^,B^) = (A+ HA,B+ HB) mod q^

After the modulus switch (i.e., the noise scaling factor), Δ = t stays the same as before. The secret key S also stays the same as before. The noise gets scaled down roughly by q^ ql , but this does not decrease the noise-to-ciphertext modulus ratio.

D-4.7.1 Difference between Modulus Switch and ModDrop

In the case of CKKS (§D-3.5.4), the difference between modulus switch and ModDrop is that the former scales down the plaintext’s scaling factor by ql ql1 1 Δ, whereas ModDrop does not affect the plaintext’s scaling factor.

Similarly, in the case of BGV, modulus switch (rescaling) and ModDrop from ql ql1 both lower a BGV ciphertext’s modulus from ql ql1. However, the key difference is that rescaling also decreases the noise’s scaling factor by ql ql1 1 Δ, whereas ModDrop keeps the noise’s scaling factor the same as it is. Therefore, rescaling is used only during ciphertext-to-ciphertext multiplication (to be explained in §D-4.8) when scaling down the plaintext’s scaling factor in the intermediate ciphertext from Δ2 Δ. Meanwhile, ModDrop is used to reduce the modulo computation time during an application’s routine when it becomes certain that the ciphertext will not undergo any additional ciphertext-to-ciphertext multiplication (i.e., no need to further decrease the ciphertext’s modulus).

The main difference in modulus switch between CKKS and BGV is that the former decreases the plaintext’s scaling factor by approximately 1 Δ, whereas the latter decreases the noise’s scaling factor by approximately 1 Δ.

Source Code: Examples of BGV modulus switch can be executed by running this Python script.