Problem during CryptoContext generation for BGV

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.

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

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


#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.

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