pub fn alloc_scalar_as_base<G, CS>(
  mut cs: CS,
  input: Option<G::Scalar>,
) -> Result<AllocatedNum<G::Base>, SynthesisError>
where
  G: Group,
  <G as Group>::Scalar: PrimeFieldBits,
  CS: ConstraintSystem<<G as Group>::Base>,
{
  AllocatedNum::alloc(cs.namespace(|| "allocate scalar as base"), || {
    let input_bits = input.unwrap_or_else(G::Scalar::zero).clone().to_le_bits();
    let mut mult = G::Base::one();
    let mut val = G::Base::zero();
    for bit in input_bits {
      if bit {
        val += mult;
      }
      mult = mult + mult;
    }
    Ok(val)
  })
}
/// Allocate a scalar as a base. Only to be used is the scalar fits in base!
Allocate a scalar as a base. Only to be used is the scalar fits in base!
Allocate a scalar as a base . Only to be used is the scalar fits in base!
pub fn alloc_scalar_as_base<G, CS>(
  mut cs: CS,
  input: Option<G::Scalar>,
) -> Result<AllocatedNum<G::Base>, SynthesisError>
where
  G: Group,
  <G as Group>::Scalar: PrimeFieldBits,
  CS: ConstraintSystem<<G as Group>::Base>,
{
  AllocatedNum::alloc(cs.namespace(|| "allocate scalar as base"), || {
    let input_bits = input.unwrap_or_else(G::Scalar::zero).clone().to_le_bits();
    let mut mult = G::Base::one();
    let mut val = G::Base::zero();
    for bit in input_bits {
      if bit {
        val += mult;
      }
      mult = mult + mult;
    }
    Ok(val)
  })
}
pub fn alloc_scalar_as_base < G , CS > ( mut cs : CS , input : Option < G :: Scalar > , ) -> Result < AllocatedNum < G :: Base > , SynthesisError > where G : Group , < G as Group > :: Scalar : PrimeFieldBits , CS : ConstraintSystem < < G as Group > :: Base > , { AllocatedNum :: alloc ( cs . namespace ( | | " " ) , | | { let input_bits = input . unwrap_or_else ( G :: Scalar :: zero ) . clone ( ) . to_le_bits ( ) ; let mut mult = G :: Base :: one ( ) ; let mut val = G :: Base :: zero ( ) ; for bit in input_bits { if bit { val += mult ; } mult = mult + mult ; } Ok ( val ) } ) }
Allocate a scalar as a base.
Allocate a scalar as a base .
cs
CS
input
Option<G::Scalar>
cs
CS
input
Option<G::Scalar>