# Question on definition of EvalAddCount and KeySwitchCount

**URL:** <https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835>\
**Category:** Library Questions\
**Created:** [January 16, 2025, 2:28am UTC](https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835 "2025-01-16T02:28:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenithal](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/zenithal/32/311_2.png) [@zenithal](https://openfhe.discourse.group/u/zenithal)\
**Post date:** [January 16, 2025, 2:28am UTC](https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835/1 "2025-01-16T02:28:30Z")

</div>

For longer context, check [BGV: Count Add/Keyswitch in one level for OpenFHE by ZenithalHourlyRate · Pull Request #1254 · google/heir · GitHub](https://github.com/google/heir/pull/1254).

We are trying to provide EvalAddCount and KeySwitchCount parameter from compiler, and we encounter the question what is the exact definition of them. Is it the number of add/keyswitch operations (then we would simply count the number of operations), or is it the number of addition/keyswitch op when the circuit is flattened. My own understanding is the second one.

They are initially defined in _“Revisiting Homomorphic Encryption Schemes for Finite Fields, Section 4”_, yet later attacks revealed that correctly setting them is crucial, see _“Application-Aware Approximate Homomorphic Encryption: Configuring FHE for Practical Use, Introduction, Attacks by Guo et al”_, which said that when the circuit is repeated addition of one ciphertext then the EvalAddCount should be set _higher_, yet neither of these papers gives exact way to calculate EvalAddCount.

We ask for clarification and detailed step to calculate these quantities in the documentation of these APIs in OpenFHE.

Cc @j2kun

---

<div class="post-metadata">

**Author:** ![j2kun](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/j2kun/32/202_2.png) [@j2kun](https://openfhe.discourse.group/u/j2kun)\
**Post date:** [January 17, 2025, 6:27pm UTC](https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835/2 "2025-01-17T18:27:04Z")

</div>

+1, I think the main question here is, when our program iteratively adds the same ciphertexts together (`x1 = x+x; x2 = x1+x1; ...`), does that imply we should provide a higher `EvalAddCount` than if the additions are independent? If we _should_ provide a higher count, what is the precise relationship between the circuit and the required value of `EvalAddCount`?

---

<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:** [January 17, 2025, 10:16pm UTC](https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835/3 "2025-01-17T22:16:07Z")

</div>

@zenithal @j2kun We are currently revising the Application-Aware FHE paper to include a formal application specification language that would allow a granular description of any circuit. We will share it here once it is ready.

You are right that in order to support the doubling circuit, the EvalAddCount should be set larger, essentially to capture all additions done on the (single) input x. However, this is error-prone and not sufficiently descriptive, which is why we are planning a change.
