diff --git a/src/fri/recursive_verifier.rs b/src/fri/recursive_verifier.rs index 12246504..11cdd7d4 100644 --- a/src/fri/recursive_verifier.rs +++ b/src/fri/recursive_verifier.rs @@ -33,13 +33,9 @@ impl, const D: usize> CircuitBuilder { // The evaluation vector needs to be reordered first. let mut evals = last_evals.to_vec(); reverse_index_bits_in_place(&mut evals); - let mut old_x_index_bits = old_x_index_bits.to_vec(); - old_x_index_bits.reverse(); // 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. - // TODO: Once the exponentiation gate lands, we won't need the bits and will be able to compute - // `g^(arity-rev_old_x_index)` directly. - let start = self.exp_from_complement_bits(gt, &old_x_index_bits); + let start = self.exp_from_complement_bits(gt, old_x_index_bits.iter().rev()); let coset_start = self.mul_many(&[start, gt, x]); // The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta. diff --git a/src/gadgets/arithmetic.rs b/src/gadgets/arithmetic.rs index 6dcf1b3d..0598f3e7 100644 --- a/src/gadgets/arithmetic.rs +++ b/src/gadgets/arithmetic.rs @@ -1,3 +1,5 @@ +use std::borrow::Borrow; + use crate::circuit_builder::CircuitBuilder; use crate::field::extension_field::Extendable; use crate::target::Target; @@ -187,15 +189,19 @@ impl, const D: usize> CircuitBuilder { // 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: &[Target]) -> Target { + pub fn exp_from_complement_bits( + &mut self, + base: Target, + exponent_bits: impl ExactSizeIterator> + Clone, + ) -> Target { let mut current = base; let one_ext = self.one_extension(); let mut product = self.one(); - for &bit in exponent_bits { + for bit in exponent_bits { let current_ext = self.convert_to_ext(current); // TODO: Add base field select. - let multiplicand = self.select(bit, one_ext, current_ext); + let multiplicand = self.select(*bit.borrow(), one_ext, current_ext); product = self.mul(product, multiplicand.0[0]); current = self.mul(current, current); }