Skip to content

feat(starknet_os): inline ark_poly bit_reversal algorithm #5110

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

Conversation

dorimedini-starkware
Copy link
Collaborator

feat(starknet_os): inline ark_poly bit_reversal algorithm

feat(starknet_os): refactor bit_reversal for our needs

Signed-off-by: Dori Medini dori@starkware.co

@reviewable-StarkWare
Copy link

This change is Reviewable

@dorimedini-starkware dorimedini-starkware self-assigned this Mar 20, 2025
@dorimedini-starkware dorimedini-starkware force-pushed the 03-17-test_starknet_os_fft_regression branch from 7d8c3a5 to d8a5f6a Compare March 20, 2025 10:28
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from cbc6c81 to a16f05d Compare March 20, 2025 10:28
@dorimedini-starkware dorimedini-starkware force-pushed the 03-17-test_starknet_os_fft_regression branch from d8a5f6a to fcbd745 Compare March 20, 2025 10:35
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from a16f05d to 8c5b064 Compare March 20, 2025 10:35
@dorimedini-starkware dorimedini-starkware force-pushed the 03-17-test_starknet_os_fft_regression branch from fcbd745 to 2b1cb0f Compare March 20, 2025 11:39
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from 8c5b064 to 1d067ea Compare March 20, 2025 11:39
@dorimedini-starkware dorimedini-starkware force-pushed the 03-17-test_starknet_os_fft_regression branch from 2b1cb0f to f9a03bd Compare March 20, 2025 14:49
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from 1d067ea to 8bde8f3 Compare March 20, 2025 14:50
@dorimedini-starkware dorimedini-starkware force-pushed the 03-17-test_starknet_os_fft_regression branch from f9a03bd to f95f6e8 Compare March 23, 2025 09:38
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from 8bde8f3 to 92bfdda Compare March 23, 2025 09:38
@dorimedini-starkware dorimedini-starkware force-pushed the 03-17-test_starknet_os_fft_regression branch from f95f6e8 to 9138d42 Compare March 23, 2025 11:14
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch 2 times, most recently from 0c38e02 to 173019e Compare March 23, 2025 15:57
@dorimedini-starkware dorimedini-starkware changed the base branch from 03-17-test_starknet_os_fft_regression to main March 23, 2025 15:57
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from 173019e to 84d251f Compare March 23, 2025 16:29
@aner-starkware
Copy link
Contributor

crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 176 at r6 (raw file):

        }
        r
    }

What's going on here? (I mean, bit manipulation is hard to follow, so maybe consider an explanation\reference on why it works?)

Code quote:

    fn bitreverse(mut n: usize) -> usize {
        let mut r = 0;
        for _ in 0..WIDTH {
            r = (r << 1) | (n & 1);
            n >>= 1;
        }
        r
    }

Copy link
Contributor

@aner-starkware aner-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 3 files at r1, 1 of 2 files at r3, 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @Yoni-Starkware)

@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from 84d251f to 2303ab8 Compare March 24, 2025 14:01
Copy link
Contributor

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


crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 169 at r8 (raw file):

    }

    /// Reverses the bits of `n`, assuming it has a width (in bits) of `WIDTH`.

Maybe?

Suggestion:

; assumes `n` is at most `WIDTH` bits.

crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 184 at r8 (raw file):

        // As bitreverse(bitreverse(i)) = i, by swapping only when i < reversed_i we avoid swapping
        // the same element twice. When the loop terminates, each index will have swapped locations
        // with it's reversed, as required.

It's a bit verbose; consider shortening.

Code quote:

        // As bitreverse(bitreverse(i)) = i, by swapping only when i < reversed_i we avoid swapping
        // the same element twice. When the loop terminates, each index will have swapped locations
        // with it's reversed, as required.

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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, 1 unresolved discussion (waiting on @aner-starkware and @Yoni-Starkware)


crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 169 at r8 (raw file):

