# Problem during CryptoContext generation for BGV

**URL:** <https://openfhe.discourse.group/t/problem-during-cryptocontext-generation-for-bgv/2059>\
**Category:** Library Questions\
**Tags:** bugs\
**Created:** [June 3, 2025, 2:48pm UTC](https://openfhe.discourse.group/t/problem-during-cryptocontext-generation-for-bgv/2059 "2025-06-03T14:48:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![julienB](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@julienB](https://openfhe.discourse.group/u/julienB)\
**Post date:** [June 3, 2025, 2:48pm UTC](https://openfhe.discourse.group/t/problem-during-cryptocontext-generation-for-bgv/2059/1 "2025-06-03T14:48:06Z")

</div>

Hello OpenFHE team and thank you for your great library.

I was doing some test with BGV to know the value that is automatically chosen for the Ring Dimension depending on the Multiplicative Depth and the Plaintext Modulus. For most value, I have no issue but sometimes, I get a strange exception :

_“openfhe-development/src/pke/lib/scheme/bgvrns/bgvrns-parametergeneration.cpp:l.642:ParamsGenBGVRNSInternal(): The ring dimension found using estimated logQ(P) [16384] does does not meet security requirements. Report this problem to OpenFHE developers and set the ring dimension manually to 32768.  
Aborted (core dumped)”_

A code that result in this error is the following :

> CCParams\< CryptoContextBGVRNS \> parameters;
> 
> parameters.SetPlaintextModulus(786433);  
> parameters.SetMultiplicativeDepth(6);
> 
> CryptoContext cc = GenCryptoContext(parameters);
> 
> cc-\>Enable(PKE);  
> cc-\>Enable(KEYSWITCH);  
> cc-\>Enable(LEVELEDSHE);  
> cc-\>Enable(ADVANCEDSHE);
> 
> cout \<\< cc-\> GetRingDimension() \<\< endl;

I want to add that this error only occurs for Multiplicative Depth 6 but I found other Modulus that leads to the same exepction.(mostly values around 19-20 bits). Also, I did the same test for BFV before that and never got that mistake.

I tought it would be important to share this mistake because the exception told me to do so.

---

<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 3, 2025, 4:34pm UTC](https://openfhe.discourse.group/t/problem-during-cryptocontext-generation-for-bgv/2059/2 "2025-06-03T16:34:57Z")

</div>

Thank you for reporting this issue. There is a small probability for it, and we put this safeguard in place to see if we run into it in practice. I created an issue for this: [Exception thrown during CryptoContext generation for BGV · Issue #997 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/issues/997)

---

<div class="post-metadata">

**Author:** ![lc85301](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lc85301](https://openfhe.discourse.group/u/lc85301)\
**Post date:** [June 29, 2025, 6:37am UTC](https://openfhe.discourse.group/t/problem-during-cryptocontext-generation-for-bgv/2059/3 "2025-06-29T06:37:06Z")

</div>

Just an update that I found that this issue is being fixed in the commit 5ebe2b26  
With the test case below as src/pke/examples/issue997.cpp

```auto

#include "openfhe.h"
#include <iostream>

using namespace std;
using namespace lbcrypto;

int main() {
  CCParams< CryptoContextBGVRNS > parameters;

  parameters.SetPlaintextModulus(786433);
  parameters.SetMultiplicativeDepth(6);

  auto cc = GenCryptoContext(parameters);

  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);
  cc->Enable(ADVANCEDSHE);

  cout << cc-> GetRingDimension() << endl;
  return 0;
}

```

It print 32768 after the commit.

---

<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:** [July 1, 2025, 12:23am UTC](https://openfhe.discourse.group/t/problem-during-cryptocontext-generation-for-bgv/2059/4 "2025-07-01T00:23:58Z")

</div>

Thank you for reporting it. We will mark this issue as closed.
