blyssprivacy/sdk

What does `(1i64 << 10)` mean in `dec_gsw`?

qxzhou1010 opened this issue · 3 comments

In src/server.rs, there is a method called dec_gsw :

    fn dec_gsw<'a>(params: &'a Params, ct: &PolyMatrixNTT<'a>, client: &mut Client<'a>) -> u64 {
   
        let dec = client.decrypt_matrix_reg(ct).raw();
        
        // why need calculate this idx?
        let idx: usize = 2 * (params.t_gsw - 1) * params.poly_len + params.poly_len; // this offset should encode a large value
        let mut val = dec.data[idx] as i64;
        if val >= (params.modulus / 2) as i64 {
            println!("{} - {} = {}", val as i64, params.modulus as i64,  val - params.modulus as i64);
            val -= params.modulus as i64;
        }
        println!("params.modulus: {}", params.modulus as i64);
        println!("dec.data[{}]: {}, val: {}", idx, dec.data[idx], val);

        // why compared with 1i64 << 10? where is the 1i64 << 10 comes from?
        if i64::abs(val) < (1i64 << 10) {
            0
        } else {
            1
        }
    }

I have two questions:

  1. why need to calculate a idx? let idx: usize = 2 * (params.t_gsw - 1) * params.poly_len + params.poly_len;
  2. why compared with 1i64 << 10? where is the 1i64 << 10 comes from?

@qxzhou1010 1 << 10 is 1024, << is bitshift left operator, basically the same as 2^10.

Thanks for your reply. Ok, I know this point. My question is that why use 2^10 here? why not use 2^8 or 2^5, or any other number ? What's the reference for using 2^10 here?

One possible guess here is plaintext space. However, I found in the parameters of the code that the plaintext modulus (pt_modulus) is all 256.