Decrypting and Encrypting Results in an Accurate Rotation Computation

EDIT: This post has been updated after more debugging. See the end for more details.

Hi,

I have been developing a machine learning model with OpenFHE’s CKKSRNS implementation, but there’s a strange bug I am encountering in my code: There is one operation (a matrix multiplication I implemented) where the decrypted output doesn’t match the expected output (even though the decrypted inputs are correct). The numbers (which are all between -2 and 2) are off by significant enough margin that something is clearly wrong. Strangely, if I decrypt and then encrypt those exact same values which include errors from previous operations, the output matches with the expected output. I understand that as operations accumulate, the errors should slowly increase, and that’s what I have observed with other linear and non linear operations, but not the order of magnitude of error increase in one step that I am observing. I’ve isolated it to only change on whether to decrypt and decode the plaintext, followed by encode and encrypt the same data, and it somehow works when I choose to do so.

I’ve tried everything I know of to fix this bug - increasing parameters such as the multiplicative depth, Scaling Modulus Size, Bootstrapping, Ring Dimension, even native integer size, but all give me the same significant, consistent increase in error that I don’t see elsewhere. Does anyone have any ideas where I might be going wrong? I think it may be my code somewhere that is wrong - and I’m blind to it, but I’m just wondering if someone knows something I don’t about this.

EDIT after more debugging: The bug has nothing to do with OpenFHE or CKKS, but my code. Thanks again for the help.

Could you please write a minimum working example? It is difficult to concretely identify the problem otherwise. Does your output differ only after rotations or after rotations and additions (and masking)? What kind of rotations are you using (standard or fast)? Do you see the errors accumulating more for large matrices or even for small ones?

I apologize for your time, I may have finally come up with the reason it’s not working and it probably has to do with my code, not OpenFHE nor CKKS. I will delete this post once I verify the true source of the error.