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

Add FRI layer 0 commitment #186

Merged
merged 1 commit into from
Dec 2, 2024
Merged

Conversation

andrewmilson
Copy link
Contributor

@andrewmilson andrewmilson commented Nov 20, 2024

This change is Reviewable

@andrewmilson andrewmilson changed the title Add FRI layer 0 commitment Add FRI layer 0 commitment (WIP) Nov 20, 2024
@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch from 50a3450 to cdce69c Compare November 20, 2024 03:34
@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/pcs/quotients.cairo line 30 at r1 (raw file):

    mut query_positions_per_log_size: Felt252Dict<Nullable<Span<usize>>>,
    queried_values_per_column: @Array<Array<M31>>,
    mut missing_values: Span<QM31>,

Please document the arguments.

Code quote:

    log_size_per_column: @Array<u32>,
    samples_per_column: @Array<Array<PointSample>>,
    random_coeff: QM31,
    mut query_positions_per_log_size: Felt252Dict<Nullable<Span<usize>>>,
    queried_values_per_column: @Array<Array<M31>>,
    mut missing_values: Span<QM31>,

@andrewmilson andrewmilson force-pushed the 11-19-Replace_with branch 2 times, most recently from dcb2a6d to 460e403 Compare November 21, 2024 14:31
Base automatically changed from 11-19-Replace_with to main November 21, 2024 14:34
@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch 9 times, most recently from b4f7132 to fcb1a9d Compare November 26, 2024 04:01
@andrewmilson andrewmilson changed the title Add FRI layer 0 commitment (WIP) Add FRI layer 0 commitment Nov 26, 2024
@andrewmilson andrewmilson marked this pull request as ready for review November 26, 2024 04:02
@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch from fcb1a9d to 9d381d8 Compare November 26, 2024 04:09
Copy link
Contributor Author

@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: 0 of 29 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @shaharsamocha7)


stwo_cairo_verifier/src/pcs/quotients.cairo line 30 at r1 (raw file):

Previously, ilyalesokhin-starkware wrote…

Please document the arguments.

Done.


stwo_cairo_verifier/src/utils.cairo line 14 at r3 (raw file):

