Unable to compute multiplication

@IceTDrinker

I am unable to compute multiplication using the shortint_sk.smart_mul_lsb_assign(). I get error current parameters can’t be used to make a bivariate function evaluation.

Same code was working earlier. I am using standard shortint parameters and have tried with different shortint parameters, to get same error for all.

What could be the reason

The carry modulus needs to be >= to the message modulus for bivariate functions

How do I make sure this happens?

see e.g. this parameter set for shortint: tfhe-rs/tfhe/src/shortint/parameters/classic/p_fail_2_minus_40/ks_pbs.rs at 57c5ef6b52624e3c2395583b2875fb41230159bd · zama-ai/tfhe-rs · GitHub

the carry modulus is >= message modulus

you need to choose parameters that satisfy this constraint

1 Like

Also in version 0.6.1 I see that for integers operation scalar_eq_parallelized function the return structure is a BooleanBlock instead of RadicCiphertext. The question is saying I want to use the result from scalar_eq_parallelized to multiply/add with a RadixCipher, earlier it used to be a direct operation. How do you suggest I do it now?

It is in the API reference

1 Like

Here is my code snippet

let cipher = sks.smart_scalar_eq_parallelized(&ip, 0u64);
cipher.into_radix(&num_blocks, &sks);

let blocks = cipher.blocks()

This results in error method not found for BooleanBlock in last line of code. What am I doing wrong here?

If you need access to the blocks you need to import the following trait

with use tfhe::integer::IntegerCiphertext

if you just want the ciphertext in the boolean block you can call into_inner

I am already using

use::tfhe::integer::IntegerCiphertext

The concern is into_radix function is not converting the BooleanBlock into a RadixCiphertext, because if it was, i would not get the error that BooleanBlocks doesn’t have blocks method

I want to use multiply 2 shortint ciphertexts and then add the result to a radixCiphertext, that is why I am using blocks

Please share a github repository with the code causing problems

Thanks

a version that compiles, you were misusing the into_radix function which returns a value.

I added a comment that you should read as you seem to be using the wrong block of the boolean as a radix to get the data you are interested in

use tfhe::integer::{gen_keys_radix, IntegerCiphertext, RadixCiphertext};

use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;

fn main() {
    let num_blocks = 4;
    let (cks, sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2, num_blocks);
    let num = 47u8;

    let mut cipher = cks.encrypt(num);

    let shortint_sk: tfhe::shortint::ServerKey = sks.clone().into();

    let mut output: RadixCiphertext = sks.create_trivial_radix(0u64, num_blocks);

    let mut res1 = sks.smart_scalar_eq_parallelized(&mut cipher, 47);
    let mut res2 = shortint_sk.create_trivial(1);

    let mut res1_as_radix: RadixCiphertext = res1.into_radix(num_blocks, &sks);

    let res1_blocks = res1_as_radix.blocks_mut();
    // Warning data is stored in Little endian order, if you want to have access to the 0 or the 1
    // from the boolean block you need to use res1_blocks[0]
    shortint_sk.smart_mul_lsb_assign(&mut res1_blocks[num_blocks - 1], &mut res2);

    sks.smart_add_assign_parallelized(&mut output, &mut res1_as_radix);
}
1 Like

Say I have another encrypted Boolean like

let b1 = cks.encrypt_bool(true)

Now I want to do a boolean operation with variable res1, how do I generate the Boolean supported server_key to this operation?

The tfhe::integer::ServerKey supports operations with BooleanBlock, they are prefixed with boolean_

Hmm, interesting. So say I have compared two FheUint8 variables, the result is stored in BooleanBlock. What will be the size of this BooleanBlock? Is it one bit or 8 bit? To be more precise how are these BooleanBlock represented in terms of LWE ciphers?

They are just 1 block, so 1 LWE

1 Like