Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTL's looking table grouping is wonky #1582

Open
matthiasgoergens opened this issue Apr 25, 2024 · 0 comments
Open

CTL's looking table grouping is wonky #1582

matthiasgoergens opened this issue Apr 25, 2024 · 0 comments

Comments

@matthiasgoergens
Copy link
Contributor

matthiasgoergens commented Apr 25, 2024

ctl_helper_zs_cols in starky/src/cross_table_lookup.rs looks like this:

/// Computes helper columns and Z polynomials for all looking tables
/// of one cross-table lookup (i.e. for one looked table).
fn ctl_helper_zs_cols<F: Field, const N: usize>(
    all_stark_traces: &[Vec<PolynomialValues<F>>; N],
    looking_tables: Vec<TableWithColumns<F>>,
    challenge: GrandProductChallenge<F>,
    constraint_degree: usize,
) -> Vec<(usize, Vec<PolynomialValues<F>>)> {
    let grouped_lookups = looking_tables.iter().group_by(|a| a.table);

    grouped_lookups
        .into_iter()
        .map(|(table, group)| {
            let columns_filters = group
                .map(|table| (&table.columns[..], &table.filter))
                .collect::<Vec<(&[Column<F>], &Filter<F>)>>();
            (
                table,
                partial_sums(
                    &all_stark_traces[table],
                    &columns_filters,
                    challenge,
                    constraint_degree,
                ),
            )
        })
        .collect::<Vec<(usize, Vec<PolynomialValues<F>>)>>()
}

The line let grouped_lookups = looking_tables.iter().group_by(|a| a.table); is rather questionable, because it only groups together looking tables that are already adjacent.

I suggest we replace it with something like this:

diff --git a/starky/src/cross_table_lookup.rs b/starky/src/cross_table_lookup.rs
index 73caf28c..dc662fcd 100644
--- a/starky/src/cross_table_lookup.rs
+++ b/starky/src/cross_table_lookup.rs
@@ -396,14 +396,14 @@ fn ctl_helper_zs_cols<F: Field, const N: usize>(
     challenge: GrandProductChallenge<F>,
     constraint_degree: usize,
 ) -> Vec<(usize, Vec<PolynomialValues<F>>)> {
-    let grouped_lookups = looking_tables.iter().group_by(|a| a.table);
-
-    grouped_lookups
+    looking_tables
+        .iter()
+        .map(|a| (a.table, (&a.columns[..], &a.filter)))
+        .into_group_map()
         .into_iter()
-        .map(|(table, group)| {
-            let columns_filters = group
-                .map(|table| (&table.columns[..], &table.filter))
-                .collect::<Vec<(&[Column<F>], &Filter<F>)>>();
+        // We sort for determinism:
+        .sorted_by_key(|(table, _)| *table)
+        .map(|(table, columns_filters)| {
             (
                 table,
                 partial_sums(

But I don't know which other parts of the code have to change. Perhaps something in the verifier, too?

Currently, we work around this problem in our client code by pre-sorting our looking tables before we hand them over to starky.

matthiasgoergens added a commit to 0xmozak/plonky2 that referenced this issue Apr 25, 2024
@Nashtare Nashtare added this to the Cleanups and Misc. milestone Jun 5, 2024
@Nashtare Nashtare modified the milestones: Misc., System strengthening Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants