# Coefficient Packing maximum 32 bits

**URL:** https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588
**Category:** Library Questions
**Created:** [May 30, 2023, 10:16am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588 "2023-05-30T10:16:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Bernardo\_Ramalho](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/bernardo_ramalho/32/92_2.png) [@Bernardo\_Ramalho](https://openfhe.discourse.group/u/Bernardo_Ramalho)
#### Post date: [May 30, 2023, 10:16am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/1 "2023-05-30T10:16:55Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)
#### Post date: [May 31, 2023, 1:49pm UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/2 "2023-05-31T13:49:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Bernardo\_Ramalho](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/bernardo_ramalho/32/92_2.png) [@Bernardo\_Ramalho](https://openfhe.discourse.group/u/Bernardo_Ramalho)
#### Post date: [June 1, 2023, 10:40am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/3 "2023-06-01T10:40:12Z")

</div>

Hello

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

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

numbers[0] = 4294967300;

Plaintext plaintext = cryptoContext->MakeCoefPackedPlaintext(numbers);

```

The error output is this:

```auto
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)

```

---

<div class="post-metadata">

### Author: ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)
#### Post date: [June 2, 2023, 3:54am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/4 "2023-06-02T03:54:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bernardo\_Ramalho](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/bernardo_ramalho/32/92_2.png) [@Bernardo\_Ramalho](https://openfhe.discourse.group/u/Bernardo_Ramalho)
#### Post date: [June 2, 2023, 10:25am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/5 "2023-06-02T10:25:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bernardo\_Ramalho](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/bernardo_ramalho/32/92_2.png) [@Bernardo\_Ramalho](https://openfhe.discourse.group/u/Bernardo_Ramalho)
#### Post date: [June 13, 2023, 10:54am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/6 "2023-06-13T10:54:01Z")

</div>

I went into the OpenFHE source files and commented out the if statement from lines 47 to 49 on this [file](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/lib/encoding/coefpackedencoding.cpp).

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.

---

<div class="post-metadata">

### Author: ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)
#### Post date: [June 14, 2023, 2:54am UTC](https://openfhe.discourse.group/t/coefficient-packing-maximum-32-bits/588/7 "2023-06-14T02:54:41Z")

</div>

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.
