mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 17:23:08 +00:00
Small fixes to the le_sum and reduce gadgets
This commit is contained in:
parent
5d8241760f
commit
4305a95cdb
@ -32,6 +32,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
bits: impl ExactSizeIterator<Item = impl Borrow<BoolTarget>> + Clone,
|
bits: impl ExactSizeIterator<Item = impl Borrow<BoolTarget>> + Clone,
|
||||||
) -> Target {
|
) -> Target {
|
||||||
let num_bits = bits.len();
|
let num_bits = bits.len();
|
||||||
|
if num_bits == 0 {
|
||||||
|
return self.zero();
|
||||||
|
}
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
BaseSumGate::<2>::START_LIMBS + num_bits <= self.config.num_routed_wires,
|
BaseSumGate::<2>::START_LIMBS + num_bits <= self.config.num_routed_wires,
|
||||||
"Not enough routed wires."
|
"Not enough routed wires."
|
||||||
|
|||||||
@ -137,12 +137,6 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
|||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reduces a length `n` vector of `ExtensionTarget`s using `n/2` `ArithmeticExtensionGate`s.
|
|
||||||
/// It does this by batching two steps of Horner's method in each gate.
|
|
||||||
/// Here's an example with `n=4, alpha=2, D=1`:
|
|
||||||
/// 1st gate: 2 0 4 4 3 4 11 <- 2*0+4=4, 2*4+3=11
|
|
||||||
/// 2nd gate: 2 11 2 24 1 24 49 <- 2*11+2=24, 2*24+1=49
|
|
||||||
/// which verifies that `2.reduce([1,2,3,4]) = 49`.
|
|
||||||
pub fn reduce<F>(
|
pub fn reduce<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
terms: &[ExtensionTarget<D>], // Could probably work with a `DoubleEndedIterator` too.
|
terms: &[ExtensionTarget<D>], // Could probably work with a `DoubleEndedIterator` too.
|
||||||
@ -155,7 +149,7 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
|||||||
self.count += l as u64;
|
self.count += l as u64;
|
||||||
|
|
||||||
let mut terms_vec = terms.to_vec();
|
let mut terms_vec = terms.to_vec();
|
||||||
let mut acc = terms_vec.pop().unwrap();
|
let mut acc = builder.zero_extension();
|
||||||
terms_vec.reverse();
|
terms_vec.reverse();
|
||||||
|
|
||||||
for x in terms_vec {
|
for x in terms_vec {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user