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 -dimensional integer input slot vector modulo into another -dimensional vector modulo , which are the coefficients of the encoded -degree (or lesser-degree) polynomial .
In §A-10.6, we learned that an -degree (or lesser degree) polynomial can be isomorphically mapped to an -dimensional vector based on the mapping (we notate in §A-10.6 as for simplicity):
, which evaluates the polynomial at distinct -th primitive roots of unity: . Let be a vector that contains coefficients of the polynomial . Then, we can express the mapping as follows:
, where is as follows:
# is a transpose of described in §A-10.6
Note that the dot product between each row of and computes the evaluation of at each . In the BFV encoding scheme, the Encoding1 process encodes an -dimensional input slot vector into a plaintext polynomial , and the Decoding2 process decodes back to . Since gives us which is a decoding of , we call a decoding matrix. Meanwhile, the goal of Encoding1 is to encode into so that we can do homomorphic computations based on . Given the relation , the encoding formula can be derived as follows:
Therefore, we need to find out what is, the inverse of as the encoding matrix. But we already learned from Theorem A-11.4 (in §A-11.4) that , where and . In other words, . Therefore, we can express the BFV encoding formula as:
, where
, where ( is a generator of ). In §A-10.6, we learned that is a valid basis of the -dimensional vector space. Therefore, is guaranteed to be a unique vector corresponding to each in the -dimensional vector space (refer to Theorem A-10.4 in §A-10.4), and thereby the polynomial comprising the elements of as coefficients is a unique polynomial bi-jective to .
Note that by computing , we transform the input slot vector into another vector in the same vector space , while preserving isomorphism between these two vectors (i.e., bi-jective one-to-one mappings and homomorphism on the operations).
Once we have the -dimensional vector , we scale (i.e., multiply) it by some scaling factor , where is the ciphertext modulus. We scale by and make it . The integers in will be used as coefficients of the plaintext polynomial for RLWE encryption. The finally encoded plaintext polynomial .
Once an RLWE ciphertext is decrypted to , we compute .
In §D-2.2.1, we already derived the decoding formula that transforms an -degree polynomial having integer modulo coefficients into an -dimensional input slot vector as follows:
Summary D-2.2.5 BFV’s Encoding and Decoding
Input: An -dimensional integer modulo vector
Encoding
, where is a basis of the -dimensional vector space crafted as follows:
, where ( is a generator of )
Decoding: From the plaintext polynomial , recover . Then, compute .
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.