D-3.9 Homomorphic Rotation of Input Vector Slots

CKKS’s batch encoding scheme (Summary D-3.1 in §D-3.1) implicitly supports homomorphic rotation of input slot vectors like that of BFV’s homomorphic rotation (Summary D-2.9.3 in §D-2.9.3). This is because CKKS uses the same encoding and decoding matrices (W~ and W~) designed for the BFV encoding and decoding scheme that supports homomorphic rotation of input vector slots. Although the roots of the (μ = 2n)-th cyclotomic polynomial Xn + 1 are different for the BFV and CKKS schemes (as one is designed over X t and the other is over X ), CKKS still can use the same W~ (and W~) matrices as BFV, because the (μ = 2n)-th cyclotomic polynomial over X t exhibits the same essential properties as the (μ = 2n)-th cyclotomic polynomial over X (as explained in §A-9). Especially, the roots of both (μ = 2n) cyclotomic polynomials are the primitive (μ = 2n)-th roots of unity having the order 2n, and those n distinct roots are defined as ω1,ω3,,ω2n1, where ω can be any root. Therefore, substituting CKKS’s (μ = 2n)-th roots of unity into the ω terms in BFV’s encoding matrix W~ (and decoding matrix W~) preserves the same computational correctness for the encoding and decoding schemes, as well as for input vector slot rotation.

Importantly, the W~ and W~ matrices in both the BFV and CKKS schemes satisfy the exact requirement for supporting input vector slot rotation. That is, given the following relations:

, updating the polynomial M(X) to M(XJ(h)) results in the effect of rotating the first half of the n-dimensional input vector slots (v pn in the case of BFV, and the forward-ordered Hermitian vector v ^n n 2 in the case of CKKS) by h positions to the left (in a wrapping manner among them) and the second half of the slots also by h positions to the right (in a wrapping manner among them).

BFV uses CKKS’s same rotation scheme described in Summary D-2.9.3 (in §D-2.9.3) as follows:

Summary D-3.9 CKKS’s Homomorphic Rotation of Input Vector Slots

Suppose we have an RLWE ciphertext and a key-switching key as follows:

𝖱𝖫𝖶𝖤S,σ(ΔM) = (A,B), 𝖱𝖫𝖾𝗏S,σβ,l(SJ(h))

Then, the procedure of rotating all n 2 elements of the ciphertext’s original input vector v by h positions to the left is as follows:

1.
Update A(X), B(X) to A(XJ(h)), B(XJ(h)).
2.
Perform the following key switching (§D-3.8) from S(XJ(h)) to S(X):

𝖱𝖫𝖶𝖤S(X),σ(ΔM(XJ(h))) = (0,B(XJ(h))) + 𝖣𝖾𝖼𝗈𝗆𝗉β,l(A(XJ(h))), 𝖱𝖫𝖾𝗏S(X),σβ,l(S(XJ(h)))

Rotation within Half Slots: Like BFV, CKKS rotates the first half of the forward-ordered Hermitian input vector slots v ^n and the second half of its slots separately in a partitioned manner. This is because the first half rows of W~ comprise the terms ωJ(h) for h = {0,1,,n 2 1} (i.e., evaluates M(X) at X = {ωJ(0),ωJ(1),,ωJ(n 2 1)}), whereas the second half rows of W~ comprise the terms ωJ(h) (i.e., evaluates M(X) at X = {ωJ(0),ωJ(1),,ωJ(n 2 1)}), and the computed values of J(h) and J(h) repeat (i.e., rotate) within their own rotation group across h = {0,1,,n 2 1}. Because of this structure of W~ and W~, BFV and CKKS cannot design a wrapping rotation scheme across all n slots of the input vector homogeneously, but can instead design a wrapping rotation scheme across each group of the first-half and the second-half n 2 slots of the input vector in a partitioned manner. That being said, CKKS can meaningfully only use the first n 2 slots for homomorphic computations anyway, because the latter n 2 slots are conjugates of the first n 2 slots which cannot be chosen by the user but are deterministically configured based on the first n 2. On the other hand, in BFV, the user can choose the entire n 2 according to his/her needs, so BFV’s utility of slots is full n. Therefore, the user can use BFV’s first-half slots and second-half slots together to perform parallel computations.

D-3.9.1 Example

In this subsection, we will show the following 2 examples:

1.
Encode an input vector v into a plaintext polynomial M(X) based on our updated updated encoding & decoding matrices W~ and W~
2.
Rotate all elements of the input vector v h positions to the left by updating the encoded plaintext M(X) to M(XJ(h))

We will use the same example of the input vector v used in §D-3.1.1: vh=1 = (1.1 + 4.3i,3.5 1.4i).

Remember that the encoded plaintext polynomial of v is as follows:

ΔM(X) = 2355 + 1195X + 1485X2 + 2933X3 R4 [X]X4 + 1

Suppose we want to rotate the input vector v by 1 position to the left as follows:

vh=1 = (3.5 1.4i,1.1 + 4.3i)

Therefore, we update ΔM(X) to ΔM(XJ(1)) as follows:

ΔM(XJ(1)) = ΔM(X5) = 2355 + 1195(X5) + 1485(X5)2 + 2933(X5)3

= 2355 + 1195X5 + 1485X10 + 2933X15

= 2355 + 1195X (1) + 1485X2 (1) (1) + 2933X3 (1) (1) (1)

= 2355 1195X + 1485X2 2933X3

The rotated forward-ordered Hermitian input vector is computed as follows:

W~Δm Δ = [ 1,ω,ω2,ω3 1,ω3,ω6,ω 1,ω¯,ω2¯,ω3¯ 1,ω3¯,ω6¯,ω¯ ]

[ 2355 1195 1485 2933 ] 1 1024

= [ 1,2 2 + i2 2 ,i,2 2 + i2 2 1,2 2 i2 2 ,i,2 2 i2 2 1,2 2 + i2 2 ,i,2 2 + i2 2 1,2 2 i2 2 ,i,2 2 i2 2 ] [ 2.2998046875 1.1669921875 1.4501953125 2.8642578125 ]

(3.500 1.4003i, 1.0997 + 4.3007i, 3.500 + 1.4003i, 1.0997 4.3007i)

Extract the first n 2 = 2 elements in the above Hermitian vector to recover the input vector:

(3.500 1.4003i, 1.0997 + 4.3007i)

(3.5 1.4i, 1.1 + 4.3i) = vh=1 # The original input vector v rotated by 1 position to the left

In practice, we do not directly update ΔM(X) to ΔM(XJ(1)), because we would not have access to the plaintext polynomial M(X) unless we have the secret key S(X). Therefore, we instead update 𝖼𝗍 = (A(X),B(X)) to 𝖼𝗍h=1 = (A(XJ(1)),B(XJ(1))), which is equivalent to homomorphically rotating the encrypted input vector slots. Then, decrypting 𝖼𝗍h=1 and decoding it would output vh=1.

Source Code: Examples of CKKS’s homomorphic input vector slot rotation can be executed by running this Python script.