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

Logup generator returns multiple prefix sums #829

Merged

Conversation

shaharsamocha7
Copy link
Collaborator

@shaharsamocha7 shaharsamocha7 commented Sep 9, 2024

Logup generator finalize get a list of indices and returns the corresponding prefix sum


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.96%. Comparing base (75b94f9) to head (ee7ec83).
Report is 2 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #829      +/-   ##
==========================================
+ Coverage   91.95%   91.96%   +0.01%     
==========================================
  Files          90       90              
  Lines       12195    12211      +16     
  Branches    12195    12211      +16     
==========================================
+ Hits        11214    11230      +16     
  Misses        875      875              
  Partials      106      106              
Flag Coverage Δ
91.96% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from d50d61f to b3f754b Compare September 10, 2024 06:50
@shaharsamocha7 shaharsamocha7 force-pushed the 09-08-Logup_-_rename_claimed_sum_to_total_sum_Take_total_sum_from_cum_sum_column branch from 483abed to 4095bd6 Compare September 17, 2024 11:01
@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from b3f754b to 4c3990c Compare September 17, 2024 11:01
@shaharsamocha7 shaharsamocha7 force-pushed the 09-08-Logup_-_rename_claimed_sum_to_total_sum_Take_total_sum_from_cum_sum_column branch from 4095bd6 to f465a76 Compare September 17, 2024 12:29
@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from 4c3990c to 45206e8 Compare September 17, 2024 14:43
@shaharsamocha7 shaharsamocha7 marked this pull request as ready for review September 17, 2024 15:10
Copy link
Contributor

@Alon-Ti Alon-Ti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @andrewmilson and @shaharsamocha7)


crates/prover/src/examples/blake/round/gen.rs line 280 at r1 (raw file):

    col_gen.finalize_col();

    let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]);

Isn't it a little weird that you have to specify an index that in all "normal" cases translates to a constant index? Maybe there should be a finalize_last, or conversely finalize_at?

@shaharsamocha7 shaharsamocha7 force-pushed the 09-08-Logup_-_rename_claimed_sum_to_total_sum_Take_total_sum_from_cum_sum_column branch from f465a76 to ffa1666 Compare September 22, 2024 10:14
@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from 45206e8 to 4a63b70 Compare September 22, 2024 10:14
Copy link
Collaborator Author

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @Alon-Ti and @andrewmilson)


crates/prover/src/examples/blake/round/gen.rs line 280 at r1 (raw file):

Previously, Alon-Ti wrote…

Isn't it a little weird that you have to specify an index that in all "normal" cases translates to a constant index? Maybe there should be a finalize_last, or conversely finalize_at?

you suggest to rename finalize, to finalize_at()?
I think that there are more API functions that I want to rename here
e.g. next_interaction_mask(..) -> next_trace_column(..), WDYT?

Copy link
Contributor

@andrewmilson andrewmilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @Alon-Ti and @shaharsamocha7)


crates/prover/src/constraint_framework/logup.rs line 195 at r1 (raw file):

            .collect_vec();
        (trace, returned_prefix_sums)
    }

Agree with Alon.
Realise I already had this in Draft from a couple days ago but forgot to publish.

Suggestion:

    /// Returns the trace and the claimed sum of the last column.
    pub fn finalize_last(self) -> (
        ColumnVec<CircleEvaluation<SimdBackend, BaseField, BitReversedOrder>>,
        [SecureField; N],
    ) {
        let (trace, [cum_sum] = self.finalize_with_sum_at_indices(...);
        (trace, cum_sum)
    }
    
    /// Returns the trace and the prefix sum of the last column at the corresponding `indices`.
    pub fn finalize_at<const N: usize>(
        mut self,
        indices: [usize; N],
    ) -> (
        ColumnVec<CircleEvaluation<SimdBackend, BaseField, BitReversedOrder>>,
        [SecureField; N],
    ) {
        // Prefix sum the last column.
        let last_col_coords = self.trace.pop().unwrap().columns;
        let coord_prefix_sum = last_col_coords.map(inclusive_prefix_sum);
        let secure_prefix_sum = SecureColumnByCoords {
            columns: coord_prefix_sum,
        };
        let returned_prefix_sums = indices.map(|idx| {
            // Prefix sum column is in bit-reversed circle domain order.
            let fixed_index = bit_reverse_index(
                coset_index_to_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
            .trace
            .into_iter()
            .flat_map(|eval| {
                eval.columns.map(|c| {
                    CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), c)
                })
            })
            .collect_vec();
        (trace, returned_prefix_sums)
    }

Copy link
Collaborator Author

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @Alon-Ti and @andrewmilson)


crates/prover/src/constraint_framework/logup.rs line 195 at r1 (raw file):

Previously, andrewmilson (Andrew Milson) wrote…

Agree with Alon.
Realise I already had this in Draft from a couple days ago but forgot to publish.

Do you suggest to rename finalize -> finalize_at?
or adding more functions?

I think this can be done in another pr, WDYT?

Copy link
Contributor

@andrewmilson andrewmilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: with comment

Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @Alon-Ti and @shaharsamocha7)


crates/prover/src/constraint_framework/logup.rs line 195 at r1 (raw file):

Previously, shaharsamocha7 wrote…

Do you suggest to rename finalize -> finalize_at?
or adding more functions?

I think this can be done in another pr, WDYT?

Sounds good to me

I'm not so fussed about the names it just seems that

let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]);
(trace, total_sum)

will be a very common operation (will it be?) and seems nice to have a specific function for it

@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from 4a63b70 to 93e7e51 Compare September 24, 2024 07:34
Copy link
Contributor

@Alon-Ti Alon-Ti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 6 of 6 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @shaharsamocha7)


crates/prover/src/examples/blake/round/gen.rs line 280 at r1 (raw file):

Previously, shaharsamocha7 wrote…

you suggest to rename finalize, to finalize_at()?
I think that there are more API functions that I want to rename here
e.g. next_interaction_mask(..) -> next_trace_column(..), WDYT?

Agreed, I think mask isn't a word that should make it to the user.

Copy link
Collaborator Author

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @andrewmilson)


crates/prover/src/constraint_framework/logup.rs line 195 at r1 (raw file):

Previously, andrewmilson (Andrew Milson) wrote…

Sounds good to me

I'm not so fussed about the names it just seems that

let (trace, [total_sum]) = logup_gen.finalize([(1 << log_size) - 1]);
(trace, total_sum)

will be a very common operation (will it be?) and seems nice to have a specific function for it

Done.

@shaharsamocha7 shaharsamocha7 force-pushed the 09-08-Logup_-_rename_claimed_sum_to_total_sum_Take_total_sum_from_cum_sum_column branch 2 times, most recently from 1a0ef77 to 62932c1 Compare September 24, 2024 11:21
@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from 93e7e51 to c011bab Compare September 24, 2024 11:21
@shaharsamocha7 shaharsamocha7 changed the base branch from 09-08-Logup_-_rename_claimed_sum_to_total_sum_Take_total_sum_from_cum_sum_column to graphite-base/829 September 24, 2024 11:31
@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from c011bab to 51bde84 Compare September 24, 2024 11:31
@shaharsamocha7 shaharsamocha7 changed the base branch from graphite-base/829 to dev September 24, 2024 11:32
@shaharsamocha7 shaharsamocha7 force-pushed the 09-09-Logup_generator_returns_multiple_prefix_sums branch from 51bde84 to ee7ec83 Compare September 24, 2024 11:32
@shaharsamocha7 shaharsamocha7 merged commit fd39544 into dev Sep 24, 2024
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants