Open gogo9th opened 1 month ago
I’m sorry to hear things didn’t go as planned. I’ll take care of implementing these functions and aim to have them ready by tomorrow.
I am so happy to hear that. Thanks very much for your support!
Everything is working perfectly now. I’ve also added a new example of serialization. Please take a look and let me know if something is wrong.
Hi, I made my integration and it works very well. Thanks so much!
There is a very minor note (which I forgot to ask every time). When we do make install
, the header file folder phantom/
gets installed at the root directory of the filesystem, so I always manually move it to /usr/local/include
. Even if I set the CMake option to make it install under /usr/local/include
, it does not seem to work. So making the default install directory of the header files to be /usr/local/include
could make our lives a bit easier.
Could you please try building and installing the library using CMake commands? You can refer to the following documentation for detailed instructions:
https://encryptorion-lab.gitbook.io/phantom-fhe/installation
cmake --build build -j
sudo cmake --install build
In my case, it is always installed to /usr/local
by default.
That's weird, my default install directory is this:
:fhe/phantom-fhe$ sudo cmake --install build
-- Install configuration: ""
-- Installing: /usr/local/lib/libPhantom.so
-- Installing: /cmake/phantom/PhantomConfig.cmake
-- Installing: /cmake/phantom/PhantomConfig-noconfig.cmake
-- Up-to-date: /phantom
-- Up-to-date: /phantom/scalingvariant.cuh
-- Up-to-date: /phantom/fft.h
-- Up-to-date: /phantom/cuda_wrapper.cuh
-- Up-to-date: /phantom/batchencoder.h
-- Up-to-date: /phantom/evaluate.cuh
-- Up-to-date: /phantom/gputype.h
-- Up-to-date: /phantom/galois.cuh
-- Up-to-date: /phantom/ckks.h
-- Up-to-date: /phantom/phantom.h
-- Up-to-date: /phantom/ntt.cuh
-- Up-to-date: /phantom/rns.cuh
-- Up-to-date: /phantom/uintmath.cuh
-- Up-to-date: /phantom/prng.cuh
-- Up-to-date: /phantom/ciphertext.h
-- Up-to-date: /phantom/lock.cuh
-- Up-to-date: /phantom/secretkey.h
-- Up-to-date: /phantom/util.cuh
-- Up-to-date: /phantom/plaintext.h
-- Up-to-date: /phantom/context.cuh
-- Up-to-date: /phantom/rns_bconv.cuh
-- Up-to-date: /phantom/uintmodmath.cuh
-- Up-to-date: /phantom/host
-- Up-to-date: /phantom/host/ntt.h
-- Up-to-date: /phantom/host/globals.h
-- Up-to-date: /phantom/host/modulus.h
-- Up-to-date: /phantom/host/numth.h
-- Up-to-date: /phantom/host/blake2.h
-- Up-to-date: /phantom/host/uintcore.h
-- Up-to-date: /phantom/host/uintarithsmallmod.h
-- Up-to-date: /phantom/host/defines.h
-- Up-to-date: /phantom/host/blake2-impl.h
-- Up-to-date: /phantom/host/hash.h
-- Up-to-date: /phantom/host/encryptionparams.h
-- Up-to-date: /phantom/host/uintarithmod.h
-- Up-to-date: /phantom/host/uintarith.h
-- Up-to-date: /phantom/host/rns.h
-- Up-to-date: /phantom/host/common.h
-- Up-to-date: /phantom/host/hestdparms.h
-- Up-to-date: /phantom/rns_base.cuh
-- Up-to-date: /phantom/polymath.cuh
-- Up-to-date: /phantom/butterfly.cuh
-- Up-to-date: /phantom/common.h
If I set the prefix:
:fhe/phantom-fhe$ sudo cmake --install build --prefix /usr/local
-- Install configuration: ""
-- Up-to-date: /usr/local/lib/libPhantom.so
-- Up-to-date: /cmake/phantom/PhantomConfig.cmake
-- Up-to-date: /cmake/phantom/PhantomConfig-noconfig.cmake
-- Up-to-date: /phantom
-- Up-to-date: /phantom/scalingvariant.cuh
-- Up-to-date: /phantom/fft.h
-- Up-to-date: /phantom/cuda_wrapper.cuh
-- Up-to-date: /phantom/batchencoder.h
-- Up-to-date: /phantom/evaluate.cuh
-- Up-to-date: /phantom/gputype.h
-- Up-to-date: /phantom/galois.cuh
-- Up-to-date: /phantom/ckks.h
-- Up-to-date: /phantom/phantom.h
-- Up-to-date: /phantom/ntt.cuh
-- Up-to-date: /phantom/rns.cuh
-- Up-to-date: /phantom/uintmath.cuh
-- Up-to-date: /phantom/prng.cuh
-- Up-to-date: /phantom/ciphertext.h
-- Up-to-date: /phantom/lock.cuh
-- Up-to-date: /phantom/secretkey.h
-- Up-to-date: /phantom/util.cuh
-- Up-to-date: /phantom/plaintext.h
-- Up-to-date: /phantom/context.cuh
-- Up-to-date: /phantom/rns_bconv.cuh
-- Up-to-date: /phantom/uintmodmath.cuh
-- Up-to-date: /phantom/host
-- Up-to-date: /phantom/host/ntt.h
-- Up-to-date: /phantom/host/globals.h
-- Up-to-date: /phantom/host/modulus.h
-- Up-to-date: /phantom/host/numth.h
-- Up-to-date: /phantom/host/blake2.h
-- Up-to-date: /phantom/host/uintcore.h
-- Up-to-date: /phantom/host/uintarithsmallmod.h
-- Up-to-date: /phantom/host/defines.h
-- Up-to-date: /phantom/host/blake2-impl.h
-- Up-to-date: /phantom/host/hash.h
-- Up-to-date: /phantom/host/encryptionparams.h
-- Up-to-date: /phantom/host/uintarithmod.h
-- Up-to-date: /phantom/host/uintarith.h
-- Up-to-date: /phantom/host/rns.h
-- Up-to-date: /phantom/host/common.h
-- Up-to-date: /phantom/host/hestdparms.h
-- Up-to-date: /phantom/rns_base.cuh
-- Up-to-date: /phantom/polymath.cuh
-- Up-to-date: /phantom/butterfly.cuh
-- Up-to-date: /phantom/common.h
Hi,
We did the demo successfully. Thanks very much again for your kind support.
During our demo, we were faced with a few incompatible operations as follows:
- PhantomCiphertext.encrypt_zero() (i.e., encrypt_zero_symmetric)
- PhantomCiphertext.is_zero()
- PhantomPublicKey.save()
- PhantomPublicKey.load()
- PhantomSecretKey.save()
- PhantomSecretKey.load()
We thought it would be okay to skip the above APIs, but actually realized that these are actually needed (especially the latter 4 for a debugging purpose)... I am really sorry for asking again, but could you please consider finishing up the above implementations and perfect the network support for PhantomFHE? This will be invaluable assets to all FHE developers in the world.
Hi,
I tried to add the functionality of encrypt_zero_asymmetric and secretkey.save() and secretkey.load() by inserting the following 3 functions to secretkey.h:
/* INSERT this function in the PhantomPublicKey class */
inline void encrypt_zero_asymmetric(const PhantomContext &context, PhantomCiphertext &cipher) {
const auto &s = cudaStreamPerThread;
encrypt_zero_asymmetric_internal(context, cipher, context.get_first_index(), s);
}
/* INSERT this function in the PhantomSecretKey class */
void save(const PhantomContext& context, std::ostream &stream) const {
const cudaStream_t &s = cudaStreamPerThread;
if (!gen_flag_)
throw std::invalid_argument("PhantomSecretKey has not been generated");
auto &context_data = context.get_context_data(0);
auto &parms = context_data.parms();
auto &coeff_modulus = parms.coeff_modulus();
auto poly_degree = parms.poly_modulus_degree();
auto coeff_mod_size = coeff_modulus.size();
auto base_rns = context.gpu_rns_tables().modulus();
uint64_t *h_data;
cudaMallocHost(&h_data, poly_degree * coeff_mod_size * sizeof(uint64_t));
cudaMemcpyAsync(h_data, secret_key_array_.get(), poly_degree * coeff_mod_size * sizeof(uint64_t), cudaMemcpyDeviceToHost);
stream.write(reinterpret_cast<char*>(h_data), poly_degree * coeff_mod_size * sizeof(uint64_t));
cudaFreeHost(h_data);
}
/* INSERT this function in the PhantomSecretKey class */
void load(const PhantomContext& context, std::istream &stream) {
const cudaStream_t &s = cudaStreamPerThread;
auto &context_data = context.get_context_data(0);
auto &parms = context_data.parms();
auto &coeff_modulus = parms.coeff_modulus();
auto poly_degree = parms.poly_modulus_degree();
auto coeff_mod_size = coeff_modulus.size();
auto base_rns = context.gpu_rns_tables().modulus();
poly_modulus_degree_ = parms.poly_modulus_degree();
coeff_modulus_size_ = parms.coeff_modulus().size();
uint64_t *h_data;
chain_index_ = 0;
sk_max_power_ = 1;
gen_flag_ = true;
cudaMallocHost(&h_data, poly_degree * coeff_mod_size * sizeof(uint64_t));
stream.read(reinterpret_cast<char*>(h_data), poly_degree * coeff_mod_size * sizeof(uint64_t));
data_rns_ = phantom::util::make_cuda_auto_ptr<uint64_t>(poly_modulus_degree_ * coeff_modulus_size_, s); secret_key_array_ = phantom::util::make_cuda_auto_ptr<uint64_t>(poly_degree * coeff_mod_size, s);
cudaMemcpyAsync(secret_key_array_.get(), h_data, poly_degree * coeff_mod_size * sizeof(uint64_t), cudaMemcpyHostToDevice, s);
cudaFreeHost(h_data);
cudaStreamSynchronize(cudaStreamPerThread);
}
Now, encrypt_zero_asymmetric() works fine, but load() and save() for the secret key do not work correctly, because the it encrypts and decrypts to corrupts values. Do you have any clue where I went wrong by any chance?
Apologies for the delayed response. I’ve been quite busy lately. I’ll take a closer look at your questions after I wrap up some urgent work.
Hi, I hope things are going well with you. We are visiting Salt Lake City next week for CCS and WAHE, and plan to have some business meetings there. I also plan to submit a paper to S&P regarding our new FHE application system based on your library. But the submission deadline is approaching and we really need to finish the implementation and start evaluation of our system. I wonder if you could take a look at the issues I found by any chance when you have some time.. I am sorry for keeping asking, but I strongly believe this fixation would be really the last part regarding PhantomFHE for any practical usability.
I finally have some time to work on the issues you mentioned and will try to fix them today. I understand the urgency with the deadline, and I’ll do my best to resolve everything quickly.
Wishing you all the best with your projects and schedules.
Hi,
I am sorry for making this request again, but I was not successful in implementing the network transfer of these keys yet and the deadline for our demo is approaching (next Monday). I wonder it could be every possible to help finishing up the network support for these keys... Unlike the last ciphertext/plaintext implementation, it is okay to send these keys without the Serializable optimization (if this part is too complex). Could you please look into whether this support could be possible just once more? Thanks a lot.