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: feature contracts to use native together with casm #1455

Closed
wants to merge 1 commit into from

Conversation

varex83
Copy link
Contributor

@varex83 varex83 commented Oct 17, 2024

No description provided.

@varex83 varex83 added the native integration Related with the integration of Cairo Native into the Blockifier label Oct 17, 2024
@lotem-starkware
Copy link
Contributor

This change is Reviewable

@varex83 varex83 marked this pull request as draft October 17, 2024 14:02
@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 20a94f3 to a0aef94 Compare October 17, 2024 14:17
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 8.82353% with 31 lines in your changes missing coverage. Please review.

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

Files with missing lines Patch % Lines
crates/blockifier/src/test_utils/contracts.rs 9.37% 29 Missing ⚠️
crates/blockifier/src/test_utils/cairo_compile.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1455       +/-   ##
===========================================
+ Coverage   40.10%   68.91%   +28.81%     
===========================================
  Files          26      105       +79     
  Lines        1895    13687    +11792     
  Branches     1895    13687    +11792     
===========================================
+ Hits          760     9433     +8673     
- Misses       1100     3851     +2751     
- Partials       35      403      +368     

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


🚨 Try these New Features:

@varex83 varex83 marked this pull request as ready for review October 21, 2024 10:19
@rodrigo-pino rodrigo-pino force-pushed the rdr/update-testing-suite branch 3 times, most recently from dd2bc78 to 2bfec09 Compare October 21, 2024 12:28
@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 8b9e3b3 to ba03f27 Compare October 21, 2024 15:13
@rodrigo-pino rodrigo-pino force-pushed the rdr/update-testing-suite branch 3 times, most recently from c728762 to 4cf52c8 Compare October 24, 2024 11:51
@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 215d8dd to 86fcfd5 Compare October 28, 2024 10:46
Copy link

Artifacts upload triggered. View details here

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 86fcfd5 to 4839720 Compare October 28, 2024 10:56
Copy link

Artifacts upload triggered. View details here

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch 2 times, most recently from 20a94f3 to bf0b41c Compare October 28, 2024 11:12
Copy link

Artifacts upload triggered. View details here

@rodrigo-pino rodrigo-pino force-pushed the rdr/update-testing-suite branch 2 times, most recently from a00994e to e2c9fe8 Compare October 28, 2024 15:36
@PearsonWhite PearsonWhite force-pushed the bohdan/feature-contracts-refactor branch from d0aca03 to bf0b41c Compare October 29, 2024 01:42
@rodrigo-pino rodrigo-pino force-pushed the rdr/update-testing-suite branch 2 times, most recently from 6815d18 to a3166cf Compare October 29, 2024 11:06
@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from c50e8c7 to 7166b97 Compare October 29, 2024 14:16
Copy link

Artifacts upload triggered. View details here

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 2acc000 to 9da70d6 Compare November 8, 2024 12:29
Copy link

github-actions bot commented Nov 8, 2024

Artifacts upload triggered. View details 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 2 of 3 files at r16, all commit messages.
Reviewable status: 19 of 20 files reviewed, 1 unresolved discussion (waiting on @avi-starkware, @noaov1, and @varex83)


crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

// remove the file manually to continue.
// """
static GIT_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());

@dorimedini-starkware WDYT?

Code quote:

static GIT_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());

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 3 files at r16, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @noaov1 and @varex83)

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.

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @meship-starkware, @noaov1, and @varex83)


crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

@dorimedini-starkware WDYT?

can you explain why this is needed? not sure it's a good idea (let's chat)


crates/blockifier/src/test_utils.rs line 88 at r16 (raw file):

        }
    }
}

I don't think you really need this... and converting 2 to Native is non-intuitive

Code quote:

impl From<isize> for CairoVersion {
    fn from(value: isize) -> Self {
        match value {
            0 => Self::Cairo0,
            1 => Self::Cairo1,
            #[cfg(feature = "cairo_native")]
            2 => Self::Native,
            _ => panic!("Invalid value for CairoVersion: {}", value),
        }
    }
}

crates/blockifier/src/test_utils/contracts.rs line 120 at r16 (raw file):

    ///
    /// This order is defined in [CairoVersion] enum.
    fn supported_versions(&self) -> u32 {

please use more explicit typing...

Suggestion:

HashSet<CairoVersion>

crates/blockifier/src/test_utils/contracts.rs line 333 at r16 (raw file):

                    #[cfg(feature = "cairo_native")]
                    CairoVersion::Native => "_sierra",
                },

Suggestion:

                "feature_contracts/cairo{}/{}{}.json",
                match cairo_version {
                    CairoVersion::Cairo0 => "0/compiled",
                    CairoVersion::Cairo1 => "1/compiled_casm",
                    #[cfg(feature = "cairo_native")]
                    CairoVersion::Native => "1/compiled_sierra",
                },

crates/blockifier/src/test_utils/contracts.rs line 460 at r16 (raw file):

                    .into_iter()
            }
        })