/// Look up table where index `i` stores value `2^i`.
const POW_2: [u32; 32] = [
    0b1, // 

Formatter in new version wants to squash multiple into the same line. The empty comment stops that from happening

@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch from 9d381d8 to f8bd423 Compare November 26, 2024 04:13
@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/queries.cairo line 47 at r5 (raw file):

    fn len(self: @Queries) -> usize {
        (*self.positions).len()

doesn't span have len?

Suggestion:

 self.positions.len()

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/queries.cairo line 55 at r5 (raw file):

        Queries {
            positions: get_folded_query_positions(self.positions, n_folds),
            // TODO(andrew): Check Cairo does checked sub in all profiles.

it does, sierra is type safe.

only felt252 can overflow.

Code quote:

 // TODO(andrew): Check Cairo does checked sub in all profiles.

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/queries.cairo line 75 at r5 (raw file):

    for position in query_positions {
        folded_positions.append(*position / folding_factor);
    };

Consider deduping inside this loop.

Suggestion:

    for position in query_positions {
        new_position = *position / folding_factor;
        if new_position != prev_position
            folded_positions.append(*position / folding_factor);
        prev_position = new_position.
    };

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/utils.cairo line 166 at r5 (raw file):

    fn first(mut self: Span<T>) -> Option<@T> {
        self.pop_front()
    }

Does this work?

Suggestion:

    fn first(self: @Span<T>) -> Option<@T> {
        *self.pop_front()
    }

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/utils.cairo line 184 at r5 (raw file):

            if value == other {
                self = self_copy;
                return Option::Some(other);

nice!

Code quote:

                self = self_copy;
                return Option::Some(other);

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/pcs/quotients.cairo line 242 at r5 (raw file):

/// * `sampled_batches`: OOD column samples grouped by eval point.
/// * `queried_values_by_column`: Sampled query evals by trace column.
/// * `row`: The index of the query to compute the quotients for.

Suggestion:

/// * `query_idx`: The index of the query to compute the quotients for

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/pcs/quotients.cairo line 262 at r5 (raw file):

    let mut row_accumulator: QM31 = Zero::zero();

    for batch_i in 0..n_batches {

You have 4 loops here.

I'd consider refactoring it in the future as

  1. compute an array if (numerator, denumerator)
  2. batch_inverse + row_accumulator.

you can add a todo.

Code quote:

  for batch_i in 0..n_batches {

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/vcs/verifier.cairo line 300 at r5 (raw file):

    use core::nullable::NullableTrait;
    use core::result::ResultTrait;
    use stwo_cairo_verifier::fields::m31::m31;

revert

Code quote:

  use stwo_cairo_verifier::fields::m31::m31;

Copy link
Collaborator

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 13 files at r1, 4 of 17 files at r3, 9 of 24 files at r5, all commit messages.
Reviewable status: 13 of 29 files reviewed, 7 unresolved discussions (waiting on @andrewmilson and @shaharsamocha7)

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/pcs/quotients.cairo line 38 at r5 (raw file):

    // Group columns by log size.
    // TODO(andrew): Refactor. Use a dict.

If the columns are stored by size is the dict still nessiary?

Code quote:

 // TODO(andrew): Refactor. Use a dict.

@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch 2 times, most recently from 48a7536 to 8ef16b2 Compare November 26, 2024 19:20
Copy link
Contributor Author

@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: 13 of 29 files reviewed, 7 unresolved discussions (waiting on @ilyalesokhin-starkware and @shaharsamocha7)


stwo_cairo_verifier/src/queries.cairo line 47 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

doesn't span have len?

Span does but @Span doesn't


stwo_cairo_verifier/src/queries.cairo line 55 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

it does, sierra is type safe.

only felt252 can overflow.

Great. Removed


stwo_cairo_verifier/src/queries.cairo line 75 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

Consider deduping inside this loop.

Done.


stwo_cairo_verifier/src/utils.cairo line 166 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

Does this work?

Complains "ref argument must be a variable".
It's possible with

    fn first(self: @Span<T>) -> Option<@T> {
        let mut self_copy = *self;
        self_copy.pop_front()
    }

but leaving as is seems more consistent with the other Span impls like .len() being implemented on Span not @Span. WDYT?


stwo_cairo_verifier/src/pcs/quotients.cairo line 38 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

If the columns are stored by size is the dict still nessiary?

Ahh nice. True


stwo_cairo_verifier/src/pcs/quotients.cairo line 262 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

You have 4 loops here.

I'd consider refactoring it in the future as

  1. compute an array if (numerator, denumerator)
  2. batch_inverse + row_accumulator.

you can add a todo.

Discussed offline.


stwo_cairo_verifier/src/vcs/verifier.cairo line 300 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

revert

Done.


stwo_cairo_verifier/src/pcs/quotients.cairo line 242 at r5 (raw file):

/// * `sampled_batches`: OOD column samples grouped by eval point.
/// * `queried_values_by_column`: Sampled query evals by trace column.
/// * `row`: The index of the query to compute the quotients for.

Done.

@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch from 8ef16b2 to 2d874fc Compare November 26, 2024 21:02
@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/src/utils.cairo line 166 at r5 (raw file):

Previously, andrewmilson (Andrew Milson) wrote…

Complains "ref argument must be a variable".
It's possible with

    fn first(self: @Span<T>) -> Option<@T> {
        let mut self_copy = *self;
        self_copy.pop_front()
    }

but leaving as is seems more consistent with the other Span impls like .len() being implemented on Span not @Span. WDYT?

I find it strange that you must consume the span to get the first element.

Maybe:

fn first(self: @span) -> Option<@t> {
self.iter().next()
}

@ilyalesokhin-starkware
Copy link
Collaborator

stwo_cairo_verifier/tests/verifier.cairo line 20 at r6 (raw file):

//     let test_proof = proofs::test_proof::proof();
//     println!("TEST PROOF WORKED");
// }

?

Code quote:

// #[test]
// fn test_deserialise() {
//     let test_proof = proofs::test_proof::proof();
//     println!("TEST PROOF WORKED");
// }

Copy link
Collaborator

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 11 of 24 files at r5, 6 of 6 files at r6.
Reviewable status: 27 of 29 files reviewed, 2 unresolved discussions (waiting on @andrewmilson, @shaharsamocha7, @span, and @t)

Copy link
Contributor Author

@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: 26 of 29 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware, @shaharsamocha7, @span, and @t)


stwo_cairo_verifier/src/utils.cairo line 166 at r5 (raw file):

Previously, ilyalesokhin-starkware wrote…

I find it strange that you must consume the span to get the first element.

Maybe:

fn first(self: @span) -> Option<@t> {
self.iter().next()
}

No iter. Only into_iter() which is also implemented on Span


stwo_cairo_verifier/tests/verifier.cairo line 20 at r6 (raw file):

Previously, ilyalesokhin-starkware wrote…

?

Done.

Copy link
Collaborator

@ilyalesokhin-starkware ilyalesokhin-starkware 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 2 of 24 files at r5, 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @shaharsamocha7)

@andrewmilson andrewmilson force-pushed the 11-19-Add_FRI_layer_0_commitment branch from 1cd7436 to d7ed8f9 Compare December 2, 2024 13:35
@andrewmilson andrewmilson merged commit 3d4d77c into main Dec 2, 2024
5 of 6 checks passed
@andrewmilson andrewmilson deleted the 11-19-Add_FRI_layer_0_commitment branch December 2, 2024 13:40
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.

2 participants