Is there a limit to plaintext size?

Hello,

I use MakePackedPlaintext function to create a plaintext. I give a vector that contains 100000 integers as an input to MakePackedPlaintext function. After that, I try to encrypt this plaintext. However, I get an error (segmentation fault). I also try to create a plaintext with less size. For example, I got no error for a vector that contains 10000 integers. Is there a limited number of elements that a plaintext is able to contain or do you have any other comment for the reason of this segmentation fault?

Thank you for your time.

Yes, there is a limit on the vector size, and that depends on the scheme and the cryptographic parameters used.
Which scheme are you using? BFV, BGV, or CKKS?

1 Like

I see. I use BFV scheme.

Theoretically, the maximum number of slots one BFV ciphertext may contain is equal to the underlying ring dimension N. Do print N in your main program after initializing the cryptocontext. You can use the line below to print the ring dimension:

std::cout << "N: " << cryptoContext->GetRingDimension() << "\n";

You can increase N by increasing the multiplicative depth via parameters.SetMultiplicativeDepth(depth);. Or you can break down your input data into multiple vectors of size less than or equal to N and use multiple ciphertexts instead.

Note that increasing N unnecessarily may degrade the performance as this will amplify low-level FHE data structures and induce more complex computations.

Also, note that to get the maximum number of slots in BFV, your plaintext modulus should be a prime integer that satisfies the following condition:
1 \equiv t \mod 2N

1 Like

Hi @guliz , could you submit an issue (bug report) about this? MakePackedPlaintext() should probably check if you are trying to encrypt a vector that is too large, and throw an exception, rather than just segfaulting.

Thanks, Dave

1 Like

@dcousins

See Github: Throw an exception if the plaintext size exceeds its limit.

@guliz

Is there a limit to plaintext size?

I think that for practical purposes it depends on how much RAM your computer has but I’ll leave it to the other people to keep me honest

1 Like

Hello @Caesar,

Thank you for your response. I tried to solve the problem by using different multiplicative depth and plaintext modulus. Actually, I can encrypt a vector of 100000 elements in this way.

Thanks.

1 Like

The limit to plaintext size is based on the encoding and the size of the Ciphertext ringsize, as @Caesar showed.
In the extreme, there is a limit of machine memory for any computer program. One can always enable swap memory if your problem gets larger than your ram, however, we suggest at least 32GB if not 64GB ram for large problems.

Hello @dcousins ,

Thank you for your reply. As I said, I can encrypt a vector of 100000 elements by increasing multiplicative depth and plaintext modulus. However, I realized that the calculations I performed on the encrypted data do not give correct results when I increase multiplicative depth too much. After I tried different parameters, I see that the following parameters for the multiplication of the ciphertexts of 100000 elements works for now.

    parameters.SetPlaintextModulus(5767169);
    parameters.SetMultiplicativeDepth(5);
    parameters.SetRingDim(262144);

Thanks

Hi, while this may fit, We suggest that you do not try to fit everything into one ciphertext. You should work with a vector of ciphertext instead. In other words, multiple ciphertexts can be used to represent a vector of a large size.

Larger size Ciphertext (i.e. ringsize) make everything run more slowly in general. Approx NlogN slower where N is the ring size.

1 Like