Maximum CoefPacked/Packed Plaintext Size

Hello,

So I’m using the BFV scheme and experimenting with MakeCoefPackedPlaintext and MakePackedPlaintext. My question is, what is the maximum number of elements I can encrypt with each one?

For context, my n = cryptoContext->GetCryptoParameters()->GetElementParams()->GetCyclotomicOrder() / 2 is equal to n = 8192 .

In MakePackedPlaintext, I get an error if I try to encrypt a vector with size 8194 (so I can encrypt a vector with 8193 elements). In MakeCoefPackedPlaintext, I can encrypt vectors with size 16385. I didn’t test this one for error since I can’t understand the limit. I thought 8192 elements would be the maximum size for both plaintexts.

Theoretically, you should only be able to pack n values, where n is the underlying ring dimension. Note for PackedEncoding, the number of available slots depends on the plaintext modulus you choose. To get the maximum number of slots in PackedEncoding, your plaintext modulus t should be a prime integer that satisfies the following condition:
1\equiv t \pmod{m=2n}

You can change t to get different plaintext algebras with a lower number of slots, but these are trickier to treat. For a complete treatment of this, you can refer to Appendix C in this work.

@Bernardo_Ramalho Yes, the limit should be 8192 for n = 8192. We will look into this. The exception handling for this case should be changed.

Created an issue for this: MakeCoefPackedPlaintext allows encoding more integers than the number of slots · Issue #340 · openfheorg/openfhe-development · GitHub

Hi @Bernardo_Ramalho, we failed to regenerate the problem reported above as OpenFHE does raise an exception for a proper info message as detailed here. OpenFHE does not allow encoding vectors of size larger than n for both encoding methods MakeCoefPackedPlaintext and MakePackedPlaintext.
If you can help us in regenerating this issue, that would be helpful so we can fix the issue if it exists.

Hey, sorry for the delay but you can check the code I used to test this here HE_Optimization/plaintextSize.cpp at variance · BernardoRamalho/HE_Optimization · GitHub

If you have any problem accessing it I can paste the code here

Hi @Bernardo_Ramalho
I have just executed your program against OpenFHE (dev branch: commit ID: 60b59f7008a2de0657ce6956badef647d2739772) and I got the following putout:

n = 8192
log2 q = 180
Encrypting vector v of size: 8192
Encrypting vector r of size: 8194
terminate called after throwing an instance of 'lbcrypto::config_error'
  what():  /home/caesar/development/projects/openfhe_issues/openfhe-development/src/pke/include/encoding/plaintextfactory.h:89 The size [8194] of the vector with values should not be greater than ringDim [8192] if the scheme is NOT CKKS
Aborted

The behavior is expected and the message is clear enough to explain the issue.

That is very weird, when I run I get the following output:

n = 8192
log2 q = 180
Encrypting vector v of size: 8192
Encrypting vector r of size: 8194
Encrypting vector p of size: 16384
Encrypting vector s of size: 16385
terminate called after throwing an instance of 'lbcrypto::type_error'
  what():  /usr/local/include/openfhe/pke/encoding/plaintext.h:361 not a packed coefficient vector

I have just tried against OpenFHE the main branch (commit ID 122f470) and I still got the same error message I noted above. Could you try running against OpenFHE v1.0.3?