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

chore(blockifier): create func keccak_base to delete code duplication #2198

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

avivg-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

Artifacts upload triggered. View details here

@avivg-starkware avivg-starkware marked this pull request as ready for review November 20, 2024 14:52
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 84.78261% with 7 lines in your changes missing coverage. Please review.

Project coverage is 68.91%. Comparing base (e3165c4) to head (ff30a90).
Report is 610 commits behind head on main.

Files with missing lines Patch % Lines
.../blockifier/src/execution/syscalls/syscall_base.rs 87.17% 4 Missing and 1 partial ⚠️
crates/blockifier/src/execution/syscalls/mod.rs 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2198       +/-   ##
===========================================
+ Coverage   40.10%   68.91%   +28.81%     
===========================================
  Files          26      108       +82     
  Lines        1895    13982    +12087     
  Branches     1895    13982    +12087     
===========================================
+ Hits          760     9636     +8876     
- Misses       1100     3934     +2834     
- Partials       35      412      +377     

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

Copy link
Collaborator

@Yoni-Starkware Yoni-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 3 files reviewed, 1 unresolved discussion (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)


crates/blockifier/src/execution/syscalls/mod.rs line 666 at r1 (raw file):

    let gas_cost = n_rounds_as_u64 * syscall_handler.context.gas_costs().keccak_round_cost_gas_cost;
    if gas_cost > *remaining_gas {
        let out_of_gas_error =

Try to share this code as well (in the same base func)

Code quote:

    let mut state = [0u64; 25];
    for chunk in data.chunks(KECCAK_FULL_RATE_IN_WORDS) {
        for (i, val) in chunk.iter().enumerate() {
            state[i] ^= val.to_u64().ok_or_else(|| SyscallExecutionError::InvalidSyscallInput {
                input: **val,
                info: String::from("Invalid input for the keccak syscall."),
            })?;
        }
        keccak::f1600(&mut state)
    }

Copy link
Collaborator

@Yoni-Starkware Yoni-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 3 files reviewed, 2 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)


crates/blockifier/src/execution/native/syscall_handler.rs line 578 at r1 (raw file):

        match syscall_base::keccak_base(self.context, input_length, remaining_gas) {
            Ok(_) => (),
            Err(e) => return Err(self.handle_error(remaining_gas, e.into())),

Can be done in one line?

Code quote:

            Ok(_) => (),
            Err(e) => return Err(self.handle_error(remaining_gas, e.into())),

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/create_keccak_base branch from b808867 to 4e9a816 Compare November 27, 2024 12:10
Copy link

github-actions bot commented Nov 27, 2024

Copy link
Contributor Author

@avivg-starkware avivg-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 3 files reviewed, 2 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @Yoni-Starkware)


crates/blockifier/src/execution/native/syscall_handler.rs line 578 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Can be done in one line?

changed according to other changes. WDYT?


crates/blockifier/src/execution/syscalls/mod.rs line 666 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Try to share this code as well (in the same base func)

I moved the conversion logic to be made before hand. please tell me if this implementation looks OK to you. thanks

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/create_keccak_base branch from 4e9a816 to b6f7a00 Compare November 27, 2024 12:42
Copy link
Collaborator

@Yoni-Starkware Yoni-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: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)


crates/blockifier/src/execution/syscalls/syscall_base.rs line 217 at r3 (raw file):

        &mut self,
        input: &[u64],
        input_length: usize,

No need to pass the length - take it from the array.

Copy link
Collaborator

@Yoni-Starkware Yoni-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 3 files reviewed, 3 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)


crates/blockifier/src/execution/syscalls/syscall_base.rs line 214 at r3 (raw file):

    }

    pub fn keccak_base(

Rename and move it above finalize

Suggestion:

    pub fn finalize(&mut self) {
        self.context
            .revert_infos
            .0
            .last_mut()
            .expect("Missing contract revert info.")
            .original_values = std::mem::take(&mut self.original_values);
    }

    pub fn keccak(

Copy link
Contributor

@meship-starkware meship-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, 2 of 3 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @Yoni-Starkware)

Copy link
Collaborator

@Yoni-Starkware Yoni-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, 5 unresolved discussions (waiting on @avi-starkware and @avivg-starkware)


crates/blockifier/src/execution/syscalls/syscall_base.rs line 226 at r3 (raw file):

                error_data: vec![
                    Felt::from_hex(INVALID_INPUT_LENGTH_ERROR)
                        .map_err(SyscallExecutionError::from)?,

You can use .expect("Failed to parse INVALID_INPUT_LENGTH_ERROR hex string")


crates/blockifier/src/execution/syscalls/syscall_base.rs line 237 at r3 (raw file):

        if gas_cost > *remaining_gas {
            let out_of_gas_error =
                Felt::from_hex(OUT_OF_GAS_ERROR).map_err(SyscallExecutionError::from)?;

Same

Code quote:

Felt::from_hex(OUT_OF_GAS_ERROR).map_err(SyscallExecutionError::from)?;

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/create_keccak_base branch from b6f7a00 to 727adf3 Compare November 27, 2024 13:27
Copy link
Collaborator

@Yoni-Starkware Yoni-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 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @avi-starkware and @avivg-starkware)


crates/blockifier/src/execution/native/syscall_handler.rs line 460 at r4 (raw file):

                lo: u128::from(state[0]) | (u128::from(state[1]) << 64),
            }),
            Err(e) => Err(self.handle_error(remaining_gas, e.into())),

I think the into is not necessary

Suggestion:

Err(err) => Err(self.handle_error(remaining_gas, err)),

Copy link
Contributor

@meship-starkware meship-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 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @avi-starkware and @avivg-starkware)

Copy link
Contributor Author

@avivg-starkware avivg-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 @avi-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/native/syscall_handler.rs line 460 at r4 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

I think the into is not necessary

yes indeed, done.


crates/blockifier/src/execution/syscalls/syscall_base.rs line 214 at r3 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Rename and move it above finalize

Done.


crates/blockifier/src/execution/syscalls/syscall_base.rs line 217 at r3 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

No need to pass the length - take it from the array.

Done.


crates/blockifier/src/execution/syscalls/syscall_base.rs line 226 at r3 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

You can use .expect("Failed to parse INVALID_INPUT_LENGTH_ERROR hex string")

Done


crates/blockifier/src/execution/syscalls/syscall_base.rs line 237 at r3 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Same

Done

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/create_keccak_base branch from 727adf3 to ff30a90 Compare November 27, 2024 15:26
Copy link
Collaborator

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

@avivg-starkware avivg-starkware merged commit 18e06a7 into main Nov 27, 2024
13 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2024
@avivg-starkware avivg-starkware deleted the avivg/blockifier/create_keccak_base branch December 1, 2024 09:30
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