From 8dca32504225aff57532aa44e0c583b762f94287 Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Thu, 12 Nov 2020 01:18:43 -0800 Subject: [PATCH] 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. --- src/fields/fp/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fields/fp/mod.rs b/src/fields/fp/mod.rs index 693093c..d6e035c 100644 --- a/src/fields/fp/mod.rs +++ b/src/fields/fp/mod.rs @@ -876,7 +876,8 @@ impl ToBitsGadget for FpVar { fn to_non_unique_bits_le(&self) -> Result>, 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::>()), Self::Var(v) => v.to_non_unique_bits_le(),