mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 00:33:06 +00:00
Merge pull request #718 from mir-protocol/fix_basesumgate_numlimbs
Fix `num_limbs` in `BaseSumGate`
This commit is contained in:
commit
58256ce052
@ -3,6 +3,7 @@ use std::ops::Range;
|
||||
use plonky2_field::extension::Extendable;
|
||||
use plonky2_field::packed::PackedField;
|
||||
use plonky2_field::types::{Field, Field64};
|
||||
use plonky2_util::log_floor;
|
||||
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::gates::packed_util::PackedEvaluableBase;
|
||||
@ -32,7 +33,8 @@ impl<const B: usize> BaseSumGate<B> {
|
||||
}
|
||||
|
||||
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 =
|
||||
log_floor(F::ORDER - 1, B as u64).min(config.num_routed_wires - Self::START_LIMBS);
|
||||
Self::new(num_limbs)
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,23 @@ pub fn log2_strict(n: usize) -> usize {
|
||||
res as usize
|
||||
}
|
||||
|
||||
/// Returns the largest integer `i` such that `base**i <= n`.
|
||||
pub const fn log_floor(n: u64, base: u64) -> usize {
|
||||
assert!(n > 0);
|
||||
assert!(base > 1);
|
||||
let mut i = 0;
|
||||
let mut cur: u64 = 1;
|
||||
loop {
|
||||
let (mul, overflow) = cur.overflowing_mul(base);
|
||||
if overflow || mul > n {
|
||||
return i;
|
||||
} else {
|
||||
i += 1;
|
||||
cur = mul;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Permutes `arr` such that each index is mapped to its reverse in binary.
|
||||
pub fn reverse_index_bits<T: Copy>(arr: &[T]) -> Vec<T> {
|
||||
let n = arr.len();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user