mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 16:53:07 +00:00
fmt
This commit is contained in:
parent
50c24dfe8a
commit
8d3662692e
@ -163,15 +163,15 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mul_biguint_by_bool(
|
pub fn mul_biguint_by_bool(&mut self, a: &BigUintTarget, b: BoolTarget) -> BigUintTarget {
|
||||||
&mut self,
|
|
||||||
a: &BigUintTarget,
|
|
||||||
b: BoolTarget,
|
|
||||||
) -> BigUintTarget {
|
|
||||||
let t = b.target;
|
let t = b.target;
|
||||||
|
|
||||||
BigUintTarget {
|
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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let sum_expected = self.add_biguint(&a.value, &b.value);
|
let sum_expected = self.add_biguint(&a.value, &b.value);
|
||||||
|
|
||||||
let modulus = self.constant_biguint(&FF::order());
|
let modulus = self.constant_biguint(&FF::order());
|
||||||
let mod_times_overflow = self.mul_biguint_by_bool(&modulus, overflow);
|
let mod_times_overflow = self.mul_biguint_by_bool(&modulus, overflow);
|
||||||
let sum_actual = self.add_biguint(&sum.value, &mod_times_overflow);
|
let sum_actual = self.add_biguint(&sum.value, &mod_times_overflow);
|
||||||
@ -95,7 +95,12 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
|
|
||||||
NonNativeTarget {
|
NonNativeTarget {
|
||||||
value: BigUintTarget {
|
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,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
@ -120,8 +125,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
_phantom: PhantomData,
|
_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 modulus = self.constant_biguint(&FF::order());
|
||||||
let overflow_biguint = BigUintTarget {
|
let overflow_biguint = BigUintTarget {
|
||||||
limbs: vec![overflow],
|
limbs: vec![overflow],
|
||||||
@ -285,9 +292,14 @@ impl<F: RichField + Extendable<D>, const D: usize, FF: Field> SimpleGenerator<F>
|
|||||||
for NonNativeAdditionGenerator<F, D, FF>
|
for NonNativeAdditionGenerator<F, D, FF>
|
||||||
{
|
{
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
self.a.value.limbs.iter().cloned().chain(self.b.value.limbs.clone())
|
self.a
|
||||||
.map(|l| l.0)
|
.value
|
||||||
.collect()
|
.limbs
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.chain(self.b.value.limbs.clone())
|
||||||
|
.map(|l| l.0)
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||||
@ -320,16 +332,27 @@ impl<F: RichField + Extendable<D>, const D: usize, FF: Field> SimpleGenerator<F>
|
|||||||
for NonNativeMultipleAddsGenerator<F, D, FF>
|
for NonNativeMultipleAddsGenerator<F, D, FF>
|
||||||
{
|
{
|
||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
self.summands.iter().map(|summand| summand.value.limbs.iter().map(|limb| limb.0))
|
self.summands
|
||||||
.flatten()
|
.iter()
|
||||||
.collect()
|
.map(|summand| summand.value.limbs.iter().map(|limb| limb.0))
|
||||||
|
.flatten()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||||
let summands: Vec<_> = self.summands.iter().map(|summand| witness.get_nonnative_target(summand.clone())).collect();
|
let summands: Vec<_> = self
|
||||||
let summand_biguints: Vec<_> = summands.iter().map(|summand| summand.to_biguint()).collect();
|
.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 modulus = FF::order();
|
||||||
let (overflow_biguint, sum_reduced) = sum_biguint.div_rem(&modulus);
|
let (overflow_biguint, sum_reduced) = sum_biguint.div_rem(&modulus);
|
||||||
@ -370,8 +393,6 @@ impl<F: RichField + Extendable<D>, const D: usize, FF: Field> SimpleGenerator<F>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user