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 PreprocessedColumn Structs #966

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Gali-StarkWare
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@Gali-StarkWare Gali-StarkWare marked this pull request as ready for review January 8, 2025 08:17
Copy link
Contributor Author

Gali-StarkWare commented Jan 8, 2025

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.

Project coverage is 92.13%. Comparing base (31e8dbc) to head (01a4251).

Files with missing lines Patch % Lines
...r/src/constraint_framework/preprocessed_columns.rs 0.00% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #966      +/-   ##
==========================================
- Coverage   92.26%   92.13%   -0.14%     
==========================================
  Files         105      105              
  Lines       14293    14314      +21     
  Branches    14293    14314      +21     
==========================================
  Hits        13188    13188              
- Misses       1032     1053      +21     
  Partials       73       73              

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

Copy link
Collaborator

@ohad-starkware ohad-starkware 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 1 files reviewed, 2 unresolved discussions (waiting on @Gali-StarkWare and @shaharsamocha7)


crates/prover/src/constraint_framework/preprocessed_columns.rs line 169 at r1 (raw file):

// TODO(Gali): Add documentation.
#[derive(Debug)]
pub struct Plonk {

can you not include this?


crates/prover/src/constraint_framework/preprocessed_columns.rs line 201 at r1 (raw file):

/// A column with `1` at every `2^log_step` positions, `0` elsewhere, shifted by offset.
#[derive(Debug)]
pub struct IsStepWithOffset {

same, if theyre not used, add a todo to implement them
I suspect no one will do those todos for a while, or ever.

Copy link
Contributor Author

@Gali-StarkWare Gali-StarkWare 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 1 files reviewed, 2 unresolved discussions (waiting on @ohad-starkware and @shaharsamocha7)


crates/prover/src/constraint_framework/preprocessed_columns.rs line 201 at r1 (raw file):

Previously, ohad-starkware (Ohad) wrote…

same, if theyre not used, add a todo to implement them
I suspect no one will do those todos for a while, or ever.

They are used in the examples (I guess this is the reason they exist in the first place), that's why I asked you if this is the right place for them, or maybe now is the time to move their declaration to be in the examples themselves.

@ohad-starkware
Copy link
Collaborator

crates/prover/src/constraint_framework/preprocessed_columns.rs line 201 at r1 (raw file):

Previously, Gali-StarkWare wrote…

They are used in the examples (I guess this is the reason they exist in the first place), that's why I asked you if this is the right place for them, or maybe now is the time to move their declaration to be in the examples themselves.

Right, I wrote a suggestion in #965 to rid of this

@Gali-StarkWare Gali-StarkWare force-pushed the gali/create_preprocessed_column_trait branch from 1bb5639 to 663fec9 Compare January 9, 2025 13:40
@Gali-StarkWare Gali-StarkWare force-pushed the gali/preprocessed_columns_structs branch 2 times, most recently from bc0097b to 6ba7258 Compare January 9, 2025 14:28
Comment on lines 26 to 34
unsafe {
PackedM31::from_simd_unchecked(Simd::from_array(std::array::from_fn(|i| {
if i == 0 {
1
} else {
0
}
})))
}
Copy link

@semgrep-code-starkware-libs semgrep-code-starkware-libs bot Jan 9, 2025

Choose a reason for hiding this comment

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

Detected 'unsafe' usage, please audit for secure usage

🎉 Removed in commit c58dc9d 🎉

Choose a reason for hiding this comment

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

Semgrep Assistant suggests the following fix: Ensure safe usage of PackedM31::from_simd_unchecked by verifying input validity or using a safe alternative.

View step-by-step instructions
  1. Review the PackedM31::from_simd_unchecked function to understand why it requires unsafe and what invariants must be upheld for safe usage.
  2. Check if there is a safe alternative to from_simd_unchecked that can be used instead. If such a function exists, replace PackedM31::from_simd_unchecked with the safe alternative.
  3. If no safe alternative exists, ensure that the input to from_simd_unchecked is always valid and does not violate any invariants required by the function. This may involve adding checks or assertions before the unsafe block to guarantee safety.
  4. Document the reason for using unsafe and the guarantees that are being upheld in a comment above the unsafe block. This will help future developers understand why unsafe is necessary and how it is being used safely.

This code change should be a good starting point:

Suggested change
unsafe {
PackedM31::from_simd_unchecked(Simd::from_array(std::array::from_fn(|i| {
if i == 0 {
1
} else {
0
}
})))
}
// Ensure that the input to `from_simd_unchecked` is valid.
// In this case, we are creating a SIMD vector with a specific pattern
// that is known to be safe for the `PackedM31` type.
// The use of `unsafe` is justified because we are controlling the input
// and ensuring it adheres to the expected invariants.
let simd_array = Simd::from_array(std::array::from_fn(|i| {
if i == 0 {
1
} else {
0
}
}));
PackedM31::from_simd(simd_array)

Leave feedback with a 👍 / 👎. Save a memory with /remember <your custom instructions>.

@Gali-StarkWare Gali-StarkWare force-pushed the gali/preprocessed_columns_structs branch from 6ba7258 to c58dc9d Compare January 9, 2025 14:48
@semgrep-code-starkware-libs
Copy link

Semgrep found 1 unsafe-usage finding:

  • crates/prover/src/constraint_framework/preprocessed_columns.rs

Detected 'unsafe' usage, please audit for secure usage

@Gali-StarkWare Gali-StarkWare force-pushed the gali/preprocessed_columns_structs branch from c58dc9d to 3428754 Compare January 12, 2025 08:53
@Gali-StarkWare Gali-StarkWare force-pushed the gali/create_preprocessed_column_trait branch from 663fec9 to c3740fe Compare January 12, 2025 08:55
@Gali-StarkWare Gali-StarkWare force-pushed the gali/preprocessed_columns_structs branch from 3428754 to 52a4b0a Compare January 12, 2025 08:55
Copy link
Contributor Author

@Gali-StarkWare Gali-StarkWare 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 10 files reviewed, 3 unresolved discussions (waiting on @ohad-starkware and @shaharsamocha7)


crates/prover/src/constraint_framework/preprocessed_columns.rs line 169 at r1 (raw file):

Previously, ohad-starkware (Ohad) wrote…

can you not include this?

Done.


crates/prover/src/constraint_framework/preprocessed_columns.rs line 201 at r1 (raw file):

Previously, ohad-starkware (Ohad) wrote…

Right, I wrote a suggestion in #965 to rid of this

Done.

Copy link
Collaborator

@ohad-starkware ohad-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 1 of 6 files at r3.
Reviewable status: 1 of 10 files reviewed, 2 unresolved discussions (waiting on @Gali-StarkWare and @shaharsamocha7)


crates/prover/src/examples/state_machine/mod.rs line 29 at r4 (raw file):

use crate::core::vcs::blake2_merkle::{Blake2sMerkleChannel, Blake2sMerkleHasher};

pub fn gen_is_first_columns(

why is this here? you're not using it
also, this should be inlined, it doesn't save code really.

Copy link
Contributor Author

@Gali-StarkWare Gali-StarkWare 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: 1 of 10 files reviewed, 2 unresolved discussions (waiting on @ohad-starkware and @shaharsamocha7)


crates/prover/src/examples/state_machine/mod.rs line 29 at r4 (raw file):

Previously, ohad-starkware (Ohad) wrote…

why is this here? you're not using it
also, this should be inlined, it doesn't save code really.

I will be using it instead of gen_preprocessed_columns. I will inline it.

@Gali-StarkWare Gali-StarkWare force-pushed the gali/create_preprocessed_column_trait branch from c3740fe to c7e7607 Compare January 12, 2025 10:06
@Gali-StarkWare Gali-StarkWare force-pushed the gali/preprocessed_columns_structs branch from 52a4b0a to ddb66cd Compare January 12, 2025 10:06
Copy link
Collaborator

@ohad-starkware ohad-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 9 files at r2, 2 of 6 files at r3, 1 of 2 files at r4, all commit messages.
Reviewable status: 6 of 10 files reviewed, 1 unresolved discussion (waiting on @Gali-StarkWare and @shaharsamocha7)

@Gali-StarkWare Gali-StarkWare force-pushed the gali/preprocessed_columns_structs branch from ddb66cd to 9def2ec Compare January 13, 2025 08:49
@Gali-StarkWare Gali-StarkWare changed the base branch from gali/create_preprocessed_column_trait to dev January 13, 2025 08:49
@Gali-StarkWare Gali-StarkWare changed the title Add Structs using PreprocessedColumn Trait Add PreprocessedColumn Structs Jan 13, 2025
Copy link
Collaborator

@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.

Reviewed 1 of 9 files at r2, 1 of 6 files at r3, 1 of 1 files at r5, 4 of 4 files at r6, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Gali-StarkWare)


crates/prover/src/examples/plonk/preprocessed_columns.rs line 14 at r6 (raw file):

        format!("preprocessed_plonk_{}", self.wire)
    }
}

I'm not sure this worth it's own file
You can add it to the regular plonk file and please document rather than add TODO

Code quote:

// TODO(Gali): Add documentation.
#[derive(Debug)]
pub struct Plonk {
    pub wire: usize,
}
impl Plonk {
    pub const fn new(wire: usize) -> Self {
        Self { wire }
    }

    pub fn id(&self) -> String {
        format!("preprocessed_plonk_{}", self.wire)
    }
}

crates/prover/src/examples/blake/preprocessed_columns.rs line 4 at r6 (raw file):

#[allow(dead_code)]
#[derive(Debug)]
pub struct XorTable {

Consider to move the XorTable generate_constant_trace to here

Code quote:

pub struct XorTable {

Copy link
Contributor Author

@Gali-StarkWare Gali-StarkWare 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: 7 of 10 files reviewed, 3 unresolved discussions (waiting on @ohad-starkware and @shaharsamocha7)


crates/prover/src/examples/blake/preprocessed_columns.rs line 4 at r6 (raw file):

Previously, shaharsamocha7 wrote…

Consider to move the XorTable generate_constant_trace to here

Done.


crates/prover/src/examples/plonk/preprocessed_columns.rs line 14 at r6 (raw file):

Previously, shaharsamocha7 wrote…

I'm not sure this worth it's own file
You can add it to the regular plonk file and please document rather than add TODO

Done.

Copy link
Collaborator

@ohad-starkware ohad-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:

Reviewable status: 7 of 10 files reviewed, 3 unresolved discussions (waiting on @Gali-StarkWare and @shaharsamocha7)

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.

5 participants