refactor: just iterate over supported versions and add the different variants (see above, supported_versions should return a set of versions, not a u32)

Code quote:

        Self::iter().flat_map(|contract| {
            // If only one supported version exists, add the contract to the array as is.
            if contract.supported_versions().is_power_of_two() {
                vec![contract].into_iter()
            } else {
                let supported_versions = contract.supported_versions();

                #[cfg(feature = "cairo_native")]
                let range = 0..3isize;
                #[cfg(not(feature = "cairo_native"))]
                let range = 0..2isize;

                // If multiple supported versions exist, add each supported version of the
                // contract to the array.
                range
                    .filter(|i| supported_versions & (1u32 << i) != 0)
                    .map(move |i| {
                        let mut contract = contract;
                        contract.set_cairo_version(CairoVersion::from(i));

                        contract
                    })
                    .collect::<Vec<_>>()
                    .into_iter()
            }
        })

Base automatically changed from rdr/update-testing-suite to main November 10, 2024 09:30
@rodrigo-pino rodrigo-pino force-pushed the bohdan/feature-contracts-refactor branch from 9da70d6 to 060a784 Compare November 10, 2024 10:33
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.

Reviewed 5 of 8 files at r17, all commit messages.
Reviewable status: 17 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @meship-starkware, @noaov1, and @varex83)

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 6 of 8 files at r17, all commit messages.
Reviewable status: 18 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @noaov1, and @varex83)

@avi-starkware
Copy link
Contributor

crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

Previously, dorimedini-starkware wrote…

can you explain why this is needed? not sure it's a good idea (let's chat)

As far as I understood, CI errors may appear when running git commands in the function prepare_cairo1_compiler_deps because it is run concurrently in tests, causing a race condition on the index.lock file.

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.

Reviewable status: 18 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @meship-starkware, @noaov1, and @varex83)


crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

Previously, avi-starkware wrote…

As far as I understood, CI errors may appear when running git commands in the function prepare_cairo1_compiler_deps because it is run concurrently in tests, causing a race condition on the index.lock file.

who runs it concurrently?
there is an open task to do this, it is not simple for this reason.
we do not want to parallelize blindly.
different cairo1 compiler versions used should be checked out sequentially, so we don't build the same tag multiple times.
when parallelizing, we should group compile jobs by compiler version, and execute groups sequentially,
or checkout different copies of the compiler repo (worktrees?) to be able to compile different versions in parallel

@avi-starkware
Copy link
Contributor

crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

Previously, dorimedini-starkware wrote…

who runs it concurrently?
there is an open task to do this, it is not simple for this reason.
we do not want to parallelize blindly.
different cairo1 compiler versions used should be checked out sequentially, so we don't build the same tag multiple times.
when parallelizing, we should group compile jobs by compiler version, and execute groups sequentially,
or checkout different copies of the compiler repo (worktrees?) to be able to compile different versions in parallel

I think it is used in multiple tests and cargo test runs these tests concurrently in the CI

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.

Reviewable status: 18 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @meship-starkware, @noaov1, and @varex83)


crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

Previously, avi-starkware wrote…

I think it is used in multiple tests and cargo test runs these tests concurrently in the CI

then this is new.
since when do multiple tests recompile?
this is not intended, and if it is done, the cairo repo should be explicitly checked out to a different directory

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.

Reviewable status: 18 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @meship-starkware, @noaov1, and @varex83)


crates/blockifier/src/test_utils/cairo_compile.rs line 213 at r16 (raw file):

Previously, dorimedini-starkware wrote…

then this is new.
since when do multiple tests recompile?
this is not intended, and if it is done, the cairo repo should be explicitly checked out to a different directory

or, implement "smart" parallelization...
waiting for a lock is not a good solution, we will end up recompiling the same compiler tag multiple times

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 060a784 to 0d99611 Compare November 11, 2024 10:10
Copy link

Artifacts upload triggered. View details 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 1 of 1 files at r18, all commit messages.
Reviewable status: 18 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @noaov1, and @varex83)

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from 0d99611 to e83dcd7 Compare November 11, 2024 22:48
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.

Can we avoid the extra casm compilation here?

Reviewed 2 of 15 files at r9, 1 of 13 files at r13, 4 of 8 files at r17, 1 of 1 files at r18, all commit messages.
Reviewable status: 17 of 20 files reviewed, 5 unresolved discussions (waiting on @avi-starkware, @meship-starkware, @noaov1, and @varex83)

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from e83dcd7 to e70e320 Compare November 14, 2024 15:25
Copy link

Artifacts upload triggered. View details here

@varex83 varex83 force-pushed the bohdan/feature-contracts-refactor branch from e70e320 to b80eda2 Compare November 14, 2024 15:48
Copy link

Artifacts upload triggered. View details here

@rodrigo-pino
Copy link
Contributor

Closing PR since a bigger rework is required which will include this fix as part of it

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

7 participants