Hello there, I am writing a program in which I perform many rotations on a ciphertext, and I noticed the function EvalFastRotation. I was wondering if you can provide an example of how it works, and which are the benefits in terms of time
Thank you
Hello there, I am writing a program in which I perform many rotations on a ciphertext, and I noticed the function EvalFastRotation. I was wondering if you can provide an example of how it works, and which are the benefits in terms of time
Thank you
I tried a couple of experiments, but the program has some kind of error. I leave the code here.
The output is the following:
CryptoContext and Keys generation started...
Generating crypto context...
Evaluating MultKeyGen...
Encoding and encrypting a vector...
Iteration 0:
Decryptable
Iteration 1:
Decryptable
Iteration 2:
Decryptable
Iteration 3:
Decryptable
Iteration 4:
Decryptable
Iteration 5:
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Hi @marc-alonso
EvalFastRotation
is function that can speed up rotations when multiple rotations of the same ciphertext need to be performed. The first idea is that digit decomposition for the ciphertext can be precomputed and then reused for multiple rotations. A good example of this is openfhe-development/advanced-real-numbers.cpp at v1.0.3 · openfheorg/openfhe-development · GitHub
For hybrid key switching only, there is another optimization for fast rotations. It is slightly more involved. The example is provided at openfhe-development/UnitTestBootstrap.cpp at v1.0.3 · openfheorg/openfhe-development · GitHub In addition to the digit decomposition, one can perform actual fast rotations using the extended modulus (used internally in hybrid key switching), and then call expensive KeySwitchDown
only once. This works well for the scenario when the results of fast rotations are added together (as in linear transforms). Note that in this case, you should call EvalFastRotationExt
rather than EvalFastRotation
to take advantage of the second optimization.
Hello @ypolyakov , thank you very much for the references. Any suggestion for my previous example? I think I am using the fast rotation correctly …
In your example, EvalFastRotation
is not used properly. The idea is that you apply it when multiple rotations of the same ciphertext need to be computed. In your example, the ciphertext keeps changing. So if you run your example, you will see the answer is garbage from iteration 1 on.
On top of this, you try to generate two rotations keys for the same index: 128*2*2 and 128*4.
Moreover, the ciphertext uses only 4 slots, which also does not make sense for the desired rotations.
Another issue is that no key for iteration 5 is generated with EvalRotateKeyGen (missing key).
So there are four different problems with the provided example.