Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable transparent ciphertext runtime error? #124

Closed
AlexMV12 opened this issue May 30, 2022 · 7 comments
Closed

How to disable transparent ciphertext runtime error? #124

AlexMV12 opened this issue May 30, 2022 · 7 comments
Labels
Functionality Wether this library supports a certain operation or not

Comments

@AlexMV12
Copy link

Describe the feature
By default, SEAL enable a runtime check against "transparent" ciphertexts.
As of this SEAL issue, transparent ciphertexts are defined as ciphertexts whose second polynomial is 0.
The check is done because such ciphertext (in the form (ctxt[0], 0)) is just a "plain" value inside a ciphertext object, hence, not guaranteeing any protection against attacks (i.e., no secret key is needed to access that value). Producing a transparent ciphertext in Pyfhel results in a runtime error:

from Pyfhel import Pyfhel, PyPtxt, PyCtxt

HE = Pyfhel()
HE.contextGen(scheme='bfv', n=2**12, t_bits=20)
HE.keyGen()
HE.relinKeyGen()

ctxt1 = HE.encrypt(42)
ptxt1 = HE.encode(0)

r = ctxt1*ptxt1

produces:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [119], in <cell line: 7>()
      4 ctxt1 = HE.encrypt(42)
      5 ptxt1 = HE.encode(0)
----> 7 r = ctxt1*ptxt1

File Pyfhel/PyCtxt.pyx:431, in Pyfhel.PyCtxt.PyCtxt.__mul__()

File Pyfhel/Pyfhel.pyx:1041, in Pyfhel.Pyfhel.Pyfhel.multiply_plain()

RuntimeError: result ciphertext is transparent

In the same SEAL issue it is written that such warning may be disabled "[by] passing -DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=OFF when configuring SEAL through CMake".

It would be nice to have a way to disable this check, what do you think? Thanks!

Is this feature related to a project/objective? Please describe briefly
Transparent ciphertexts may be expected in some scenarios. Consider, for instance, ML/DL models on encrypted data. It may happen that a weight is 0; hence, it is not surprising that the output neuron is... 0. It is not a problem, though, because no data leak happens.

Unfortunately a RuntimeError is quite difficult to manage, and for now I have no ideas on how to proceed.

@AlexMV12 AlexMV12 added the Functionality Wether this library supports a certain operation or not label May 30, 2022
ibarrond added a commit that referenced this issue May 30, 2022
Control whether multiplying a ciphertxt with a zeroed plaintext raises a Runtime Error or not
@ibarrond
Copy link
Owner

I would leave it on by default for security purposes (so that novel users do not accidentally program vulnerable applications). That being said, you can control the CMake flags passed to SEAL by modifying the pyproject.toml file. In your case, you can manually set the following property to 'OFF' (and install the repo locally via pip install .) to disable that Runtime Error:

SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT='ON' # ON/OFF, runtime error when multiplying a ctxt with a zeroed plaintext.

@AlexMV12
Copy link
Author

Thanks! This looks reasonable. Thank you for the commit.

@AlexMV12
Copy link
Author

AlexMV12 commented Jun 9, 2022

Hi ibarrond,
I had time today to try this but unfortunately, even after changing the line to "OFF" and installing Pyfhel via pip install . still throws the transparent ciphertext error. Do you have any clues?
Thanks!

@AlexMV12 AlexMV12 reopened this Jun 9, 2022
@ibarrond
Copy link
Owner

ibarrond commented Jun 9, 2022

Mmmmm, can you do pip install -v . (verbose) and check if there is any occurrence of "SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT" in the output? This way we could rule out an issue with argument parsing to run CMake.

@AlexMV12
Copy link
Author

Yes, there is, but the settings is not taken:

...
-- Performing Test C_FLAG_WCAST_ALIGN - Success
  -- Performing Test CXX_FLAG_WCAST_ALIGN
  -- Performing Test CXX_FLAG_WCAST_ALIGN - Success
  -- Performing Test C_FLAG_WCAST_QUAL
  -- Performing Test C_FLAG_WCAST_QUAL - Success
  -- Performing Test CXX_FLAG_WCAST_QUAL
  -- Performing Test CXX_FLAG_WCAST_QUAL - Success
  -- Performing Test C_FLAG_WSTRICT_PROTOTYPES
  -- Performing Test C_FLAG_WSTRICT_PROTOTYPES - Success
  -- CMAKE_INSTALL_PREFIX: /usr/local
  -- CMAKE_INSTALL_LIBDIR: lib
  -- ZSTD_LEGACY_SUPPORT not defined!
  -- ZSTD_MULTITHREAD_SUPPORT is disabled
  -- SEAL_USE_INTEL_HEXL: OFF
  -- BUILD_SHARED_LIBS: OFF
  -- SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT: ON
  -- SEAL_USE_GAUSSIAN_NOISE: OFF
  -- SEAL_DEFAULT_PRNG: Blake2xb
  -- x86intrin.h - found
  -- SEAL_USE_INTRIN: ON
  -- Performing Test SEAL_MEMSET_S_FOUND
  -- Performing Test SEAL_MEMSET_S_FOUND - Failed
...

I confirm that I modified the pyproject file:

  ## CMake options: https://github.com/microsoft/SEAL/#basic-cmake-options
    [cpplibraries.SEAL.cmake_opts]
    CMAKE_BUILD_TYPE = 'Release'
    SEAL_USE_INTEL_HEXL ='OFF'   # ON/OFF, use Intel HEXL for low-level kernels
    SEAL_USE_ALIGNED_ALLOC ='OFF'# ON/OFF, 64B aligned memory allocations, better perf with Intel HEXL.
    BUILD_SHARED_LIBS ='OFF'     # ON/OFF, build shared and not static library
    SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT = 'OFF' # ON/OFF, runtime error when multiplying a ctxt with a zeroed plaintext.

Thanks,
Alessandro

@ibarrond
Copy link
Owner

ibarrond commented Jun 12, 2022

Should be working now! We were missing a parser of cmake_opts section in pyproject.toml to add them to the call to the cmake_cli. Not anymore!

PS: Wow, Github closed it automatically just by writing "fixes #124", interesting.

@ibarrond ibarrond reopened this Jun 12, 2022
@AlexMV12
Copy link
Author

AlexMV12 commented Jun 13, 2022

Thanks, now it is working!
Let's close it then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality Wether this library supports a certain operation or not
Projects
None yet
Development

No branches or pull requests

2 participants