# Implementation of LeveledSHECKKSRNS::AdjustLevelsAndDepthInPlace

**URL:** <https://openfhe.discourse.group/t/implementation-of-leveledsheckksrns-adjustlevelsanddepthinplace/2168>\
**Category:** Library Questions\
**Tags:** questions\
**Created:** [September 12, 2025, 9:57am UTC](https://openfhe.discourse.group/t/implementation-of-leveledsheckksrns-adjustlevelsanddepthinplace/2168 "2025-09-12T09:57:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srovira](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@srovira](https://openfhe.discourse.group/u/srovira)\
**Post date:** [September 12, 2025, 9:57am UTC](https://openfhe.discourse.group/t/implementation-of-leveledsheckksrns-adjustlevelsanddepthinplace/2168/1 "2025-09-12T09:57:23Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [September 15, 2025, 5:52pm UTC](https://openfhe.discourse.group/t/implementation-of-leveledsheckksrns-adjustlevelsanddepthinplace/2168/2 "2025-09-15T17:52:26Z")

</div>

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)](https://eprint.iacr.org/2020/1118). 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).
