# Less levels after first bootstrapping

**URL:** <https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407>\
**Category:** FHE Questions\
**Created:** [March 13, 2023, 5:12pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407 "2023-03-13T17:12:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [March 13, 2023, 5:12pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/1 "2023-03-13T17:12:29Z")

</div>

Hello there,

I am trying to understand how to optimize the use of bootstrapping and its parameters. After playing with different values, I noticed that after the first bootstrap, the ciphertext levels will always be limited. For instance, I usually find this situation:

- Fresh ciphertext: 20 available multiplications
- 1st bootstrap: 8 available multiplications
- 2nd bootstrap: 8 available multiplications

and so on.  
Can you confirm me that this is the “normal” behavior? Is there any way to “close” this gap between the starting 20 and the next 8?

Thank you so much!

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [March 13, 2023, 6:12pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/2 "2023-03-13T18:12:21Z")

</div>

A few things:

1. Can you share your script? Just so we can take a look at the parameters?

2. You’re supposed to bootstrap only in scenarios where it would **increase** your number of available multiplications 🙂

Just so you’re in the loop, we (OpenFHE team) have talked about this before and I myself have run into this myself.

> Can you confirm me that this is the “normal” behavior?

Yes, it is normal, even if it is unexpected for the end-user.

> Is there any way to “close” this gap between the starting 20 and the next 8?

Depends on your parameters, hence my asking for your script 🙂

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [March 14, 2023, 9:29am UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/3 "2023-03-14T09:29:30Z")

</div>

Well I noticed this thing in the simple ckks bootstrapping example!

I leave it here for convenience

```auto
std::vector<uint32_t> levelBudget = {4, 4};
uint32_t approxBootstrapDepth = 8;

uint32_t levelsUsedBeforeBootstrap = 10;
usint depth =
            levelsUsedBeforeBootstrap + FHECKKSRNS::GetBootstrapDepth(approxBootstrapDepth, levelBudget, UNIFORM_TERNARY);`

```

I was wondering what `approxBootstrapDepth` is, too. I mean, it looks like an arbitrary value, but what is the way-to-go when setting it?

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [March 15, 2023, 5:36pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/4 "2023-03-15T17:36:42Z")

</div>

Here’s something that will help [advanced-ckks-bootstrapping.cpp](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/advanced-ckks-bootstrapping.cpp#L116).

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [March 20, 2023, 2:51pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/5 "2023-03-20T14:51:53Z")

</div>

Has your Q been answered?

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [March 20, 2023, 3:06pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/6 "2023-03-20T15:06:09Z")

</div>

Oh, sorry!

I’d say partially; I got that that value is the approximate number of levels bootstrapping will consume. But how would I know that? Is that a function of some other parameters?

Thank you again, @iquah !

---

<div class="post-metadata">

**Author:** ![saroja](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@saroja](https://openfhe.discourse.group/u/saroja)\
**Post date:** [March 27, 2023, 2:13pm UTC](https://openfhe.discourse.group/t/less-levels-after-first-bootstrapping/407/7 "2023-03-27T14:13:03Z")

</div>

The approximate bootstrap depth is set experimentally by observing how many levels bootstrapping consumes. The total bootstrap depth is given by this function:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/96058a8f9ee46eaf870672f18eeaeae1d34ae3b8.png)  
where R, the number of double-angle iterations, is set to 6.

For example, if you use a level budget of {4, 4} with the UNIFORM\_TERNARY secret key distribution, and you experimentally observe that bootstrapping consumes 21 levels, then you would set approxBootstrapDepth to 21 - 4 - 4 - (6 - 1) = 8.
