OpenMined / OpenMined/TenSEAL

The decryption results are inconsistent when great different parameters are used

Open
#355 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug :bug:
Dominant language
C++
Stars
1k
Forks
175
Avg merge
6d 12h
Merged PRs (30d)
5

Description

Description

The result of following code is different when choose different params coeff_mod_bit_sizes

import numpy as np
import tenseal as ts
num = 2048
np.random.seed(100)
g = np.random.random([num])
np.random.seed(101)
h = np.random.random([num])
context = ts.context(
            ts.SCHEME_TYPE.CKKS,
            poly_modulus_degree=4096,
            coeff_mod_bit_sizes=[40,28,40]
          )
context.generate_galois_keys()
context.global_scale = 2**28
enc_wx = ts.ckks_vector(context,h*0.25)
enc_forward = ts.ckks_vector(context,g)
res = (enc_forward*enc_wx).sum()
print("true result:",(num*np.log(2)+(g*h*0.25).sum())/num)
print("decrypt first, and then add num:",np.log(2)+res.decrypt()[0]/num)
print("add num first ,and then decrypt:",(num*np.log(2)+res).decrypt()[0]/num)
reslut:
true result: 0.7536323584203359
decrypt first, and then add num: 0.7536461963235349
add num first ,and then decrypt: 0.7536461963237073

While when I change the coeff_mod_bit_sizes even a little, the result is incorrect(seeing add num first ,and then decrypt result). And it has nothing to do with random number seeds

context = ts.context(
            ts.SCHEME_TYPE.CKKS,
            poly_modulus_degree=4096,
            coeff_mod_bit_sizes=[40,29,40]
          )
context.generate_galois_keys()
context.global_scale = 2**29
reslut:
true result: 0.7536323584203359
decrypt first, and then add num: 0.7536386286083517
add num first ,and then decrypt: -0.24636115532554803

How to Reproduce

Run the above code directly

Expected Behavior

A clear and concise description of what you expected to happen.

Screenshots

image

System Information

  • OS: [Windows]
  • OS Version: [10]
  • Language Version: [e.g. Python 3.7]
  • Package Manager Version: [tenseal 0.3.4]

Additional Context

I wonder why did this happen and how to choose parameters correctly

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided Python reproduction with both coeff_mod_bit_sizes configurations, starting at ts.context, context.global_scale, and ts.ckks_vector operations. Trace how the CKKS context and the res.decrypt() path handle the parameter changes. Done means the behavior is explained and, if it is a bug, the inconsistent result is corrected or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
cryptography
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.