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): add cairo-native feature #1558

Merged
merged 1 commit into from
Oct 28, 2024
Merged

Conversation

noaov1
Copy link
Collaborator

@noaov1 noaov1 commented Oct 26, 2024

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 4e37a46 to 2185b8f Compare October 26, 2024 15:42
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 2185b8f to 993a986 Compare October 26, 2024 15:48
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 993a986 to 8c3accf Compare October 26, 2024 15:51
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch 2 times, most recently from 61e77de to 868db33 Compare October 26, 2024 16:08
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 868db33 to baedc08 Compare October 26, 2024 16:13
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from baedc08 to 489eddb Compare October 26, 2024 16:38
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 489eddb to b3b1f7f Compare October 26, 2024 18:42
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from b3b1f7f to 328d73c Compare October 26, 2024 19:17
Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Oct 26, 2024

Codecov Report

Attention: Patch coverage is 56.52174% with 10 lines in your changes missing coverage. Please review.

Project coverage is 68.96%. Comparing base (e3165c4) to head (6c4010e).
Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/transaction/transactions.rs 27.27% 8 Missing ⚠️
crates/blockifier/src/execution/contract_class.rs 50.00% 1 Missing ⚠️
crates/blockifier/src/execution/syscalls/mod.rs 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1558       +/-   ##
===========================================
+ Coverage   40.10%   68.96%   +28.86%     
===========================================
  Files          26      100       +74     
  Lines        1895    13380    +11485     
  Branches     1895    13380    +11485     
===========================================
+ Hits          760     9228     +8468     
- Misses       1100     3751     +2651     
- Partials       35      401      +366     

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

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 328d73c to 640f100 Compare October 26, 2024 19:34
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 640f100 to 44dc3f2 Compare October 27, 2024 07:12
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 44dc3f2 to bed1aca Compare October 27, 2024 07:20
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from bed1aca to a8c7f39 Compare October 27, 2024 08:03
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from a8c7f39 to 0c61caa Compare October 27, 2024 08:17
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 9266e4e to 7c9710f Compare October 27, 2024 12:16
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@avi-starkware avi-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 7 of 15 files at r1, all commit messages.
Reviewable status: 7 of 15 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @noaov1)


-- commits line 2 at r1:
This is weird... Did you amend an existing commit instead of creating a new one?

Code quote:

7c9710f: feat(ci): small QoL improvements to publish_crates.py (#1542)

Copy link
Contributor

@avi-starkware avi-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 8 of 15 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware and @noaov1)


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

        }
        #[cfg(feature = "cairo_native")]
        ContractClass::V1Native(_) => {

This method introduces code duplication in many places.
Is there a way to avoid it?
Non-blocking

Code quote:

        #[cfg(feature = "cairo_native")]
        ContractClass::V1Native(_) => {

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 7c9710f to 85091d4 Compare October 27, 2024 15:23
Copy link

Artifacts upload triggered. View details here

Copy link
Collaborator Author

@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: 14 of 15 files reviewed, 2 unresolved discussions (waiting on @avi-starkware and @dorimedini-starkware)


-- commits line 2 at r1:

Previously, avi-starkware wrote…

This is weird... Did you amend an existing commit instead of creating a new one?

Indeed weird. Nice catch!

Copy link
Collaborator

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

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @avi-starkware and @noaov1)

a discussion (no related file):
there are two options as I see it

  1. what you did here
  2. duplicate all code that has a variation into separate modules - one for native and one without. for example:
// Module gated behind #[cfg(feature = "cairo_native")]
pub enum ContractClass {
    V0(ContractClassV0),
    V1(ContractClassV1),
    V1Native(NativeContractClassV1),
}
...
// Module gated behind #[cfg(not(feature = "cairo_native"))]
pub enum ContractClass {
    V0(ContractClassV0),
    V1(ContractClassV1),
}

which one is better?



.github/workflows/blockifier_ci.yml line 54 at r2 (raw file):

      - run: cargo build -p blockifier --features transaction_serde
      - run: cargo test -p blockifier --features transaction_serde
        # native-blckifier is not activated by any workspace crate; test the build.

Suggestion:

# cairo-native is not activated by any workspace crate; test the build.

crates/blockifier/src/transaction/account_transaction.rs line 972 at r2 (raw file):

    }

    false

