mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Replace exp_from_complement_bits with simpler method
This commit is contained in:
parent
6f8053cc37
commit
f325586beb
@ -25,18 +25,20 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
last_evals: &[ExtensionTarget<D>],
|
last_evals: &[ExtensionTarget<D>],
|
||||||
beta: ExtensionTarget<D>,
|
beta: ExtensionTarget<D>,
|
||||||
) -> ExtensionTarget<D> {
|
) -> ExtensionTarget<D> {
|
||||||
debug_assert_eq!(last_evals.len(), 1 << arity_bits);
|
let arity = 1 << arity_bits;
|
||||||
|
debug_assert_eq!(last_evals.len(), arity);
|
||||||
|
|
||||||
let g = F::primitive_root_of_unity(arity_bits);
|
let g = F::primitive_root_of_unity(arity_bits);
|
||||||
let gt = self.constant(g);
|
let g_inv = g.exp((arity as u64) - 1);
|
||||||
|
let g_inv_t = self.constant(g_inv);
|
||||||
|
|
||||||
// The evaluation vector needs to be reordered first.
|
// The evaluation vector needs to be reordered first.
|
||||||
let mut evals = last_evals.to_vec();
|
let mut evals = last_evals.to_vec();
|
||||||
reverse_index_bits_in_place(&mut evals);
|
reverse_index_bits_in_place(&mut evals);
|
||||||
// Want `g^(arity - rev_old_x_index)` as in the out-of-circuit version.
|
// Want `g^(arity - rev_old_x_index)` as in the out-of-circuit version.
|
||||||
// Compute it as `g^(arity-1-rev_old_x_index) * g`, where the first term is gotten using two's complement.
|
// Compute it as `g^(arity-1-rev_old_x_index) * g`, where the first term is gotten using two's complement.
|
||||||
let start = self.exp_from_complement_bits(gt, old_x_index_bits.iter().rev());
|
let start = self.exp_from_bits(g_inv_t, old_x_index_bits.iter().rev());
|
||||||
let coset_start = self.mul_many(&[start, gt, x]);
|
let coset_start = self.mul(start, x);
|
||||||
|
|
||||||
// The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta.
|
// The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta.
|
||||||
let points = g
|
let points = g
|
||||||
|
|||||||
@ -188,27 +188,6 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
product
|
product
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this, maybe with a new gate.
|
|
||||||
// TODO: Test
|
|
||||||
/// Exponentiate `base` to the power of `2^bit_length-1-exponent`, given by its little-endian bits.
|
|
||||||
pub fn exp_from_complement_bits(
|
|
||||||
&mut self,
|
|
||||||
base: Target,
|
|
||||||
exponent_bits: impl Iterator<Item = impl Borrow<Target>>,
|
|
||||||
) -> Target {
|
|
||||||
let mut current = base;
|
|
||||||
let one = self.one();
|
|
||||||
let mut product = one;
|
|
||||||
|
|
||||||
for bit in exponent_bits {
|
|
||||||
let multiplicand = self.select(*bit.borrow(), one, current);
|
|
||||||
product = self.mul(product, multiplicand);
|
|
||||||
current = self.mul(current, current);
|
|
||||||
}
|
|
||||||
|
|
||||||
product
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this, maybe with a new gate.
|
// TODO: Optimize this, maybe with a new gate.
|
||||||
// TODO: Test
|
// TODO: Test
|
||||||
/// Exponentiate `base` to the power of `exponent`, where `exponent < 2^num_bits`.
|
/// Exponentiate `base` to the power of `exponent`, where `exponent < 2^num_bits`.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user