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

Verify Bitwise Xor 9 Files #401

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

Conversation

Gali-StarkWare
Copy link
Contributor

@Gali-StarkWare Gali-StarkWare commented Jan 28, 2025

This change is Reviewable

Copy link
Contributor Author

Gali-StarkWare commented Jan 28, 2025

@Gali-StarkWare Gali-StarkWare requested review from ohad-starkware and removed request for andrewmilson and alon-f January 28, 2025 15:50
@Gali-StarkWare Gali-StarkWare self-assigned this Jan 28, 2025
@Gali-StarkWare Gali-StarkWare marked this pull request as ready for review January 28, 2025 15:51
Copy link
Contributor

@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 5 of 6 files at r1, all commit messages.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions (waiting on @Gali-StarkWare and @shaharsamocha7)


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

fn write_trace_simd(
    log_size: u32,
    mults: AtomicMultiplicityColumn,

isnt log_size encoded in mults?
also, if you call into_simd_vec right away, it should be called from the outside, and write_trace_simd does not need to be aware of MultiPlicityColumn. this is because you might want to use a different struct for mults, and this coupling has no benefit.

Code quote:

    log_size: u32,
    mults: AtomicMultiplicityColumn,

stwo_cairo_prover/crates/prover/src/components/utils.rs line 54 at r1 (raw file):

}

#[derive(Default)]

why? this sound wrong to me

@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from e5e2a1d to 457af27 Compare January 29, 2025 13:17
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from acdb174 to d11a26e Compare January 29, 2025 13:17
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from 457af27 to dae840e Compare January 30, 2025 09:11
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from d11a26e to 21eafba Compare January 30, 2025 09:11
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from dae840e to 9ab859a Compare January 30, 2025 09:14
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from 21eafba to 4b316ee Compare January 30, 2025 09:14
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from 9ab859a to de35583 Compare January 30, 2025 09:30
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch 2 times, most recently from 627fd48 to ef7bf43 Compare January 30, 2025 09:33
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from de35583 to d5ed1d2 Compare January 30, 2025 11:42
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from ef7bf43 to d93a74b Compare January 30, 2025 11:42
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from d5ed1d2 to 86eb415 Compare January 30, 2025 12:11
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from d93a74b to c60af88 Compare January 30, 2025 12:11
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from 86eb415 to 7d5fdcf Compare January 30, 2025 12:19
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from c60af88 to 6c994d2 Compare January 30, 2025 12:20
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from 52396ae to c6b9dc6 Compare January 30, 2025 14:34
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from 25cf96b to 21b338f Compare January 30, 2025 14:43
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from c6b9dc6 to 04b22cf Compare January 30, 2025 14:43
Copy link
Contributor

@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 3 of 5 files at r3, all commit messages.
Reviewable status: 4 of 6 files reviewed, 8 unresolved discussions (waiting on @Gali-StarkWare and @ohad-starkware)


stwo_cairo_prover/crates/prover/src/components/utils.rs line 54 at r1 (raw file):

Previously, ohad-starkware (Ohad) wrote…

why? this sound wrong to me

agree


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/component.rs line 70 at r3 (raw file):

    #[allow(unused_parens)]
    #[allow(clippy::double_parens)]
    #[allow(non_snake_case)]

Are those needed?

Code quote:

    #[allow(unused_parens)]
    #[allow(clippy::double_parens)]
    #[allow(non_snake_case)]

stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/component.rs line 72 at r3 (raw file):

    #[allow(non_snake_case)]
    fn evaluate<E: EvalAtRow>(&self, mut eval: E) -> E {
        let BitwiseXor0 = eval

Suggestion change to good rust names

Suggestion:

let xor_a = eval

stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/component.rs line 73 at r3 (raw file):

    fn evaluate<E: EvalAtRow>(&self, mut eval: E) -> E {
        let BitwiseXor0 = eval
            .get_preprocessed_column(PreProcessedColumn::BitwiseXor(BitwiseXor::new(9, 0)).id());

consider to move to a constant

Suggestion:

        let BitwiseXor0 = eval
            .get_preprocessed_column(PreProcessedColumn::BitwiseXor(BitwiseXor::new(N_BITS, 0)).id());

stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 42 at r3 (raw file):

pub type InputType = [M31; 3];
pub type PackedInputType = [PackedM31; 3];
const N_BITS: u32 = 9;

Move this constant to component.rs

Code quote:

const N_BITS: u32 = 9;

stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 44 at r3 (raw file):

const N_BITS: u32 = 9;
const N_TRACE_COLUMNS: usize = 1;
const LOG_SIZE: u32 = 18;

Suggestion:

const LOG_SIZE: u32 = N_BITS * 2;

stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 68 at r3 (raw file):

        let log_size = self.log_size;
        let (trace, lookup_data) = write_trace_simd(log_size, self.mults);

remove empty line

@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from 21b338f to cb12a09 Compare January 30, 2025 15:13
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch 2 times, most recently from 001bb3d to 1ea108e Compare January 30, 2025 15:18
@Gali-StarkWare Gali-StarkWare force-pushed the gali/add_xor_to_preprocessed branch from cb12a09 to af0097b Compare January 30, 2025 15:23
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from 1ea108e to 4a58380 Compare January 30, 2025 15:23
@Gali-StarkWare Gali-StarkWare changed the base branch from gali/add_xor_to_preprocessed to graphite-base/401 January 30, 2025 17:47
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from 4a58380 to f85078f Compare January 30, 2025 17:47
@Gali-StarkWare Gali-StarkWare changed the base branch from graphite-base/401 to main January 30, 2025 17:47
@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from f85078f to 0221d56 Compare January 30, 2025 17:47
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: 3 of 6 files reviewed, 8 unresolved discussions (waiting on @Gali-StarkWare, @ohad-starkware, and @shaharsamocha7)


stwo_cairo_prover/crates/prover/src/components/utils.rs line 54 at r1 (raw file):

Previously, shaharsamocha7 wrote…

agree

Because of the derive default of ClaimGenerator (it's created using just LOG_SIZE). I can put #[allow(clippy::new_without_default)] on this ClaimGenerator instead.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/component.rs line 70 at r3 (raw file):

Previously, shaharsamocha7 wrote…

Are those needed?

Not after the renaming you suggested, removed them.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/component.rs line 72 at r3 (raw file):

Previously, shaharsamocha7 wrote…

Suggestion change to good rust names

Done.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/component.rs line 73 at r3 (raw file):

Previously, shaharsamocha7 wrote…

consider to move to a constant

Done.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

Previously, ohad-starkware (Ohad) wrote…

isnt log_size encoded in mults?
also, if you call into_simd_vec right away, it should be called from the outside, and write_trace_simd does not need to be aware of MultiPlicityColumn. this is because you might want to use a different struct for mults, and this coupling has no benefit.

  1. Yes, but there is no len method on the multiplicity column and data is private.
  2. Done.

stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 42 at r3 (raw file):

Previously, shaharsamocha7 wrote…

Move this constant to component.rs

Done.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 68 at r3 (raw file):

Previously, shaharsamocha7 wrote…

remove empty line

Done.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 44 at r3 (raw file):

const N_BITS: u32 = 9;
const N_TRACE_COLUMNS: usize = 1;
const LOG_SIZE: u32 = 18;

Done.

@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from 0221d56 to 2101ebe Compare February 2, 2025 08:28
Copy link
Contributor

@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 3 of 3 files at r5, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Gali-StarkWare and @ohad-starkware)


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

Previously, Gali-StarkWare wrote…
  1. Yes, but there is no len method on the multiplicity column and data is private.
  2. Done.

now that it is Vec you do have the log_size, consider to remove


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 109 at r5 (raw file):

            *lookup_data.verify_bitwise_xor_9_0 = [
                BitwiseXor::new(9, 0).packed_at(row_index),

N_BITS

Code quote:

9

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


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

Previously, shaharsamocha7 wrote…

now that it is Vec you do have the log_size, consider to remove

Done.


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 109 at r5 (raw file):

Previously, shaharsamocha7 wrote…

N_BITS

Oops, done.

Copy link
Contributor

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

:lgtm:

Reviewed 1 of 6 files at r1, 1 of 1 files at r6, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ohad-starkware)


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

Previously, Gali-StarkWare wrote…

Done.

IIUC, ohad suggested to remove log_size as parameter.
Does it mean you considered and decided to keep it?

@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from de8bc67 to 85d98e3 Compare February 2, 2025 12:30
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: all files reviewed, 2 unresolved discussions (waiting on @ohad-starkware)


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

Previously, shaharsamocha7 wrote…

IIUC, ohad suggested to remove log_size as parameter.
Does it mean you considered and decided to keep it?

I removed it as an attribute from ClaimGenerator, and then calculated it in write_trace function. I changed it so it would be calculated in write_trace_simd as well, but IMO it's code duplication.

@Gali-StarkWare Gali-StarkWare force-pushed the gali/verify_bitwise_xor branch from 85d98e3 to 0133b80 Compare February 2, 2025 12:42
Copy link
Contributor

@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 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ohad-starkware)

Copy link
Contributor

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


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 93 at r1 (raw file):

Previously, Gali-StarkWare wrote…

I removed it as an attribute from ClaimGenerator, and then calculated it in write_trace function. I changed it so it would be calculated in write_trace_simd as well, but IMO it's code duplication.

you already have LOG_SIZE as a const


stwo_cairo_prover/crates/prover/src/components/utils.rs line 54 at r1 (raw file):

Previously, Gali-StarkWare wrote…

Because of the derive default of ClaimGenerator (it's created using just LOG_SIZE). I can put #[allow(clippy::new_without_default)] on this ClaimGenerator instead.

yes that is better, and I think the lint is incorrect here (so the allow is fine)


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 64 at r7 (raw file):

    {
        let mults = self.mults.into_simd_vec();
        let log_size = mults.len().ilog2();

you already have LOG_SIZE as a const


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 89 at r7 (raw file):

fn write_trace_simd(mults: Vec<PackedM31>) -> (ComponentTrace<N_TRACE_COLUMNS>, LookupData) {
    let log_size = mults.len().ilog2();

same


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 106 at r7 (raw file):

            *lookup_data.verify_bitwise_xor_9_0 = [
                BitwiseXor::new(N_BITS, 0).packed_at(row_index),

unrelated to this pr -
calling new in a loop is weird IMO, even though it is probably optimized out.
what happens when the struct is complex? and the new function carries some logic that cant be optimized out?

Copy link
Contributor

@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, 3 unresolved discussions (waiting on @Gali-StarkWare)


stwo_cairo_prover/crates/prover/src/components/verify_bitwise_xor_9/prover.rs line 106 at r7 (raw file):

Previously, ohad-starkware (Ohad) wrote…

unrelated to this pr -
calling new in a loop is weird IMO, even though it is probably optimized out.
what happens when the struct is complex? and the new function carries some logic that cant be optimized out?

agree that BitwiseXor::new(N_BITS, i) should be called outside of the loop

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.

3 participants