openfheorg / openfhe-development

This is the development repository for the OpenFHE library. The current (stable) version is v1.2.3 (released on October 30, 2024).
BSD 2-Clause "Simplified" License
761 stars 190 forks source link

Improve precision in CKKS Compress for FLEXIBLEAUTO(EXT) #616

Closed yspolyakov closed 10 months ago

yspolyakov commented 11 months ago

Currently the generic implementation in the base RNS scheme is used. We need to add special logic to update the scaling factor. This leads to precision loss of 3-4 bits.

For reference, see the implementation of CKKS Compress in PALISADE: https://gitlab.com/palisade/palisade-release/-/blob/master/src/pke/lib/scheme/ckks/ckks-impl.cpp?ref_type=heads#L1815

yspolyakov commented 10 months ago

When Compress is called for FLEXIBLEAUTO and FLEXIBLEAUTOEXT, it reduces the noise degree to 1 and then simply drops remaining RNS limbs (to the desired level). If all we do after this is decryption, this does not increase the approximation error.

If we use it before any flavor of bootstrapping, we need to multiply the ciphertext by the appropriate adjustment factor that will set the scaling factor for the destination level. See https://github.com/openfheorg/openfhe-development/blob/v1.1.2/src/pke/lib/scheme/ckksrns/ckksrns-multiparty.cpp#L143 and the adjustment logic right after it for an example.

yspolyakov commented 10 months ago

No action is needed.