diff --git a/crates/prover/src/constraint_framework/logup.rs b/crates/prover/src/constraint_framework/logup.rs index 245162803..78ff90a43 100644 --- a/crates/prover/src/constraint_framework/logup.rs +++ b/crates/prover/src/constraint_framework/logup.rs @@ -18,6 +18,7 @@ use crate::core::fields::FieldExpOps; use crate::core::lookups::utils::Fraction; use crate::core::poly::circle::{CanonicCoset, CircleEvaluation}; use crate::core::poly::BitReversedOrder; +use crate::core::utils::bit_reverse_index; use crate::core::ColumnVec; /// Evaluates constraints for batched logups. @@ -202,12 +203,14 @@ impl LogupTraceGenerator { } } - /// Finalize the trace. Returns the trace and the claimed sum of the last column. - pub fn finalize( + /// Finalize the trace. Returns the trace and the prefix sum of the last column at + /// the corresponding `indices`. + pub fn finalize( mut self, + indices: [usize; N], ) -> ( ColumnVec>, - SecureField, + [SecureField; N], ) { // Prefix sum the last column. let last_col_coords = self.trace.pop().unwrap().columns; @@ -215,7 +218,12 @@ impl LogupTraceGenerator { let secure_prefix_sum = SecureColumnByCoords { columns: coord_prefix_sum, }; - let total_sum = secure_prefix_sum.at(1); + let returned_prefix_sums = indices.map(|idx| { + // Prefix sum column is in bit-reversed circle domain order. + let fixed_index = + bit_reverse_index(circle_domain_index(idx, self.log_size), self.log_size); + secure_prefix_sum.at(fixed_index) + }); self.trace.push(secure_prefix_sum); let trace = self @@ -230,7 +238,7 @@ impl LogupTraceGenerator { }) }) .collect_vec(); - (trace, total_sum) + (trace, returned_prefix_sums) } } @@ -281,6 +289,12 @@ impl<'a> LogupColGenerator<'a> { } } +/// Returns the index in the order of the circle_domain of size log_size. +fn circle_domain_index(index: usize, log_size: u32) -> usize { + let (shifted_index, last_bit) = (index >> 1, index & 1); + shifted_index ^ (((1 << (log_size - 1)) - 1) * last_bit) | (last_bit * (1 << (log_size - 1))) +} + #[cfg(test)] mod tests { use num_traits::One; diff --git a/crates/prover/src/examples/blake/round/gen.rs b/crates/prover/src/examples/blake/round/gen.rs index ba9933b99..ada8ed4ad 100644 --- a/crates/prover/src/examples/blake/round/gen.rs +++ b/crates/prover/src/examples/blake/round/gen.rs @@ -277,5 +277,6 @@ pub fn generate_interaction_trace( } col_gen.finalize_col(); - logup_gen.finalize() + let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]); + (trace, total_sum) } diff --git a/crates/prover/src/examples/blake/scheduler/gen.rs b/crates/prover/src/examples/blake/scheduler/gen.rs index 0581b2fe1..20fef91d8 100644 --- a/crates/prover/src/examples/blake/scheduler/gen.rs +++ b/crates/prover/src/examples/blake/scheduler/gen.rs @@ -167,5 +167,6 @@ pub fn gen_interaction_trace( } col_gen.finalize_col(); - logup_gen.finalize() + let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]); + (trace, total_sum) } diff --git a/crates/prover/src/examples/blake/xor_table/gen.rs b/crates/prover/src/examples/blake/xor_table/gen.rs index 59d3fd92d..f6d65e3a6 100644 --- a/crates/prover/src/examples/blake/xor_table/gen.rs +++ b/crates/prover/src/examples/blake/xor_table/gen.rs @@ -132,7 +132,9 @@ pub fn generate_interaction_trace( } } - logup_gen.finalize() + let (trace, [total_sum]) = + logup_gen.finalize([(1 << column_bits::()) - 1]); + (trace, total_sum) } /// Generates the constant trace for the xor table. diff --git a/crates/prover/src/examples/plonk/mod.rs b/crates/prover/src/examples/plonk/mod.rs index 07d7ce0cd..6eb9057c4 100644 --- a/crates/prover/src/examples/plonk/mod.rs +++ b/crates/prover/src/examples/plonk/mod.rs @@ -144,7 +144,8 @@ pub fn gen_interaction_trace( } col_gen.finalize_col(); - logup_gen.finalize() + let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]); + (trace, total_sum) } #[allow(unused)] diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index 0d9f811bd..0a0fa4c01 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -317,7 +317,8 @@ pub fn gen_interaction_trace( col_gen.finalize_col(); } - logup_gen.finalize() + let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]); + (trace, total_sum) } pub fn prove_poseidon(