Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exception 'std::out_of_range' occurs when using EvalRotate in BFV without corresponding EvalKey #675

Closed
Maokami opened this issue Feb 23, 2024 · 2 comments

Comments

@Maokami
Copy link

Maokami commented Feb 23, 2024

Hello OpenFHE team!

The following code throws an exception with the message terminate called after throwing an instance of 'std::out_of_range' what(): map::at.

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

using namespace lbcrypto;
using namespace std;

int main(void) {
  CCParams<CryptoContextBFVRNS> parameters;
  parameters.SetRingDim(32768);
  size_t plaintext_modulus = 65537;
  parameters.SetPlaintextModulus(plaintext_modulus);
  parameters.SetMultiplicativeDepth(2);
  CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);
  KeyPair<DCRTPoly> keyPair;
  keyPair = cc->KeyGen();
  cc->EvalMultKeyGen(keyPair.secretKey);
  size_t slots(cc->GetRingDimension());
  vector<int64_t> tmp_vec_(slots);
  Plaintext tmp;
  vector<int> rots = {1};
  cc->EvalRotateKeyGen(keyPair.secretKey, rots);
  Ciphertext<DCRTPoly> tmp_;

  Ciphertext<DCRTPoly> x;
  int c;
  vector<int64_t> tmp_vec_1 = { 1, 2, 3 };
  tmp = cc->MakePackedPlaintext(tmp_vec_1);
  x = cc->Encrypt(keyPair.publicKey, tmp);

  // use EvalRotate without corresponding EvalKey
  x = cc->EvalRotate(x, 0);
  return 0;
}

When I changed the scheme to BGV or CKKS, the code produced a more detailed error message:

terminate called after throwing an instance of 'lbcrypto::openfhe_error'
 what():  OpenFHE/src/pke/lib/schemebase/base-leveledshe.cpp:422 EvalKey for index [1] is not found. [called from: OpenFHE/src/pke/lib/schemebase/base-leveledshe.cpp:EvalAtIndex():l.540]
@Maokami
Copy link
Author

Maokami commented Feb 28, 2024

related to #362

@yspolyakov
Copy link
Contributor

Please ask this question in the Discourse forum: https://openfhe.discourse.group/ BTW, EvalRotate is executed for index 0. What is meant by that? Should it not be 1? But please continue the discussion in the forum. I am closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants