How to choose padding bit for output encoder during bootstrapping? And Why the way you handle drift error in VectorLWE and LWE are different?

I have confusion on how to choose the padding bit for output encoder during the bootstrapping operation. From the code in vector_lwe, in bootstrap_nth_with_function, I see this code section:

The if condition only depend on the old encoder bit padding. It seems that as long as my output encoder padding bit doesn’t overlap with the noise in new ciphertext everything will be okay, but it turns out that if I choose padding bit that is too large on output encoding, the cipher will be corrupted by noise. So I think the code above should be (?):

        if nb_rounding_noise_bit
            +  new_encoder_output.nb_bit_padding
            + new_encoder_output.nb_bit_precision
            > bsk.get_polynomial_size_log() + 1
        {
            let nb_bit_loss = self.encoders[n].nb_bit_padding
                + new_encoder_output.nb_bit_precision
                + nb_rounding_noise_bit
                - bsk.get_polynomial_size_log()
                - 1;

            new_encoder_output.nb_bit_precision = i32::max(
                new_encoder_output.nb_bit_precision as i32 - nb_bit_loss as i32,
                0i32,
            ) as usize;
            // drift
            println!(
                "{}: {} bit(s) of precision lost over {} bit(s) of message originally ({} bits are affected by the noise). Consider increasing the polynomial size of the RLWE secret key.",
                "Loss of precision during bootstrap due to the rounding".red().bold(),
                nb_bit_loss, self.encoders[n].nb_bit_precision,nb_rounding_noise_bit
            );
        }

The other question is why in lwe, in bootstrap_with_function, the code for dealing drift error become like this:

Why you always fix the bit padding of old encoder always 1? Why don’t you make it same with the code from vector_lwe? Thank you

Hello @Dwen, so sorry for the late reply. I’ve asked the Concrete Lib team to have a look at your question!
Thanks for your patience :sweat_smile:
Jérémy

Hello @Dwen

It seems you have spotted 2 errors :+1:
Would you mind opening a PR ? as your suggestions sounds like proper fixes for both issues.
Thanks