does this work?

Suggestion:

    match contract_class {
        ContractClass::V0(_) => false,
        ContractClass::V1(_) => true,
        #[cfg(feature = "cairo_native")]
        ContractClass::V1Native(_) => true,
    }

@avi-starkware
Copy link
Contributor

Previously, dorimedini-starkware wrote…

there are two options as I see it

  1. what you did here
  2. duplicate all code that has a variation into separate modules - one for native and one without. for example:
// Module gated behind #[cfg(feature = "cairo_native")]
pub enum ContractClass {
    V0(ContractClassV0),
    V1(ContractClassV1),
    V1Native(NativeContractClassV1),
}
...
// Module gated behind #[cfg(not(feature = "cairo_native"))]
pub enum ContractClass {
    V0(ContractClassV0),
    V1(ContractClassV1),
}

which one is better?

Solution 2 adds much more code duplication. This means any change to this module will have to be made twice.

Copy link
Contributor

@avi-starkware avi-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, 4 unresolved discussions (waiting on @dorimedini-starkware and @noaov1)


crates/blockifier/src/transaction/account_transaction.rs line 972 at r2 (raw file):

Previously, dorimedini-starkware wrote…

does this work?

It should work. The same pattern is used in test_utils.rs in this PR (and in many other places...)

Copy link
Contributor

@avi-starkware avi-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: all files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @noaov1)

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 85091d4 to 8635ac7 Compare October 27, 2024 21:27
Copy link

Artifacts upload triggered. View details here

Copy link
Collaborator Author

@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: 12 of 15 files reviewed, 3 unresolved discussions (waiting on @avi-starkware and @dorimedini-starkware)

a discussion (no related file):

Previously, avi-starkware wrote…

Solution 2 adds much more code duplication. This means any change to this module will have to be made twice.

I tend to agree with Avi.



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

Previously, avi-starkware wrote…

This method introduces code duplication in many places.
Is there a way to avoid it?
Non-blocking

Good question. Changed. WDYT?


crates/blockifier/src/transaction/account_transaction.rs line 972 at r2 (raw file):

Previously, avi-starkware wrote…

It should work. The same pattern is used in test_utils.rs in this PR (and in many other places...)

Like. Done.

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 8635ac7 to 113fd37 Compare October 27, 2024 21:38
Copy link
Collaborator Author

@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: 12 of 15 files reviewed, 3 unresolved discussions (waiting on @avi-starkware and @dorimedini-starkware)


.github/workflows/blockifier_ci.yml line 54 at r2 (raw file):

      - run: cargo build -p blockifier --features transaction_serde
      - run: cargo test -p blockifier --features transaction_serde
        # native-blckifier is not activated by any workspace crate; test the build.

Opps. Done

Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@avi-starkware avi-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: 11 of 15 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @noaov1)


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

Previously, noaov1 (Noa Oved) wrote…

Good question. Changed. WDYT?

Why not just:

if !is_cairo1(&class) {
    return Err(....)
}

The function is_cairo1 covers all the cases. If it is false, it has to be Cairo 0.

Copy link
Contributor

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


crates/blockifier/src/transaction/transactions.rs line 156 at r4 (raw file):

        let declare_version = declare_tx.version();
        // Verify contract class version.
        if matches!(class_info.contract_class(), ContractClass::V0(_)) {

As I suggested above

Suggestion:

        if !is_cairo1(class_info.contract_class()) {

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from 113fd37 to d198eb6 Compare October 28, 2024 06:08
Copy link

Artifacts upload triggered. View details here

@noaov1 noaov1 force-pushed the noa/add_native_feature branch from d198eb6 to 6c4010e Compare October 28, 2024 08:13
Copy link

Artifacts upload triggered. View details here

Copy link
Collaborator

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

:lgtm:

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

@noaov1 noaov1 merged commit 8823d31 into main Oct 28, 2024
12 checks passed
@noaov1 noaov1 deleted the noa/add_native_feature branch October 28, 2024 09:54
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 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.

4 participants