homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.11k stars 759 forks source link

segfault when running the BGV_binary_arithemtic #501

Open mk-khalil opened 9 months ago

mk-khalil commented 9 months ago

I built and installed HElib following the instructions (package build). When I tried to run one of the example projects (BGV_binary_arithmetic) it segfaults before doing the two number multiplication. I don't have a solid understanding of HElib but I wanted to use it for a simple project I'm working on that involves error injection on FHE. I'm using macos Sonoma v14.0. This is the output of the (BGV_binary_arithmetic) program that I attached to lldb debugger:

Process 85523 launched: '/Users/ma2323/fhe/HElib/examples/build/bin/BGV_binary_arithmetic' (arm64)

*********************************************************
*            Basic Binary Arithmetic Example            *
*            ===============================            *
*                                                       *
* This is a sample program for education purposes only. *
* It attempts to demonstrate the use of the API for the *
* binary arithmetic operations that can be performed.   *
*                                                       *
*********************************************************
Initialising context object...
RecryptData::setAE(): e=12, e'=4
m = 4095, p = 2, phi(m) = 1728
  ord(p) = 12
  normBnd = 2.25463
  polyNormBnd = 22.5545
  factors = [3 5 7 13]
  generator 2341 has order (== Z_m^*) of 6
  generator 3277 has order (== Z_m^*) of 4
  generator 911 has order (== Z_m^*) of 6
r = 1
nslots = 144
hwt = 120
ctxtPrimes = [6,7,8,9,10,11,12,13,14]
specialPrimes = [15,16,17,18,19]
number of bits = 798

security level = 24.2499

Security: 24.2499
Creating secret key...
Number of slots: 144
Pre-encryption data:
a = 3871
b = 65210
c = 35980
 before multiplication, capacity=487
Process 85523 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x00000001000b351c BGV_binary_arithmetic`helib::SecKey::Decrypt(NTL::ZZX&, helib::Ctxt const&, NTL::ZZX&) const [inlined] helib::PubKey::getContext(this=0x0000000000000000) const at keys.cpp:273:52 [opt]
   270  
   271  bool PubKey::operator!=(const PubKey& other) const { return !(*this == other); }
   272  
-> 273  const Context& PubKey::getContext() const { return context; }
   274  long PubKey::getPtxtSpace() const { return pubEncrKey.ptxtSpace; }
   275  bool PubKey::keyExists(long keyID) const
   276  {
Target 0: (BGV_binary_arithmetic) stopped.
warning: BGV_binary_arithmetic was compiled with optimization - stepping may behave oddly; variables may not be available.

And if it helps this is the exception's backtrace:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
  * frame #0: 0x00000001000b351c BGV_binary_arithmetic`helib::SecKey::Decrypt(NTL::ZZX&, helib::Ctxt const&, NTL::ZZX&) const [inlined] helib::PubKey::getContext(this=0x0000000000000000) const at keys.cpp:273:52 [opt]
    frame #1: 0x00000001000b351c BGV_binary_arithmetic`helib::SecKey::Decrypt(this=0x0000000000000000, plaintxt=0x000000016fdfe4c8, ciphertxt=0x0000000159a2a420, f=0x000000016fdfe4c0) const at keys.cpp:1338:13 [opt]
    frame #2: 0x000000010005f9e8 BGV_binary_arithmetic`helib::embeddingLargestCoeff(ctxt=<unavailable>, sk=<unavailable>) at debugging.cpp:60:6 [opt]
    frame #3: 0x000000010005f980 BGV_binary_arithmetic`helib::realToEstimatedNoise(ctxt=0x0000000159a2a420, sk=0x0000000000000000) at debugging.cpp:30:30 [opt]
    frame #4: 0x000000010005fb8c BGV_binary_arithmetic`helib::checkNoise(ctxt=<unavailable>, sk=<unavailable>, msg="reLinearize 5798798368", thresh=10) at debugging.cpp:50:16 [opt]
    frame #5: 0x00000001000513b0 BGV_binary_arithmetic`helib::Ctxt::multiplyBy(this=0x0000000159a2a420, other=<unavailable>) at Ctxt.cpp:1772:3 [opt]
    frame #6: 0x000000010002284c BGV_binary_arithmetic`helib::multTwoNumbers(helib::PtrVector<helib::Ctxt>&, helib::PtrVector<helib::Ctxt> const&, helib::PtrVector<helib::Ctxt> const&, bool, long, std::__1::vector<NTL::Vec<long>, std::__1::allocator<NTL::Vec<long>>>*) at binaryArith.cpp:1104:19 [opt]
    frame #7: 0x00000001000227e4 BGV_binary_arithmetic`helib::multTwoNumbers(helib::PtrVector<helib::Ctxt>&, helib::PtrVector<helib::Ctxt> const&, helib::PtrVector<helib::Ctxt> const&, bool, long, std::__1::vector<NTL::Vec<long>, std::__1::allocator<NTL::Vec<long>>>*) [inlined] void NTL::BasicThreadPool::relaxed_exec_range<helib::multTwoNumbers(helib::PtrVector<helib::Ctxt>&, helib::PtrVector<helib::Ctxt> const&, helib::PtrVector<helib::Ctxt> const&, bool, long, std::__1::vector<NTL::Vec<long>, std::__1::allocator<NTL::Vec<long>>>*)::$_1>(pool=<unavailable>, sz=<unavailable>, fct=0x000000016fdfe630) at BasicThreadPool.h:561:7 [opt]
    frame #8: 0x00000001000227a8 BGV_binary_arithmetic`helib::multTwoNumbers(product=0x000000016fdfea28, lhs=0x000000016fdfea18, rhs=0x000000016fdfea08, rhsTwosComplement=<unavailable>, sizeLimit=<unavailable>, unpackSlotEncoding=0x000000016fdfec10 size=12) at binaryArith.cpp:1099:3 [opt]
    frame #9: 0x0000000100002d74 BGV_binary_arithmetic`main + 2504
    frame #10: 0x000000018f775058 dyld`start + 2224