About the BINFHE KeyGen and Decrypt

Hi OpenFHE team!

I want to know if this operation is incorrect
and if there should be a warning if it is wrong.
In my code, the first parameter BinFHE::BTKeyGen uses the secret key generated by the second parameter, but there is no warning. Then, I used the secret key from the first parameter for computation and decryption, but the result was incorrect.
I want to know if you think this is a bug?

Here is the MWE:

 #include "binfhecontext.h"

 using namespace lbcrypto;
 
 int main() {
 
     auto cc = BinFHEContext();
 
     cc.GenerateBinFHEContext(STD128_LMKCDEY, LMKCDEY);

     auto cc1 = BinFHEContext();

     cc1.GenerateBinFHEContext(STD128);

     cc.GenerateBinFHEContext(STD128);
     
     cc1 = cc;

     auto sk = cc.KeyGen();

     auto sk1 = cc1.KeyGen();
 
     cc.BTKeyGen(sk1);

     auto ct1 = cc.Encrypt(sk, 1);
     auto ct2 = cc.Encrypt(sk, 1);

     auto ctAND1 = cc.EvalBinGate(AND, ct1, ct2);
 
     auto ct2Not = cc.EvalNOT(ct2);
 
     auto ctAND2 = cc.EvalBinGate(AND, ct2Not, ct1);
 
     auto ctResult = cc.EvalBinGate(OR, ctAND1, ctAND2);
 
     LWEPlaintext result;
 
     cc.Decrypt(sk, ctResult, &result);
 
     std::cout << "Result of encrypted computation of (1 AND 1) OR (1 AND (NOT 1)) = " << result << std::endl;
 
     return 0;
 }

And the result will be
Result of encrypted computation of (1 AND 1) OR (1 AND (NOT 1)) = 2

Could you clarify what you are trying to do? Are you trying to cause some unexpected behavior to see how OpenFHE handles it? In your code, two different secret keys are generated (one for cc, another for cc1). Then you are using one of them for encryption, and another for bootstrapping key generation. Of course, this will produce an incorrect result (by design). So what you are seeing make sense to me.

By design, bootstrapping is automatically performed after every operation in the FHEW and TFHE schemes. I want to know whether OpenFHE can execute operations without automatically bootstrapping each time and then generate the bootstrapping key in such a scenario. I just noticed that in the BFV and BGV schemes, encryption can be done using either the secret key or the public key, so I want to see if BinFHE has similar behavior. If such behavior is not allowed, then my question might be incorrect. May I just want to see how OpenFHE handles it.

For FHEW/TFHE, OpenFHE supports both secret-key and public-key encryption. An example of public key encryption is provided in openfhe-development/src/binfhe/examples/pke/boolean-pke.cpp at v1.2.4 · openfheorg/openfhe-development · GitHub (the comments in this example provide further details on how to avoid automated modulus & key switching, i.e., how to keep the large dimension).