From 8d3662692e6cbcec73ae35d6066fbca21202a29c Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Tue, 18 Jan 2022 14:11:21 -0800 Subject: [PATCH] fmt --- plonky2/src/gadgets/biguint.rs | 12 ++++---- plonky2/src/gadgets/nonnative.rs | 51 ++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/plonky2/src/gadgets/biguint.rs b/plonky2/src/gadgets/biguint.rs index 1a829f97..4f9e1574 100644 --- a/plonky2/src/gadgets/biguint.rs +++ b/plonky2/src/gadgets/biguint.rs @@ -163,15 +163,15 @@ impl, const D: usize> CircuitBuilder { } } - pub fn mul_biguint_by_bool( - &mut self, - a: &BigUintTarget, - b: BoolTarget, - ) -> BigUintTarget { + pub fn mul_biguint_by_bool(&mut self, a: &BigUintTarget, b: BoolTarget) -> BigUintTarget { let t = b.target; BigUintTarget { - limbs: a.limbs.iter().map(|l| U32Target(self.mul(l.0, t))).collect() + limbs: a + .limbs + .iter() + .map(|l| U32Target(self.mul(l.0, t))) + .collect(), } } diff --git a/plonky2/src/gadgets/nonnative.rs b/plonky2/src/gadgets/nonnative.rs index 1006b513..83333491 100644 --- a/plonky2/src/gadgets/nonnative.rs +++ b/plonky2/src/gadgets/nonnative.rs @@ -77,7 +77,7 @@ impl, const D: usize> CircuitBuilder { }); let sum_expected = self.add_biguint(&a.value, &b.value); - + let modulus = self.constant_biguint(&FF::order()); let mod_times_overflow = self.mul_biguint_by_bool(&modulus, overflow); let sum_actual = self.add_biguint(&sum.value, &mod_times_overflow); @@ -95,7 +95,12 @@ impl, const D: usize> CircuitBuilder { NonNativeTarget { value: BigUintTarget { - limbs: a.value.limbs.iter().map(|l| U32Target(self.mul(l.0, t))).collect() + limbs: a + .value + .limbs + .iter() + .map(|l| U32Target(self.mul(l.0, t))) + .collect(), }, _phantom: PhantomData, } @@ -120,8 +125,10 @@ impl, const D: usize> CircuitBuilder { _phantom: PhantomData, }); - let sum_expected = summands.iter().fold(self.zero_biguint(), |a, b| self.add_biguint(&a, &b.value)); - + let sum_expected = summands + .iter() + .fold(self.zero_biguint(), |a, b| self.add_biguint(&a, &b.value)); + let modulus = self.constant_biguint(&FF::order()); let overflow_biguint = BigUintTarget { limbs: vec![overflow], @@ -285,9 +292,14 @@ impl, const D: usize, FF: Field> SimpleGenerator for NonNativeAdditionGenerator { fn dependencies(&self) -> Vec { - self.a.value.limbs.iter().cloned().chain(self.b.value.limbs.clone()) - .map(|l| l.0) - .collect() + self.a + .value + .limbs + .iter() + .cloned() + .chain(self.b.value.limbs.clone()) + .map(|l| l.0) + .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { @@ -320,16 +332,27 @@ impl, const D: usize, FF: Field> SimpleGenerator for NonNativeMultipleAddsGenerator { fn dependencies(&self) -> Vec { - self.summands.iter().map(|summand| summand.value.limbs.iter().map(|limb| limb.0)) - .flatten() - .collect() + self.summands + .iter() + .map(|summand| summand.value.limbs.iter().map(|limb| limb.0)) + .flatten() + .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let summands: Vec<_> = self.summands.iter().map(|summand| witness.get_nonnative_target(summand.clone())).collect(); - let summand_biguints: Vec<_> = summands.iter().map(|summand| summand.to_biguint()).collect(); + let summands: Vec<_> = self + .summands + .iter() + .map(|summand| witness.get_nonnative_target(summand.clone())) + .collect(); + let summand_biguints: Vec<_> = summands + .iter() + .map(|summand| summand.to_biguint()) + .collect(); - let sum_biguint = summand_biguints.iter().fold(BigUint::zero(), |a, b| a + b.clone()); + let sum_biguint = summand_biguints + .iter() + .fold(BigUint::zero(), |a, b| a + b.clone()); let modulus = FF::order(); let (overflow_biguint, sum_reduced) = sum_biguint.div_rem(&modulus); @@ -370,8 +393,6 @@ impl, const D: usize, FF: Field> SimpleGenerator } } - - #[cfg(test)] mod tests { use anyhow::Result;