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

Adding ciphertext and plaintext from different contexts causes unintended errors #584

Open
Maokami opened this issue Nov 9, 2023 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Maokami
Copy link

Maokami commented Nov 9, 2023

Hi, OpenFHE Team!

I found that when ciphertext and plaintext created in different contexts are added, unintended errors can occur.

#include "openfhe.h"

using namespace lbcrypto;

int main() {

    //c1 in cc1
    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetMultiplicativeDepth(2);

    CryptoContext<DCRTPoly> cc1 = GenCryptoContext(parameters);

    cc1->Enable(PKE);
    cc1->Enable(LEVELEDSHE);

    auto keys = cc1->KeyGen();

    std::vector<double> x1 = {1};
    Plaintext plaintext = cc1->MakeCKKSPackedPlaintext(x1);
    auto c1 = cc1->Encrypt(keys.publicKey, plaintext);

    //p1 in cc2
    CCParams<CryptoContextCKKSRNS> parameters2;
    parameters2.SetMultiplicativeDepth(3);

    CryptoContext<DCRTPoly> cc2 = GenCryptoContext(parameters2);
    std::vector<double> x2 = {1};
    Plaintext p1 = cc2->MakeCKKSPackedPlaintext(x2);

    // Add(c1,p1) in cc1
    c1 = cc1->EvalAdd(c1,p1);

    return 0;
}

Result:

libc++abi: terminating due to uncaught exception of type lbcrypto::math_error: /project/openfhe-development/src/core/lib/math/hal/intnat/mubintvecnat.cpp:245 ModAddEq called on NativeVectorT's with different parameters.
libc++abi: terminating due to uncaught exception of type lbcrypto::math_error: /project/openfhe-development/src/core/lib/math/hal/intnat/mubintvecnat.cpp:245 ModAddEq called on NativeVectorT's with different parameters.

I believe there are several possible ways to address the issue:

  1. Throw an exception when plaintext and ciphertext created in different contexts are added.
  2. Check if the coefficient modulus of each context matches when adding plaintext and ciphertext from different contexts, and thrwo an exception if they do not.
@yspolyakov yspolyakov added the bug Something isn't working label Nov 16, 2023
@yspolyakov yspolyakov added this to the Release 1.1.2 milestone Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants