# CKKS Bootstrapping level management

**URL:** <https://openfhe.discourse.group/t/ckks-bootstrapping-level-management/1877>\
**Category:** Library Questions\
**Created:** [February 17, 2025, 1:58pm UTC](https://openfhe.discourse.group/t/ckks-bootstrapping-level-management/1877 "2025-02-17T13:58:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pan](https://avatars.discourse-cdn.com/v4/letter/p/b5e925/32.png) [@Pan](https://openfhe.discourse.group/u/Pan)\
**Post date:** [February 17, 2025, 1:58pm UTC](https://openfhe.discourse.group/t/ckks-bootstrapping-level-management/1877/1 "2025-02-17T13:58:43Z")

</div>

Hi!  
I want to know that in advanced-ckks-bootstrapping.cpp,we set the ciphertext to level depth - 1 which will only remain 1 level for bootstrapping. How can we finish a bootstrapping in 1 level?  
usint depth = levelsAvailableAfterBootstrap +  
FHECKKSRNS::GetBootstrapDepth(levelBudget, secretKeyDist);  
parameters.SetMultiplicativeDepth(depth);  
Plaintext ptxt = cryptoContext-\>MakeCKKSPackedPlaintext(x, 1, depth - 1, nullptr, numSlots);  
ptxt-\>SetLength(numSlots);  
std::cout \<\< "Input: " \<\< ptxt \<\< std::endl;

```
// Encrypt the encoded vectors
Ciphertext<DCRTPoly> ciph = cryptoContext->Encrypt(keyPair.publicKey, ptxt);

std::cout << "Initial number of levels remaining: " << depth - ciph->GetLevel() << std::endl;

// Step 5: Perform the bootstrapping operation. The goal is to increase the number of levels remaining
// for HE computation.
auto ciphertextAfter = cryptoContext->EvalBootstrap(ciph);

std::cout << "Number of levels remaining after bootstrapping: " << depth - ciphertextAfter->GetLevel() << std::endl
          << std::endl;

// Step 7: Decryption and output
Plaintext result;
cryptoContext->Decrypt(keyPair.secretKey, ciphertextAfter, &result);
result->SetLength(numSlots);
std::cout << "Output after bootstrapping \n\t" << result << std::endl;

```

}

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [February 17, 2025, 2:51pm UTC](https://openfhe.discourse.group/t/ckks-bootstrapping-level-management/1877/2 "2025-02-17T14:51:17Z")

</div>

Inside CKKS bootstrapping, the ciphertext’s level is increased to the max, enabling bootstrapping to proceed without issues. The code you’re referring to simulates a ciphertext that has reached its computational limit - i.e., a state where no further homomorphic operations can be performed. This is the typical scenario where bootstrapping is invoked.

---

<div class="post-metadata">

**Author:** ![Pan](https://avatars.discourse-cdn.com/v4/letter/p/b5e925/32.png) [@Pan](https://openfhe.discourse.group/u/Pan)\
**Post date:** [February 18, 2025, 5:38am UTC](https://openfhe.discourse.group/t/ckks-bootstrapping-level-management/1877/3 "2025-02-18T05:38:28Z")

</div>

Thanks!  
What’s more,I want to know if there’s anyway for us to increase levels remaining after bootstrapping. Because when I use ring dimension like 65536, levels don’t change sometimes. Even for dimension like 8192 or 4096,there’s still only 10 levels remaining which are unacceptable. I know we can use the iteration bootstrapping but I’m concerning that will caused efficiency declined.

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [February 18, 2025, 3:48pm UTC](https://openfhe.discourse.group/t/ckks-bootstrapping-level-management/1877/4 "2025-02-18T15:48:54Z")

</div>

Your question is not clear. What do you mean by “levels don’t change sometimes”?  
You can always set the multiplicative depth as high as you want, but this might pump up the ring dimension which causes the scheme to run very slowly.

Using reasonable parameters (ring dimension = 64k) and bootstrap more is usually better than pumping the ring dimension to 2^17 and bootstrap less. This rule of thumb is generally true but it depends on the use case of interest.

I do not understand the part below. Do you claim you can do bootstrapping and get 10 levels after that with ring dimensions 2^13 or 2^14?! The only way I see this happens is if you disable the security check, which is not recommended.

> [@Pan](#):
>
> Even for dimension like 8192 or 4096,there’s still only 10 levels remaining which are unacceptable.

Furthermore, please provide your code so we can help you better.
