Coefficient Packing maximum 32 bits

Hello,

I was trying to encrypt some big int values and, while I can do it with Slot Packing, when I use Coefficient packing, I get an error saying that I can’t encrypt values bigger than 32 bits.

Why is that and is there any way to circumvent that?

Hi - please share a code snippet and the exact error message you received.

Hello

The code is this, using a plaintext modulus of 7000000462849:

std::vector<int64_t> numbers(8192, 0);

numbers[0] = 4294967300;

Plaintext plaintext = cryptoContext->MakeCoefPackedPlaintext(numbers);

The error output is this:

terminate called after throwing an instance of 'lbcrypto::config_error'
  what():  /home/bernardoramalho99/Tese/openfhe-development/src/pke/lib/encoding/coefpackedencoding.cpp:48 Cannot encode a coefficient larger than 32 bits
Aborted (core dumped)

Yes, the plaintext modulus in BGV/BFV is currently limited to 32 bits. Using larger values will significantly increase the runtime. So we always suggest working with smaller plaintext moduli (less than 32 bits). Typically it is faster to use multiple slots with smaller plaintext moduli (using so-called plaintext CRT) rather than work with a single slot of a large plaintext modulus.

That makes sense but why does it only happen with coefficient packing? If I run the same code but instead of cryptoContext->MakeCoefPackedPlaintext() I use cryptoContext->MakePackedPlaintext(), I get no error.

I went into the OpenFHE source files and commented out the if statement from lines 47 to 49 on this file.

After testing, all the operations work as intended, so I don’t know if this is something you want to remove or also put on the slot packing implementation.

We have not tested the setup for plaintext moduli larger than 32 bits. It may work for the CoefPacked encoding (I would expect it to be trickier for the regular Packed encoding). However, there is a limit up to which it may work as each modulus in BGV is at least [plaintext modulus] * 4 * [ring dimension]. So a 43-bit modulus may work, but I would not expect a 59-bit modulus to work, for example. So I suggest using this option with caution.