Browse Source

Speed up exp_by_const

master
ValarDragon 4 years ago
committed by Pratyush Mishra
parent
commit
349407faef
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      r1cs-std/src/fields/mod.rs

+ 5
- 3
r1cs-std/src/fields/mod.rs

@ -242,17 +242,19 @@ pub trait FieldGadget:
mut cs: CS,
exp: S,
) -> Result<Self, SynthesisError> {
let mut res = Self::one(cs.ns(|| "Alloc result"))?;
let mut res = self.clone();
let mut found_one = false;
for (i, bit) in BitIterator::new(exp).enumerate() {
if found_one {
res.square_in_place(cs.ns(|| format!("square for bit {:?}", i)))?;
res = res.square(cs.ns(|| format!("square for bit {:?}", i)))?;
}
if bit {
if found_one {
res = res.mul(cs.ns(|| format!("mul for bit {:?}", i)), self)?;
}
found_one = true;
res.mul_in_place(cs.ns(|| format!("mul for bit {:?}", i)), self)?;
}
}

Loading…
Cancel
Save