/// Take a sequence of booleans and expose them as compact public inputs, if the conditional value
/// equals 1. If the conditional value equals 0, the public inputs are set to 0.
Take a sequence of booleans and expose them as compact public inputs, if the conditional value
equals 1. If the conditional value equals 0, the public inputs are set to 0.
Take a sequence of booleans and expose them as compact public inputs if the conditional value equals 1 . If the conditional value equals 0 the public inputs are set to 0 .
pub fn conditional_pack_into_inputs<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(
    mut cs: CS,
    bits: &[Boolean],
    conditional_bit: &AllocatedBit,
) -> Result<(), SynthesisError> {
    for (i, bits) in bits.chunks(Scalar::CAPACITY as usize).enumerate() {
        // Note: we counter-act the reverse in num_from_bits.
        let num = num_from_bits::<Scalar, CS>(&bits.iter().rev().cloned().collect::<Vec<_>>());
        let input = cs.alloc_input(
            || format!("input {}", i),
            || match conditional_bit.get_value() {
                Some(true) => Ok(*num.get_value().get()?),
                Some(false) => Ok(Scalar::zero()),
                None => Err(SynthesisError::AssignmentMissing),
            },
        )?;
        cs.enforce(
            || format!("conditional constraint {}", i),
            |_| num.lc(Scalar::one()),
            |lc| lc + conditional_bit.get_variable(),
            |lc| lc + input,
        );
    }
    Ok(())
}
pub fn conditional_pack_into_inputs < Scalar : PrimeField , CS : ConstraintSystem < Scalar > > ( mut cs : CS , bits : & [ Boolean ] , conditional_bit : & AllocatedBit , ) -> Result < ( ) , SynthesisError > { for ( i , bits ) in bits . chunks ( Scalar :: CAPACITY as usize ) . enumerate ( ) { // Note: we counter-act the reverse in num_from_bits. let num = num_from_bits :: < Scalar , CS > ( & bits . iter ( ) . rev ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ) ; let input = cs . alloc_input ( | | format ! ( " " i ) , | | match conditional_bit . get_value ( ) { Some ( true ) => Ok ( * num . get_value ( ) . get ( ) ? ) , Some ( false ) => Ok ( Scalar :: zero ( ) ) , None => Err ( SynthesisError :: AssignmentMissing ) , } , ) ? ; cs . enforce ( | | format ! ( " " i ) , | _ | num . lc ( Scalar :: one ( ) ) , | lc | lc + conditional_bit . get_variable ( ) , | lc | lc + input , ) ; } Ok ( ( ) ) }
Take a sequence of booleans and expose them as compact public inputs, if the conditional value
equals 1.
Take a sequence of booleans and expose them as compact public inputs if the conditional value equals 1 .
cs
CS
bits
&[Boolean]
conditional_bit
&AllocatedBit