mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-02 22:03:07 +00:00
Merge pull request #126 from mir-protocol/remove_exp_from_complement
Replace `exp_from_complement_bits` with simpler method
This commit is contained in:
commit
5fbeb8742e
@ -25,18 +25,19 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
last_evals: &[ExtensionTarget<D>],
|
||||
beta: 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 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.
|
||||
let mut evals = last_evals.to_vec();
|
||||
reverse_index_bits_in_place(&mut evals);
|
||||
// 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.
|
||||
let start = self.exp_from_complement_bits(gt, old_x_index_bits.iter().rev());
|
||||
let coset_start = self.mul_many(&[start, gt, x]);
|
||||
// Want `g^(arity - rev_old_x_index)` as in the out-of-circuit version. Compute it as `(g^-1)^rev_old_x_index`.
|
||||
let start = self.exp_from_bits(g_inv_t, old_x_index_bits.iter().rev());
|
||||
let coset_start = self.mul(start, x);
|
||||
|
||||
// The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta.
|
||||
let points = g
|
||||
|
||||
@ -188,27 +188,6 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
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: Test
|
||||
/// Exponentiate `base` to the power of `exponent`, where `exponent < 2^num_bits`.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user