-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BGV: Count Add/Keyswitch in one level for OpenFHE #1254
base: main
Are you sure you want to change the base?
BGV: Count Add/Keyswitch in one level for OpenFHE #1254
Conversation
6a581df
to
57e508b
Compare
Still taking a look at this, but I noticed in your |
for (auto i = 0; i != body->getNumArguments(); ++i) { | ||
auto blockArg = body->getArgument(i); | ||
// one Vfresh | ||
propagate(blockArg, CountState(1, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to my other comment, naively I would expect zero adds here, not 1, and below (line 53) it appears you're adding the countState once per operand, rather than per op.
This indeed is quite a less understood thing until recently. KPZ21 does not illustrate the difference but Application Aware, Introduction, Attacks by Guo et al. points out the difference: Let's say we have the following two circuit %0 = add %arg0, %arg1
%1 = add %0, %arg2
%2 = add %1, %arg3 And %0 = add %arg0, %arg0
%1 = add %0, %0
%2 = add %1, %1 Suppose for each Note that in KPZ21 section 4, we have the formula
This answers why we count on operands (counting |
I get that repeated addition blows up the noise faster. But neither KPZ21 nor ABMP24 seems to give a precise definition of My main concerns are:
This link still only says "max number of additions" and browsing through their code I don't see anywhere that is more specific... [Edit]: We should be able to clear this up by asking Yuriy and the OpenFHE devs on their discourse. |
Then it should be better called
Typically, noise analysis starts with numerial input, e.g. initial noise level being The trick for KPZ21 is that instead of detailed numerical analysis, they view each level as composition of add and keyswitch, thus they only need to count the equivalent addition number (not the same as add operation number) and equivalent key switch number.
I'll open a thread on openfhe discourse. [Edit]: Opened in https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835 |
Based on https://openfhe.discourse.group/t/question-on-definition-of-evaladdcount-and-keyswitchcount/1835/3 let's go ahead with what you have here and cite that thread for followup. I still suggest that we don't need the attributes and can compute the desired values on the fly, using op interfaces to support the same code applying to multiple dialects. |
Part of #1168.
This is a baseline of parameter selection for BGV. While concrete param (like moduli) is still selected by the OpenFHE library, the information of the circuit needed by the OpenFHE is now provided by the compiler.
Note that providing
EvalAddCount/KeySwitchCount
is crucial under the Application-Aware security model, where the compiler/library should reject circuit whose parameter can not be generated, or generate larger parameters. CiteWhen further optimization on parameter selection is landed, this can be kept as a comparable baseline for evaluation purpose. For end-user, they could then select different param generation mechanism based on their needs.
Example
For the
dot_product_8.mlir
, we get the following counting result.A very counter-intuitive result is that instead of
KeySwitchCount
being 4 (1 mul-relin + 3 rotate), it is 15 as it has been accumulated via additions. Detailed definition of KeySwitchCount could be found in KPZ21, section 4. Though I want to ask for review of relevent people whether I understand them correctly.As a result, the generated param becomes
where the moduli chain has
[47, 53, 53, 16]
bits for each level and 169 bits in total.When they are not specified, the generated param is
With moduli chain having
[47, 52, 52, 16]
bits and 167 bits in total.