Make ToBitsGadget for FpVar's output constant-length (#12)

This is related to a Zexe issue https://github.com/scipr-lab/zexe/issues/289

Basically, ToBitsGadget for FpVar may produce shorter output for a constant value, which is undesired for a few reasons.
This commit is contained in:
Weikeng Chen
2020-11-12 01:18:43 -08:00
committed by GitHub
parent 6077f51c97
commit 8dca325042

View File

@@ -876,7 +876,8 @@ impl<F: PrimeField> ToBitsGadget<F> for FpVar<F> {
fn to_non_unique_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError> {
use ark_ff::BitIteratorLE;
match self {
Self::Constant(c) => Ok(BitIteratorLE::without_trailing_zeros(&c.into_repr())
Self::Constant(c) => Ok(BitIteratorLE::new(&c.into_repr())
.take((F::Params::MODULUS_BITS) as usize)
.map(Boolean::constant)
.collect::<Vec<_>>()),
Self::Var(v) => v.to_non_unique_bits_le(),