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

feat(blockifier): add NativeSyscallHandler #1240

Merged
merged 7 commits into from
Oct 10, 2024

Conversation

rodrigo-pino
Copy link
Contributor

@rodrigo-pino rodrigo-pino commented Oct 7, 2024

Recration of #1157 targeting Main


This change is Reviewable

@rodrigo-pino rodrigo-pino added the native integration Related with the integration of Cairo Native into the Blockifier label Oct 7, 2024
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 10.24590% with 219 lines in your changes missing coverage. Please review.

Project coverage is 69.30%. Comparing base (b0cfe82) to head (e9d7c2a).
Report is 313 commits behind head on main.

Files with missing lines Patch % Lines
...blockifier/src/execution/native/syscall_handler.rs 0.00% 219 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1240      +/-   ##
==========================================
- Coverage   74.18%   69.30%   -4.89%     
==========================================
  Files         359       88     -271     
  Lines       36240    11803   -24437     
  Branches    36240    11803   -24437     
==========================================
- Hits        26886     8180   -18706     
+ Misses       7220     3256    -3964     
+ Partials     2134      367    -1767     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

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 4 files at r1.
Reviewable status: 2 of 5 files reviewed, all discussions resolved

Copy link
Collaborator

@noaov1 noaov1 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 4 files at r1, 1 of 1 files at r2, 1 of 1 files at r6, all commit messages.
Reviewable status: 4 of 5 files reviewed, 2 unresolved discussions (waiting on @meship-starkware and @rodrigo-pino)


crates/blockifier/src/execution/native/utils.rs line 22 at r7 (raw file):

        encoding[i] = Felt::from_bytes_be(&chunk);
    }
    encoding

The chunks are of size 31 (as well as data_chunk.
chunk is of size 32.
We write at indices 1-31 the value of data_chunk as the MSB no?
It's different than what we do in the constants messages, right?

Suggestion:

    let data = msg.as_bytes().chunks(CHUNK_SIZE - 1);
    let mut encoding = vec![];
    for data_chunk in data.iter() {
        let mut chunk = [0_u8; CHUNK_SIZE];
        chunk[1..data_chunk.len() + 1].copy_from_slice(data_chunk);
        encoding.push(Felt::from_bytes_be(&chunk));
    }
    encoding

crates/blockifier/src/execution/native/utils.rs line 27 at r7 (raw file):

// Todo(rodrigo): This is an opinionated way of interpretting error messages. It's ok for now but I
// think it can be improved; (for example) trying to make the output similar to a Cairo VM panic
pub fn decode_felts_as_str(encoding: &[Felt]) -> String {

When will it be used?

Code quote:

pub fn decode_felts_as_str(encoding: &[Felt]) -> String {

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 1 files at r6.
Reviewable status: 4 of 5 files reviewed, 2 unresolved discussions (waiting on @rodrigo-pino)

Copy link
Contributor Author

@rodrigo-pino rodrigo-pino 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: 4 of 5 files reviewed, 2 unresolved discussions (waiting on @meship-starkware and @noaov1)


crates/blockifier/src/execution/native/utils.rs line 22 at r7 (raw file):

We write at indices 1-31 the value of data_chunk as the MSB no?
It's different than what we do in the constants messages, right?

I'd have to dive a bit deep in the code to answer a 100% sure but I think is not. Both messages are encoded in the same fashion as your error messages. When they get decoded during execution we don't see any word being reversed 🤔


crates/blockifier/src/execution/native/utils.rs line 27 at r7 (raw file):

Previously, noaov1 (Noa Oved) wrote…

When will it be used?

When outputting the final error message, after Cairo Native returned control if there was a failure, the message is contained in a Vec<Felt>

Copy link
Collaborator

@noaov1 noaov1 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: 4 of 5 files reviewed, 3 unresolved discussions (waiting on @meship-starkware and @rodrigo-pino)


crates/blockifier/src/execution/native/utils.rs line 22 at r7 (raw file):

Previously, rodrigo-pino (Rodrigo) wrote…

We write at indices 1-31 the value of data_chunk as the MSB no?
It's different than what we do in the constants messages, right?

I'd have to dive a bit deep in the code to answer a 100% sure but I think is not. Both messages are encoded in the same fashion as your error messages. When they get decoded during execution we don't see any word being reversed 🤔

I tried to decode it and it seems to result with the same "Out of gas" message. I guess it's because you remove the 0's (in prefix and suffix). Makes sense?


crates/blockifier/src/execution/native/utils.rs line 34 at r7 (raw file):

        // If the string is utf8 make sure it is not prefixed by no null chars. Null chars in
        // between can still happen
        Ok(s) => s.trim_matches('\0').to_owned(),

Can it be problematic? Consider the error message: "Not supporting Cairo 0". It's hex is "4E 6F 74 20 73 75 70 70 6F 72 74 69 6E 67 20 43 61 69 72 6F 20 30", so trimming the last zero can be problematic.

Code quote:

Ok(s) => s.trim_matches('\0').to_owned(),

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 1 files at r2.
Reviewable status: 4 of 5 files reviewed, 3 unresolved discussions (waiting on @rodrigo-pino)

Copy link
Contributor

@PearsonWhite PearsonWhite 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: 4 of 5 files reviewed, 3 unresolved discussions (waiting on @meship-starkware, @noaov1, and @rodrigo-pino)


crates/blockifier/src/execution/native/utils.rs line 27 at r7 (raw file):

Previously, rodrigo-pino (Rodrigo) wrote…

When outputting the final error message, after Cairo Native returned control if there was a failure, the message is contained in a Vec<Felt>

It's used in the syscall_handler.rs execute_inner_call to translate the CallEntryPoint.


crates/blockifier/src/execution/native/utils.rs line 34 at r7 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Can it be problematic? Consider the error message: "Not supporting Cairo 0". It's hex is "4E 6F 74 20 73 75 70 70 6F 72 74 69 6E 67 20 43 61 69 72 6F 20 30", so trimming the last zero can be problematic.

I don't think this will match unicode 0s. I can't reproduce an error with the test string "Not supporting Cairo 0" in "test_encode_decode_str".

Copy link
Collaborator

@noaov1 noaov1 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 4 files at r1.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @meship-starkware, @PearsonWhite, and @rodrigo-pino)


crates/blockifier/src/execution/native/utils.rs line 34 at r7 (raw file):

Previously, PearsonWhite wrote…

I don't think this will match unicode 0s. I can't reproduce an error with the test string "Not supporting Cairo 0" in "test_encode_decode_str".

You are right :)

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 all commit messages.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @PearsonWhite and @rodrigo-pino)

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.

:lgtm:

Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @PearsonWhite and @rodrigo-pino)

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 1 files at r5.
Reviewable status: 4 of 5 files reviewed, all discussions resolved (waiting on @PearsonWhite)

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

@meship-starkware meship-starkware merged commit ac479c5 into main Oct 10, 2024
12 of 19 checks passed
@rodrigo-pino rodrigo-pino deleted the rdr/add-native-syscall-handler branch October 10, 2024 14:51
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
native integration Related with the integration of Cairo Native into the Blockifier
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants