# Large switching key size for TFHE after serialisation

**URL:** <https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925>\
**Category:** Library Questions\
**Created:** [November 19, 2023, 5:38pm UTC](https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925 "2023-11-19T17:38:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandasamanvaya](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pandasamanvaya](https://openfhe.discourse.group/u/pandasamanvaya)\
**Post date:** [November 19, 2023, 5:38pm UTC](https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925/1 "2023-11-19T17:38:02Z")

</div>

Hi,  
I am new to OpenFHE library. After going through the binfhe examples, I tried generating keys for a TFHE BinFHEContext() using the following code :-

```auto
auto cc = BinFHEContext();
cc.GenerateBinFHEContext(STD128, true, 12, 0, GINX);
auto sk = cc.KeyGen();
cc.BTKeyGen(sk);

```

After serialising the keys generated by the above code in binary format, I noticed that the size of switching key is around 4.84GB. As far as I know, for TFHE scheme, the size of switching key should be around 100-200 MB and most probably, I have generated keys for FHEW scheme. Is my suspicion correct? If yes, then how do I generate a TFHE context using OpenFHE library? If no, then what am I doing wrong?

---

<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:** [November 20, 2023, 4:25pm UTC](https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925/2 "2023-11-20T16:25:27Z")

</div>

Hi, you are using the parameters for larger-precision evaluation, which are a bit larger than for Boolean arithmetic. If you simply use one argument (STD128), or two, with the method set to GINX or LMKCDEY, you will see smaller parameters.

Also, the bootstrapping key includes both switching key and refreshing key.

A more advanced (custom) constructor for BINFHE context can also be used to generate even smaller parameters for the desired functionality. There is a special parameter estimation repository with scripts for these.

I am traveling this week and first half of the next week. If you have a specific configuration in mind, I can post some parameters space-efficient parameters when I am back.

---

<div class="post-metadata">

**Author:** ![pandasamanvaya](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pandasamanvaya](https://openfhe.discourse.group/u/pandasamanvaya)\
**Post date:** [November 21, 2023, 4:28pm UTC](https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925/3 "2023-11-21T16:28:40Z")

</div>

Thanks @ypolyakov for the explanation. I tried changing parameters and indeed I see smaller switching keys(~398 MB). However, it provides less precision. I will try to play around with parameters for now. If I don’t find any suitable set of parameters, I will ask in the forum. I have one last question - How do i know whether I am using FHEW or TFHE scheme? In case of levelled schemes(BGV, BFV and CKKS), we have different crypto contexts which makes it very clear. However, while using binary fhe schemes, its not clear. Is it differentiated based on which bootstrapping technique we choose?

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [November 28, 2023, 3:02pm UTC](https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925/4 "2023-11-28T15:02:10Z")

</div>

That is correct. What is different between the schemes is the bootstrapping method, which you can select by specifying GINX, AP or LMKCDEY.

---

<div class="post-metadata">

**Author:** ![pandasamanvaya](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pandasamanvaya](https://openfhe.discourse.group/u/pandasamanvaya)\
**Post date:** [November 29, 2023, 8:36am UTC](https://openfhe.discourse.group/t/large-switching-key-size-for-tfhe-after-serialisation/925/5 "2023-11-29T08:36:40Z")

</div>

Thanks @andreea.alexandru for confirming that.
