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

refactor(blockifier): share get_block_hash syscall code between native and casm #2107

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

meship-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch from cdee8c9 to 7120aab Compare November 17, 2024 11:55
@meship-starkware meship-starkware changed the title share get_block_hash syscall code between native and casm refactor(blockifier): share get_block_hash syscall code between native and casm Nov 17, 2024
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

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

Reviewable status: 0 of 5 files reviewed, 2 unresolved discussions (waiting on @avi-starkware and @Yoni-Starkware)


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

    {
        let out_of_range_error =
            Felt::from_hex(BLOCK_NUMBER_OUT_OF_RANGE_ERROR).map_err(SyscallExecutionError::from)?;

I am not sure this is the right way to handle the error here because, in the native implementation, we panicked.

Code quote:

        let out_of_range_error =
            Felt::from_hex(BLOCK_NUMBER_OUT_OF_RANGE_ERROR).map_err(SyscallExecutionError::from)?;

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

        let (key, block_hash_contract_address) =
            get_block_hash_base(current_block_number, block_number)
                .map_err(|e| self.handle_error(remaining_gas, e.into()))?;

I am not sure this is the right way to handle the error here.

Code quote:

.map_err(|e| self.handle_error(remaining_gas, e.into()))?;

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.32%. Comparing base (e3165c4) to head (fadd3b1).
Report is 466 commits behind head on main.

Files with missing lines Patch % Lines
.../blockifier/src/execution/syscalls/syscall_base.rs 88.46% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2107       +/-   ##
===========================================
+ Coverage   40.10%   77.32%   +37.22%     
===========================================
  Files          26      383      +357     
  Lines        1895    40180    +38285     
  Branches     1895    40180    +38285     
===========================================
+ Hits          760    31071    +30311     
- Misses       1100     6816     +5716     
- Partials       35     2293     +2258     

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

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch from 7120aab to 913d484 Compare November 17, 2024 12:06
Copy link
Contributor Author

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

Reviewable status: 0 of 5 files reviewed, 3 unresolved discussions (waiting on @avi-starkware and @Yoni-Starkware)


crates/blockifier/cairo_native line 1 at r1 (raw file):

Subproject commit 0bc6f408884370e4fbbf421c4e8e109911c3d73e

This is a mistake. Working on it

Code quote:

Subproject commit 0bc6f408884370e4fbbf421c4e8e109911c3d73e

Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch from 913d484 to 45f1971 Compare November 17, 2024 12:11
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch from 45f1971 to 600f313 Compare November 17, 2024 12:12
Copy link

Artifacts upload triggered. View details 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.

Reviewed 1 of 5 files at r1.
Reviewable status: 1 of 5 files reviewed, 8 unresolved discussions (waiting on @avi-starkware and @meship-starkware)


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

Previously, meship-starkware (Meshi Peled) wrote…

I am not sure this is the right way to handle the error here.

Why not?


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

Previously, meship-starkware (Meshi Peled) wrote…

I am not sure this is the right way to handle the error here because, in the native implementation, we panicked.

Panic here as well. It is safe


crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs line 120 at r2 (raw file):

    };

    let call_info = entry_point_call.execute_directly(&mut state).unwrap();

Thanks :)


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

    OUT_OF_GAS_ERROR,
};
use crate::execution::syscalls::syscall_base::get_block_hash_base;

Suggestion:

ase;

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

        let current_block_number =
            self.context.tx_context.block_context.block_info().block_number.0;

Share this code as well

Code quote:

        if self.context.execution_mode == ExecutionMode::Validate {
            let err = SyscallExecutionError::InvalidSyscallInExecutionMode {
                syscall_name: "get_block_hash".to_string(),
                execution_mode: ExecutionMode::Validate,
            };
            return Err(self.handle_error(remaining_gas, err));
        }

        let current_block_number =
            self.context.tx_context.block_context.block_info().block_number.0;

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

        let (key, block_hash_contract_address) =
            get_block_hash_base(current_block_number, block_number)

Suggestion:

syscall_base::get_block_hash(

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

                .map_err(|e| self.handle_error(remaining_gas, e.into()))?;

        match self.state.get_storage_at(block_hash_contract_address, key) {

Share this as well

Code quote:

self.state.get_storage_at(block_hash_contract_address, key) {

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

    BLOCK_NUMBER_OUT_OF_RANGE_ERROR,
};

Document this file shortly.

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch from 600f313 to e94d3b0 Compare November 17, 2024 14:05
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

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

Reviewable status: 1 of 5 files reviewed, 6 unresolved discussions (waiting on @avi-starkware and @Yoni-Starkware)


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

Previously, Yoni-Starkware (Yoni) wrote…

Share this code as well

Done.


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

Previously, Yoni-Starkware (Yoni) wrote…

Share this as well

Seems like it fails the native tests. I'll look into it.


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

    OUT_OF_GAS_ERROR,
};
use crate::execution::syscalls::syscall_base::get_block_hash_base;

Done.


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

        let (key, block_hash_contract_address) =
            get_block_hash_base(current_block_number, block_number)

Done.

Copy link
Contributor Author

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

Reviewable status: 1 of 5 files reviewed, 6 unresolved discussions (waiting on @avi-starkware and @Yoni-Starkware)


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

Previously, meship-starkware (Meshi Peled) wrote…

Seems like it fails the native tests. I'll look into it.

NM seems OK in the CI, although it fails locally.
Done.

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


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

    let block_hash = BlockHash(syscall_base::get_block_hash_base(
        syscall_handler.execution_mode(),
        current_block_number,

Pass the context instead.

Suggestion:

    let block_hash = BlockHash(syscall_base::get_block_hash_base(
        self.context,

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch 2 times, most recently from 0caab14 to 0e196fc Compare November 18, 2024 07:34
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

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

Reviewable status: 1 of 5 files reviewed, 4 unresolved discussions (waiting on @avi-starkware and @Yoni-Starkware)


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

Previously, Yoni-Starkware (Yoni) wrote…

Why not?

Not relevant anymore


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

Previously, Yoni-Starkware (Yoni) wrote…

Pass the context instead.

Done.


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

Previously, Yoni-Starkware (Yoni) wrote…

Document this file shortly.

Done.

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: 4 of 5 files reviewed, all discussions resolved (waiting on @avi-starkware)


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

Previously, meship-starkware (Meshi Peled) wrote…

Done.

Not yet :) but non-blocking

@meship-starkware meship-starkware force-pushed the meship/blockifier/share_syscall_code branch from 0e196fc to fadd3b1 Compare November 18, 2024 09:21
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

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

Reviewable status: 3 of 6 files reviewed, 1 unresolved discussion (waiting on @avi-starkware and @Yoni-Starkware)


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

/// This file is for sharing common logic between Native and Casm syscalls implementations.

Is this not enough documentation, or is it in the wrong place?

Code quote:

/// This file is for sharing common logic between Native and Casm syscalls implementations.

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 2 of 2 files at r5, all commit messages.
Reviewable status: 5 of 6 files reviewed, 1 unresolved discussion (waiting on @avi-starkware)

Copy link
Contributor Author

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

@meship-starkware meship-starkware merged commit ef8f923 into main Nov 18, 2024
21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2024
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.

3 participants