zama-ai / concrete

Concrete: TFHE Compiler that converts python programs into FHE equivalent
Other
1.26k stars 145 forks source link

Questions regard to the module npe and the macro deltas_eq #9

Closed NewStaff971 closed 3 years ago

NewStaff971 commented 3 years ago

It has been a while since I use this library. It is an extraordinary FHE library. I have two questions during my usage.

Q1: The formula for noise estimation of key switching is potentially wrong.

In concrete version 0.1.7, the following code is weird from my point of view:

https://github.com/zama-ai/concrete/blob/aa73965cc2595181eda3f16cd37eed5ee974468c/concrete-npe/src/lwe.rs#L56

I guess it should be

let q_square = f64::powi(2., (2 * std::mem::size_of::<$T>() * 8) as i32);

Q2: The deltas_eq macro confused me.

https://github.com/zama-ai/concrete/blob/aa73965cc2595181eda3f16cd37eed5ee974468c/concrete/src/lib.rs#L123-L130

As the name suggested, the macro compares the equality of two f64 variables. However, a simple pair of float numbers (10., 20.) proves the macro is not working.

Hope to get a reply.

aPere3 commented 3 years ago

Hello @NewStaff971 :wave: ,

Thanks for reaching out !

For your first question, good catch, this is a bug introduced in the 0.1.7 version. I am preparing a patch to fix that.

For your second question, this macro is supposed to check if encoding deltas are compatible, e.g. they must have not more than 20 different least significant bits on their mantissa. I don't know what the current implementation is supposed to do, but I'll include a new version of the function in the patch.

Also, a new crate, specially meant to manage encoding should be included in the next major release.

Again, thanks for going this deep into the library, and for reaching out with your questions :smiley: