fn decompose_and_enforce_less_than_k_bits(
    cs: ConstraintSystemRef<Fq>,
    input_var: &FqVar,
    bit_length: usize,
) -> Result<Vec<Boolean<Fq>>, SynthesisError> {
    if bit_length == 0 {
        panic!("invalid input bit length {}", bit_length)
    }

    let input_val = input_var.value()?;
    let input_bits = input_val.into_repr().to_bits_le();
    let input_bits_vars = input_bits
        .iter()
        .take(bit_length)
        .map(|b| Boolean::new_witness(cs.clone(), || Ok(*b)))
        .collect::<Result<Vec<_>, _>>()?;

    let mut res_var = FqVar::from(input_bits_vars[bit_length - 1].clone());
    for e in input_bits_vars.iter().rev().skip(1) {
        res_var = res_var.double()?;
        res_var = &res_var + FqVar::from(e.clone());
    }
    res_var.enforce_equal(input_var)?;

    Ok(input_bits_vars)
}
// Decomposite the elements into bit_length booleans and prove that
// input is the composition of those bit_length booleans.
// This implies that input < 2^bit_length.
// Return the bit_length boolean constrains.
// Cost: bit_length+1 constraints
Decomposite the elements into bit_length booleans and prove that
input is the composition of those bit_length booleans.
This implies that input < 2^bit_length.
Return the bit_length boolean constrains.
Decomposite the elements into bit_length booleans and prove that input is the composition of those bit_length booleans . This implies that input < 2^bit_length . Return the bit_length boolean constrains .
fn decompose_and_enforce_less_than_k_bits(
    cs: ConstraintSystemRef<Fq>,
    input_var: &FqVar,
    bit_length: usize,
) -> Result<Vec<Boolean<Fq>>, SynthesisError> {
    if bit_length == 0 {
        panic!("invalid input bit length {}", bit_length)
    }
    let input_val = input_var.value()?;
    let input_bits = input_val.into_repr().to_bits_le();
    let input_bits_vars = input_bits
        .iter()
        .take(bit_length)
        .map(|b| Boolean::new_witness(cs.clone(), || Ok(*b)))
        .collect::<Result<Vec<_>, _>>()?;
    let mut res_var = FqVar::from(input_bits_vars[bit_length - 1].clone());
    for e in input_bits_vars.iter().rev().skip(1) {
        res_var = res_var.double()?;
        res_var = &res_var + FqVar::from(e.clone());
    }
    res_var.enforce_equal(input_var)?;
    Ok(input_bits_vars)
}
fn decompose_and_enforce_less_than_k_bits ( cs : ConstraintSystemRef < Fq > , input_var : & FqVar , bit_length : usize , ) -> Result < Vec < Boolean < Fq > > , SynthesisError > { if bit_length == 0 { panic ! ( " " bit_length ) } let input_val = input_var . value ( ) ? ; let input_bits = input_val . into_repr ( ) . to_bits_le ( ) ; let input_bits_vars = input_bits . iter ( ) . take ( bit_length ) . map ( | b | Boolean :: new_witness ( cs . clone ( ) , | | Ok ( * b ) ) ) . collect :: < Result < Vec < _ > , _ > > ( ) ? ; let mut res_var = FqVar :: from ( input_bits_vars [ bit_length - 1 ] . clone ( ) ) ; for e in input_bits_vars . iter ( ) . rev ( ) . skip ( 1 ) { res_var = res_var . double ( ) ? ; res_var = & res_var + FqVar :: from ( e . clone ( ) ) ; } res_var . enforce_equal ( input_var ) ? ; Ok ( input_bits_vars ) }
Decomposite the elements into bit_length booleans and prove that
input is the composition of those bit_length booleans.
Decomposite the elements into bit_length booleans and prove that input is the composition of those bit_length booleans .
cs
ConstraintSystemRef<Fq>
input_var
&FqVar
bit_length
usize
cs
ConstraintSystemRef<Fq>
input_var
&FqVar
bit_length
usize