Previously, aner-starkware wrote…

Maybe?

no, this is not an upper bound; if n=7 then bitreverse(n, 3) == 7 but bitreverse(n, 4) == 14. n can be "smaller than the width".


crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 184 at r8 (raw file):

Previously, aner-starkware wrote…

It's a bit verbose; consider shortening.

what would you suggest?

Copy link
Contributor

@aner-starkware aner-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, 1 unresolved discussion (waiting on @dorimedini-starkware and @Yoni-Starkware)


crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 169 at r8 (raw file):

Previously, dorimedini-starkware wrote…

no, this is not an upper bound; if n=7 then bitreverse(n, 3) == 7 but bitreverse(n, 4) == 14. n can be "smaller than the width".

Ah, right, so maybe "where n is represented by WIDTH bits". Is WIDTH the best name, btw?


crates/starknet_os/src/hints/hint_implementation/kzg/utils.rs line 184 at r8 (raw file):

Previously, dorimedini-starkware wrote…

what would you suggest?

Maybe "Applies the bit-reversal permutation on all elements. Swaps only when i < reversed_i to avoid swapping the same element twice."

Copy link
Contributor

@aner-starkware aner-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, 1 unresolved discussion (waiting on @dorimedini-starkware and @Yoni-Starkware)

* feat(starknet_os): copy get_deprecated_contract_class_struct from moonsong's repo

* feat(starknet_os): implement LoadCairoObject trait for DeprecatedContractClass

* feat(starknet_os): copy load_deprecated_class_inner hint implementation from moonsong's repo

* feat(starknet_os): implement load deprecated class inner hint
@dorimedini-starkware dorimedini-starkware force-pushed the 03-20-feat_starknet_os_inline_ark_poly_bit_reversal_algorithm branch from 2303ab8 to dabe98d Compare March 25, 2025 09:49
Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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: 2 of 4 files reviewed, all discussions resolved (waiting on @aner-starkware and @Yoni-Starkware)


config/sequencer/presets/consolidated_node/application_configs/node.json line 306 at r9 (raw file):

  "versioned_constants_overrides.max_recursion_depth": 50,
  "versioned_constants_overrides.validate_max_n_steps": 1000000
}

I have no idea why the latest gt sync cause so many conflicts, but this JSON was missing a trailing newline... unrelated to my PR but no damage

Copy link
Contributor

@aner-starkware aner-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 2 files at r9.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @Yoni-Starkware)


-- commits line 10 at r9:
What's this?

Code quote:

New commits in r9 on 3/25/2025 at 11:48 AM by rotem-starkware:
- dabe98d: feat(starknet_os): implement load deprecated class inner hint (#5108)

  * feat(starknet_os): copy get_deprecated_contract_class_struct from moonsong's repo

  * feat(starknet_os): implement LoadCairoObject trait for DeprecatedContractClass

  * feat(starknet_os): copy load_deprecated_class_inner hint implementation from moonsong's repo

  * feat(starknet_os): implement load deprecated class inner hint

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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 (commit messages unreviewed), 1 unresolved discussion (waiting on @aner-starkware and @Yoni-Starkware)


-- commits line 10 at r9:

Previously, aner-starkware wrote…

What's this?

gt sync issue... commits will be squashed anyway, as long as the diff is fine it's fine.
not sure what happened here

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-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 (commit messages unreviewed), 1 unresolved discussion (waiting on @aner-starkware and @Yoni-Starkware)


-- commits line 10 at r9:

Previously, dorimedini-starkware wrote…

gt sync issue... commits will be squashed anyway, as long as the diff is fine it's fine.
not sure what happened here

the commit message will be the PR title

Copy link
Contributor

@aner-starkware aner-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 all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Yoni-Starkware)

@dorimedini-starkware dorimedini-starkware added this pull request to the merge queue Mar 25, 2025
Merged via the queue into main with commit 4e60d20 Mar 25, 2025
16 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants