diff --git a/src/fri/recursive_verifier.rs b/src/fri/recursive_verifier.rs index 4219aefc..d0795520 100644 --- a/src/fri/recursive_verifier.rs +++ b/src/fri/recursive_verifier.rs @@ -261,7 +261,8 @@ impl, const D: usize> CircuitBuilder { let mut evaluations: Vec>> = Vec::new(); // TODO: Do we need to range check `x_index` to a target smaller than `p`? let mut x_index = challenger.get_challenge(self); - x_index = self.split_low_high(x_index, n_log).0; + x_index = self.split_low_high(x_index, n_log, 64).0; + let mut x_index_num_bits = n_log; let mut domain_size = n; self.fri_verify_initial_proof( x_index, @@ -301,7 +302,8 @@ impl, const D: usize> CircuitBuilder { }; let mut evals = round_proof.steps[i].evals.clone(); // Insert P(y) into the evaluation vector, since it wasn't included by the prover. - let (low_x_index, high_x_index) = self.split_low_high(x_index, arity_bits); + let (low_x_index, high_x_index) = + self.split_low_high(x_index, arity_bits, x_index_num_bits); evals = self.insert(low_x_index, e_x, evals); evaluations.push(evals); self.verify_merkle_proof( @@ -320,6 +322,7 @@ impl, const D: usize> CircuitBuilder { domain_size = next_domain_size; old_x_index = low_x_index; x_index = high_x_index; + x_index_num_bits -= arity_bits; } let last_evals = evaluations.last().unwrap(); diff --git a/src/gadgets/range_check.rs b/src/gadgets/range_check.rs index e711eadd..34f34496 100644 --- a/src/gadgets/range_check.rs +++ b/src/gadgets/range_check.rs @@ -15,9 +15,10 @@ impl, const D: usize> CircuitBuilder { } /// Returns `(a,b)` such that `x = a + 2^n_log * b` with `a < 2^n_log`. - pub fn split_low_high(&mut self, x: Target, n_log: usize) -> (Target, Target) { + /// `x` is assumed to be range-checked for having `num_bits` bits. + pub fn split_low_high(&mut self, x: Target, n_log: usize, num_bits: usize) -> (Target, Target) { let low_gate = self.add_gate(BaseSumGate::<2>::new(n_log), vec![]); - let high_gate = self.add_gate(BaseSumGate::<2>::new(64 - n_log), vec![]); + let high_gate = self.add_gate(BaseSumGate::<2>::new(num_bits - n_log), vec![]); let low = Target::wire(low_gate, BaseSumGate::<2>::WIRE_SUM); let high = Target::wire(high_gate, BaseSumGate::<2>::WIRE_SUM); self.add_generator(LowHighGenerator {