The difference and connection between modulus switch and modUp/Down

Hi,

I have several questions about the modulus switch and modup/down routines.

I notice that

  1. in thesis A Full RNS Variant of Approximate Homomorphic Encryptioniacr, modUp/Down requires complicated basis conversion operation.
  2. there is a step called ModUp in ckks-bootstrapping,
  3. in key switch key generation step we need to expand the original decryption key s(x) (not the s^2(x) in mult case) from mod Q to mod PQ.

The modUp in bootstrapping, and the key expansion mentioned above all call modulus switch function in OpenFHE, which in my opinion is completely different from the modUp/Down that requires basis conversion given in the above thesis.

To be specific,

  1. in ckksrns-fhe.cpp,below the comment raising the modulus, I found that the main code doing the task raising the moudlus is an operation “=” with overload function. And the core computation within the overload function is SwitchModulus Func.
  2. in keyswitch-hybrid.cpp, in the function
    EvalKey<DCRTPoly> KeySwitchHYBRID::KeySwitchGen(const PrivateKey<DCRTPoly> oldKey,const PrivateKey<DCRTPoly> newKey) const {},
    below the comment // The part with basis P there is auto sNew0 = sNew.GetElementAtIndex(0); sNew0.SwitchModulus(pj, rootj, 0, 0);. I can’t understand why the first RNS poly of sNew (i.e. sNew[0]), is always the input operation number when dealing with //The part with basis P in KSGen.

My question is,

  1. When should I use ModUp which includes basis conversion, and when should I use modulus switch? Are they equivalent to some extent? And how about ModDown?
  2. What’s the difference and connection between modulus switch and ModUp/Down?
  3. How to use the modulus switch correctly?
    For example, why the first RNS poly of sNew is always the input operation number for the key expansion when dealing with The part with basis P in KSGen?(Detailed information is given in the second example above.)
  4. I first ModUp a normal ct, and then ModDown the ct back, finally do the decryption and failed. I would like to know why it failed. (Both ModUp and Down is implemented as the A Full RNS Variant of Approximate Homomorphic Encryptioniacr told, and they perform correctly when called in the key switch procedure.)

Thanks for your help!

1 Like

P.S. I would like to know the difference between
ApproxModDown(given by A Full RNS Variant of Approximate Homomorphic Encryptioniacr),
ModReduceInternalInPlace,
LevelReduceInternalInPlace(two function offered by openFHE),
and Rescale(given by the above thesis).

Thanks!

1 Like

ApproxModUp and ApproxModDown are functions that operate on a DCRTPoly object. ModReduceInPlace, LevelReduceInPlace, and Rescale are functions that operate on a Ciphertext object, and you can call the latter set of functions from a CryptoContext. We intend for the users of OpenFHE to use functions callable from the CryptoContext.

Please give us more details about your use case for us to help us with the rest of your questions. What are you using SwitchModulus, ModUp, and ModDown for? Is it possible for you to use functions callable from a CryptoContext instead?