mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Fix num_limbs in BaseSumGate
This commit is contained in:
parent
11666f02d2
commit
e8eca780ae
@ -32,7 +32,8 @@ impl<const B: usize> BaseSumGate<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_config<F: Field64>(config: &CircuitConfig) -> Self {
|
pub fn new_from_config<F: Field64>(config: &CircuitConfig) -> Self {
|
||||||
let num_limbs = F::BITS.min(config.num_routed_wires - Self::START_LIMBS);
|
let num_limbs =
|
||||||
|
logarithm(F::ORDER as usize, B).min(config.num_routed_wires - Self::START_LIMBS);
|
||||||
Self::new(num_limbs)
|
Self::new(num_limbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +193,23 @@ impl<F: RichField, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the largest `i` such that `base**i < n`.
|
||||||
|
const fn logarithm(n: usize, base: usize) -> usize {
|
||||||
|
assert!(n > 0);
|
||||||
|
assert!(base > 1);
|
||||||
|
let mut i = 0;
|
||||||
|
let mut cur: usize = 1;
|
||||||
|
loop {
|
||||||
|
let (mul, overflow) = cur.overflowing_mul(base);
|
||||||
|
if overflow || mul >= n {
|
||||||
|
return i;
|
||||||
|
} else {
|
||||||
|
i += 1;
|
||||||
|
cur = mul;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user