Huelse / SEAL-Python

Microsoft SEAL 4.X For Python
MIT License
310 stars 66 forks source link

Issues in the output of test scripts #34

Closed tremblerz closed 3 years ago

tremblerz commented 3 years ago
python 1_bfv_basics.py 
+-------------------------------------+
|         Example: BFV Basics         |
+-------------------------------------+
--------------------------------------------------
Set encryption parameters and print
/
| Encryption parameters:
| scheme: BFV
| poly_modulus_degree: 4096
| coeff_modulus size: 109(36 + 36 + 37) bits
| plain_modulus: 256
\
~~~~~~ A naive way to calculate 2(x^2+1)(x+1)^2. ~~~~~~
--------------------------------------------------
Express x = 6 as a plaintext polynomial 0x6.
--------------------------------------------------
Encrypt x_plain to x_encrypted.
    + size of freshly encrypted x: 2
    + noise budget in freshly encrypted x: 57 bits
    + decryption of x_encrypted: 0x6 ...... Correct.
--------------------------------------------------
Compute x_sq_plus_one (x^2+1).
    + size of x_sq_plus_one: 3
    + noise budget in x_sq_plus_one: 37 bits
    + decryption of x_sq_plus_one: 0x25 ...... Correct.
--------------------------------------------------
Compute x_plus_one_sq ((x+1)^2).
    + size of x_plus_one_sq: 3
    + noise budget in x_plus_one_sq: 37 bits
    + decryption of x_plus_one_sq: 0x31 ...... Correct.
--------------------------------------------------
Compute encrypted_result (4(x^2+1)(x+1)^2).
    + size of encrypted_result: 5
    + noise budget in encrypted_result: 9 bits
NOTE: Decryption can be incorrect if noise budget is zero.

~~~~~~ A better way to calculate 4(x^2+1)(x+1)^2. ~~~~~~
--------------------------------------------------
Generate relinearization keys.
--------------------------------------------------
Compute and relinearize x_squared (x^2),
             then compute x_sq_plus_one (x^2+1)
    + size of x_squared: 3
    + size of x_squared (after relinearization): 2
    + noise budget in x_sq_plus_one: 37 bits
    + decryption of x_sq_plus_one: 0x25 ...... Correct.
--------------------------------------------------
Compute x_plus_one (x+1),
             then compute and relinearize x_plus_one_sq ((x+1)^2).
    + size of x_plus_one_sq: 3
    + noise budget in x_plus_one_sq: 37 bits
    + decryption of x_plus_one_sq: 0x31 ...... Correct.
--------------------------------------------------
Compute and relinearize encrypted_result (4(x^2+1)(x+1)^2).
    + size of encrypted_result: 3
    + size of encrypted_result (after relinearization): 2
    + noise budget in encrypted_result: 16 bits

NOTE: Notice the increase in remaining noise budget.
--------------------------------------------------
Decrypt encrypted_result (4(x^2+1)(x+1)^2).
    + decryption of 4(x^2+1)(x+1)^2 = 0x54 ...... Correct.

Not sure why x^2 + 1 should be 25 if you have x=6, shouldn't it be 37. Same is the case with other outputs as well. EDIT: Tried on two different systems Mac and Ubuntu, getting same output.

Huelse commented 3 years ago

Hexadecimal, 0x25 = 2*16+5 = 37.

tremblerz commented 3 years ago

oh damn! stupid me