Implementation of LeveledSHECKKSRNS::AdjustLevelsAndDepthInPlace

Hello,

There are a few things I don’t understand in the implementation of the function LeveledSHECKKSRNS::AdjustLevelsAndDepthInPlace.

For example, if c1lvl < c2lvl and c1depth = c2depth = 2, the code first computes EvalMultCoreInPlace which brings the scaling factor of ciphertext1 to degree 3. Then, A ModReduceInternalInPlace increases the level of ciphertext1 by 1 and it decreases its degree and towers by 1. My main question is the following: why can’t we use directly LevelReduceInternalInPlace? This increases the level of ciphertext1 by 1 and decreases the towers by 1, leaving us in exactly the same place as in the previous case. I have written a simple example which computes x**12 and I get the same result if I do this modification.

My other two related questions are the following:

  • When calling EvalMultCoreInPlace, sometimes the value 1 is hardcoded and in others a function of scaling factors is passed. My understanding is that we need this when the scaling technique is FLEXIBLEAUTO, but we could hardcode the value to 1 for FIXEDAUTO. Is this correct?
  • In the scenario that I have described at the beginning, why do we need to call SetScalingFactor after calling ModReduceInternalInPlace? Could you provide an example when the scaling factor of ciphertext1 is different than the scaling factor of ciphertext2 after the calls to EvalMultCoreInPlace and ModReduceInternalInPlace?

TLDR: Can we replace the calls to EvalMultCoreInPlace and ModReduceInternalInPlace by LevelReduceInternalInPlace in the function LeveledSHECKKSRNS::AdjustLevelsAndDepthInPlace?

There are multiple questions asked here. I will try to focus on the first one as it is representative. OpenFHE supports two flavors of rescaling modes: FIXED* (where the scaling factor is approximately 2^{p}) and FLEXIBLE* (where the scaling factor has a higher precision, i.e., that of roughly double-precision floating-point numbers). In the latter case, one needs to scale ciphertexts at different levels to bring them to a common scaling factor. The algorithmic details are presented in Section 4.1 of ePrint 2020/1118 (CT-RSA’22). If these scaling steps are not applied for FLEXIBLE* modes, the precision can degrade to that of the FIXED* modes (at least for the corresponding operation).