Skip to content

Commit

Permalink
fixed bug; passes two bus case
Browse files Browse the repository at this point in the history
  • Loading branch information
qwang98 committed Feb 6, 2025
1 parent 6998967 commit 50ca1b1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions executor/src/witgen/bus_accumulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ impl<'a, T: FieldElement, Ext: ExtensionField<T> + Sync> BusAccumulatorGenerator
.bus_interactions
.par_iter()
.flat_map(|bus_interaction| {
let (folded, acc) = self.interaction_columns(bus_interaction);
let (folded, helper, acc) = self.interaction_columns(bus_interaction);
collect_folded_columns(bus_interaction, folded)
.chain(collect_acc_columns(bus_interaction, acc.clone()))
.chain(collect_helper_columns(bus_interaction, acc))
.chain(collect_helper_columns(bus_interaction, helper))
.chain(collect_acc_columns(bus_interaction, acc))
.collect::<Vec<_>>()
})
// Each thread builds its own BTreeMap.
Expand Down Expand Up @@ -184,17 +184,18 @@ impl<'a, T: FieldElement, Ext: ExtensionField<T> + Sync> BusAccumulatorGenerator
/// according to bus_multi_interaction_2.
///
/// Returns a triple:
/// - the folded columns (one per bus interaction),
/// - the accumulator column (shared by all interactions),
/// - one helper column per pair of bus interactions.
/// - the folded columns (one per bus interaction)
/// - one helper column per pair of bus interactions
/// - the accumulator column (shared by all interactions)
fn interaction_columns(
&self,
bus_interaction: &PhantomBusInteractionIdentity<T>,
) -> (Vec<Vec<T>>, Vec<Vec<T>>) {
) -> (Vec<Vec<T>>, Vec<Vec<T>>, Vec<Vec<T>>) {
let intermediate_definitions = self.pil.intermediate_definitions();

let size = self.values.height();
let mut folded_list = vec![Ext::zero(); size];
let mut helper_list = vec![Ext::zero(); size];
let mut acc_list = vec![Ext::zero(); size];

for i in 0..size {
Expand All @@ -214,28 +215,35 @@ impl<'a, T: FieldElement, Ext: ExtensionField<T> + Sync> BusAccumulatorGenerator
.collect::<Vec<_>>();
let folded = self.beta - self.fingerprint(&tuple);

let helper = folded.inverse() * multiplicity;

let new_acc = match multiplicity.is_zero() {
true => current_acc,
false => current_acc + folded.inverse() * multiplicity,
false => current_acc + helper,
};

folded_list[i] = folded;
helper_list[i] = helper;
acc_list[i] = new_acc;
}

// Transpose from row-major to column-major & flatten.
let mut folded = vec![Vec::with_capacity(size); Ext::size()];
let mut helper = vec![Vec::with_capacity(size); Ext::size()];
let mut acc = vec![Vec::with_capacity(size); Ext::size()];
for row_index in 0..size {
for (col_index, x) in folded_list[row_index].to_vec().into_iter().enumerate() {
folded[col_index].push(x);
}
for (col_index, x) in helper_list[row_index].to_vec().into_iter().enumerate() {
helper[col_index].push(x);
}
for (col_index, x) in acc_list[row_index].to_vec().into_iter().enumerate() {
acc[col_index].push(x);
}
}

(folded, acc)
(folded, helper, acc)
}

/// Fingerprints a tuples of field elements, using the pre-computed powers of alpha.
Expand Down Expand Up @@ -297,4 +305,4 @@ fn collect_helper_columns<T>(
.iter()
.zip_eq(helper)
.map(|(column_reference, column)| (column_reference.poly_id, column))
}
}

0 comments on commit 50ca1b1

Please sign in to comment.