D-2.2 Batch Encoding

While the single-value encoding scheme (§D-2.1) encodes & decodes each individual value one at a time, the batch encoding scheme does the same for a huge list of values simultaneously using a large dimensional vector. Therefore, batch encoding is more efficient than single-value encoding. Furthermore, batch-encoded values can be homomorphically added or multiplied simultaneously element-wise by vector-to-vector addition and Hadamard product. Therefore, the homomorphic operation of batch-encoded values can be processed more efficiently in a SIMD (single-instruction-multiple-data) manner than single-value encoded ones.

BFV’s encoding converts an n-dimensional integer input slot vector v = (v0,v1,v2,vn1) modulo t into another n-dimensional vector m = (m0,m1,m2,mn1) modulo t, which are the coefficients of the encoded (n 1)-degree (or lesser-degree) polynomial M(X) t[X](Xn + 1).

D-2.2.1 Encoding1

In §A-10.6, we learned that an (n 1)-degree (or lesser degree) polynomial can be isomorphically mapped to an n-dimensional vector based on the mapping σ (we notate σc in §A-10.6 as σ for simplicity):

σ : M(X) t[X](Xn + 1)(M(ω),M(ω3),M(ω5),,M(ω2n1)) tn

, which evaluates the polynomial M(X) at n distinct (μ = 2n)-th primitive roots of unity: ω,ω3,ω5,,ω2n1. Let m be a vector that contains n coefficients of the polynomial M(X). Then, we can express the mapping σ as follows:

v = WT m

, where WT is as follows:

WT = [ 1 (ω) (ω)2 (ω)n1 1 (ω3) (ω3)2 (ω3)n1 1 (ω5) (ω5)2 (ω5)n1 1 (ω2n1) (ω2n1)2 (ω2n1)n1 ] # WT is a transpose of W described in §A-10.6

Note that the dot product between each row of WT and m computes the evaluation of M(X) at each X = {w,w3,w5,,w2n1}. In the BFV encoding scheme, the Encoding1 process encodes an n-dimensional input slot vector v t into a plaintext polynomial M(X) t[X](Xn + 1), and the Decoding2 process decodes M(X) back to v. Since WT m gives us v which is a decoding of M(X), we call WT a decoding matrix. Meanwhile, the goal of Encoding1 is to encode v into M(X) so that we can do homomorphic computations based on M(X). Given the relation v = WT m, the encoding formula can be derived as follows:

(WT )1 v = (WT )1WT m

m = (WT )1 v

Therefore, we need to find out what (WT )1 is, the inverse of WT as the encoding matrix. But we already learned from Theorem A-11.4 (in §A-11.4) that V 1 = V T InR n , where V = WT and V = W. In other words, (WT )1 = W InR n . Therefore, we can express the BFV encoding formula as:

m = (WT )1 v = W InR v n , where

W = [ 1 1 1 1 (ω) (ω3) (ω5) (ω2n1) (ω)2 (ω3)2 (ω5)2 (ω2n1)2 (ω)n1 (ω3)n1 (ω5)n1 (ω2n1)n1 ]

= [ 1 1 1 1 1 1 (ω) (ω3) (ωn 2 1) (ω(n 2 1)) (ω3) (ω1) (ω)2 (ω3)2 (ωn 2 1)2 (ω(n 2 1))2 (ω3)2 (ω1)2 (ω)n1 (ω3)n1 (ωn 2 1)n1 (ω(n 2 1))n1 (ω3)n1 (ω1)n1 ]

, where ω = gt1 2n mod t (g is a generator of t×). In §A-10.6, we learned that W is a valid basis of the n-dimensional vector space. Therefore, W v n = m is guaranteed to be a unique vector corresponding to each v in the n-dimensional vector space tn (refer to Theorem A-10.4 in §A-10.4), and thereby the polynomial M(X) comprising the n elements of m as coefficients is a unique polynomial bi-jective to v.

Note that by computing W InR v n , we transform the input slot vector v into another vector m in the same vector space tn, while preserving isomorphism between these two vectors (i.e., bi-jective one-to-one mappings and homomorphism on the (+,⋅) operations).

D-2.2.2 Encoding2

Once we have the n-dimensional vector m, we scale (i.e., multiply) it by some scaling factor Δ = q t, where q is the ciphertext modulus. We scale m by Δ and make it Δm. The n integers in Δm will be used as n coefficients of the plaintext polynomial for RLWE encryption. The finally encoded plaintext polynomial ΔM = i=0n1ΔmiXi.

D-2.2.3 Decoding1

Once an RLWE ciphertext is decrypted to ΔM = i=0n1ΔmiXi, we compute Δm Δ = m.

D-2.2.4 Decoding2

In §D-2.2.1, we already derived the decoding formula that transforms an (n 1)-degree polynomial having integer modulo t coefficients into an n-dimensional input slot vector as follows:

v = WT m

D-2.2.5 Summary

Summary D-2.2.5 BFV’s Encoding and Decoding

Input: An n-dimensional integer modulo t vector v = (v0,v1,,vn1) tn


Encoding

1.
Convert v tn into m tn by applying the transformation m = n1 W InR v

, where W is a basis of the n-dimensional vector space crafted as follows:

W = [ 1 1 1 1 (ω) (ω3) (ω5) (ω2n1) (ω)2 (ω3)2 (ω5)2 (ω2n1)2 (ω)n1 (ω3)n1 (ω5)n1 (ω2n1)n1 ]

= [ 1 1 1 1 1 1 (ω) (ω3) (ωn 2 1) (ω(n 2 1)) (ω3) (ω1) (ω)2 (ω3)2 (ωn 2 1)2 (ω(n 2 1))2 (ω3)2 (ω1)2 (ω)n1 (ω3)n1 (ωn 2 1)n1 (ω(n 2 1))n1 (ω3)n1 (ω1)n1 ]

, where ω = gt1 2n mod t (g is a generator of t×)

2.
Convert m into a scaled integer vector Δm, where 1 Δ q t is a scaling factor. If Δ is too close to 1, the noise budget will become too small. If Δ is too close to q t, the plaintext budget will become too small (i.e., cannot wrap around t much). The finally encoded plaintext polynomial ΔM = i=0n1ΔmiXi  q[X](Xn + 1).


Decoding: From the plaintext polynomial ΔM = i=0n1ΔmiXi, recover m = Δm Δ . Then, compute v = WT m.

However, Summary D-2.2.5 is not the final version of BFV’s batch encoding. In §D-2.9, we will explain how to homomorphically rotate the input vector slots without decrypting the ciphertext that encapsulates it. To support such homomorphic rotation, we will need to slightly update the encoding scheme explained in Summary D-2.2.5. We will explain how to do this in §D-2.9, and BFV’s final encoding scheme is summarized in Summary D-2.9.3 in §D-2.9.3.