Unexpected Behaviors with auto scaling techniques in BFV Scheme

Hello OpenFHE Team,

I apologize for posting frequently, but I’ve encountered another issue that I believe is worth reporting.

Below is a minimal snippet of the code that reproduces the issue:

#include "openfhe.h"

using namespace lbcrypto;
using namespace std;

int main(void)
{
  CCParams<CryptoContextBFVRNS> parameters;
  parameters.SetPlaintextModulus(65537);
  parameters.SetScalingTechnique(FIXEDAUTO); // or, FLEXIBLEAUTO, FLEXIBLEAUTOEXT

  CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);
  KeyPair<DCRTPoly> keyPair;
  keyPair = cc->KeyGen();

  Plaintext tmp;
  Ciphertext<DCRTPoly> x, y;

  tmp = cc->MakePackedPlaintext({1});
  x = cc->Encrypt(keyPair.publicKey, tmp);
  y = cc->Encrypt(keyPair.publicKey, tmp);
  x = cc->EvalAdd(x, y);
  return 0;
}

When executed on the latest version (v1.1.4), this code throws an exception with a quite ambiguous message:

terminate called after throwing an instance of 'lbcrypto::OpenFHEException'
  what():  OpenFHE-v1.1.4/src/pke/include/schemebase/base-leveledshe.h:l.764:AdjustLevelsAndDepthInPlace(): Mutable Operations are not supported for this scheme

Upon inspecting the OpenFHE codes a bit, it seems to me that the BFV scheme is supposed to use either the FIXEDMANUAL or NORESCALE technique. Is this understanding correct? If so, I would like to suggest, for clarity and to prevent future errors, maybe prohibiting the use of automatic scaling techniques in the BFV scheme could be considered.

Thank you!

Thank you for pointing this out. For BFV, only the NORESCALE scaling method should be used. BFV supports different multiplication techniques, specified in the OpenFHE design document https://eprint.iacr.org/2022/915.pdf page 6. Currently, cryptocontext parameters do not check which scheme they are called for. I opened an issue Check that the parameters input to the cryptocontext are scheme-specific · Issue #713 · openfheorg/openfhe-development · GitHub.

1 Like