Determining the size of "compressed" ciphertext

Hi

I continue to explore the openfhe codebase and am looking at using Compress and/or ModReduce to reduce Ciphertext size (for network transmission or on-disk storage). However my simple test code (in Python) is not showing a reduction in size. Am I doing something wrong?

parameters = ofhe.CCParamsBFVRNS()
parameters.SetPlaintextModulus(65537)
parameters.SetMultiplicativeDepth(2)

cc = ofhe.GenCryptoContext(parameters)
cc.Enable(ofhe.PKESchemeFeature.PKE)
cc.Enable(ofhe.PKESchemeFeature.KEYSWITCH)
cc.Enable(ofhe.PKESchemeFeature.LEVELEDSHE)

keypair = cryptoContext.KeyGen()

input = tuple(random.randint(0, 65536) for _ in range(16))
plaintext = cc.MakePackedPlaintext(input)
ciphertext = cc.Encrypt(kp.publicKey, plaintext)
compciphertext = cc.ModReduce(ciphertext)

I notice the serialized size of both ciphertext and compciphertext are 385KiB?

Any feedback appreciated.

Can you try the method compress as follows:
compciphertext = cc->Compress(ciphertext, 1); // where the second argument specifies the number of limbs to keep in the result ciphertext

@Caesar the Compress function does not seem to be available for this object.

$ ./batesste-openfhe.py 
Traceback (most recent call last):
  File "/home/batesste/Projects/batesste-openfhe/./batesste-openfhe.py", line 107, in <module>
    main(args)
  File "/home/batesste/Projects/batesste-openfhe/./batesste-openfhe.py", line 67, in main
    compciphertext = cc.Compress(ciphertext, 1)
                     ^^^^^^^^^^^
AttributeError: 'openfhe.CryptoContext' object has no attribute 'Compress'

Which version of OpenFHE are you using?
I just ran an example against OpenFHE v1.2.3 and it worked successfully.

This feature was added in OpenFHE in May 2024 (Release 1.1.0) as a request to this thread: see the issue.

@Caesar how odd. I do have the latest openFHE installed. Did you run your example in openfhe-python? Is it possible the python bindings have not been updated to include compress? I would assume that should happen automatically using the pybind11 tooling.

I see. My example was in C++. It is possible that this method is not implemented in openfhe-python. We will explore this further.

@Caesar I did some digging and it definintely looks like this method is not implemented in the python. Can you confirm and then we can open an issue for this in openfhe-python.

Confirmed. It is not implemented in openfhe-python.
I created an issue to address this.

@sbates-nvme Thank you for reporting this issue.

1 Like

I hacked up a fix for the python bindings. I now get something that looks a bit more sane but not sure if it is what is expected.

$ ./batesste-openfhe.py 
ciphertext     = 385.0 KiB
compciphertext = 129.0 KiB