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

fix(execution): forbid calling cairo0 contract with cairo1 only builtins #34

Conversation

meship-starkware
Copy link
Contributor

@meship-starkware meship-starkware commented Jul 23, 2024

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this introduce a breaking change?

  • Yes
  • No

Other information


This change is Reviewable

dafnamatsry and others added 23 commits May 2, 2024 14:06
fix(format): run format fix on all repo
* feature(ci): Identify which package need to be built according to file changed
---------

Signed-off-by: Dori Medini <[email protected]>
Co-authored-by: Dori Medini <[email protected]>
* chore: fix ci to always compare changes against the target branch
* chore: copy all crates

* chore: switch to local dependencies

* chore: delete old papyrus_test_utils crate

* chore: rename crate test_utils -> papyrus_test_utils

* chore: fix RPCTransactio name in the mempool

* chore: fix mockito deps in papyrus and gateway

* chore: update cairo-* deps version

* chore: update config and presets for mempool and papyrus

* chore: rename default_config.json -> papyrus_default_config.json

* chore: rustfmt

* chore: reorg folders

* chore: reorg folders

* chore: fix unused deps

* chore: update papyrus Dockerfile

* chore: update scripts folder

* chore: copy build_native_blockifier.sh

* chore: copy BUILD and WORKSPACE files (from blockifier and committer)

* chore: update papyrus non crates folders and files

* chore: copy blockifier docs

* chore: copy committer taplo.toml

* chore: fix config tests

* chore: copy blockifier docker file

* fix: papyrus integration test runs only Papyrus related tests

* chore: rename conflicting dump_config.rs files

* chore: fix cargo doc errors

* chore: fix CI

* chore: small optimizations for the papyrus CI

* chore: copy README files

* chore: meld common repo files

---------

Co-authored-by: alon.dotan <[email protected]>
Co-authored-by: Dan Brownstein <[email protected]>
Copy link

codecov bot commented Jul 23, 2024

The author of this PR, meship-starkware, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at [email protected] with any questions.

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


crates/blockifier/src/execution/errors.rs line 45 at r1 (raw file):

    #[error("Requested contract address {:#064x} is not deployed.", .0.key())]
    UninitializedStorageAddress(ContractAddress),
    #[error("Called an unsupported builtin inside a Cairo0 contract.")]

The original phrasing is ambiguous (is the builtin unsupported in general? Or just inside a Cairo0 contract?)

Suggestion:

    #[error("Called a builtin that is unsupported in a Cairo0 contract.")]

crates/papyrus_monitoring_gateway/src/lib.rs line 316 at r1 (raw file):

    match prometheus_handle {
        Some(handle) => {
            Collector::new(PROCESS_METRICS_PREFIX).collect();

Why make this change in papyrus in this PR? Does it fail a test without the change?

Code quote:

 Collector::new(PROCESS_METRICS_PREFIX).collect();

@meship-starkware meship-starkware force-pushed the meship/forbid_cairo1_builtins_calls_in_cairo0_contracts branch from 3d21a7a to ad0646b Compare July 23, 2024 12:55
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: 2 of 3 files reviewed, 2 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/execution/errors.rs line 45 at r1 (raw file):

Previously, avi-starkware wrote…

The original phrasing is ambiguous (is the builtin unsupported in general? Or just inside a Cairo0 contract?)

Done.


crates/papyrus_monitoring_gateway/src/lib.rs line 316 at r1 (raw file):

Previously, avi-starkware wrote…

Why make this change in papyrus in this PR? Does it fail a test without the change?

The function is deprecated, and it does not build otherwise.

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


crates/blockifier/src/execution/deprecated_entry_point_execution.rs line 92 at r2 (raw file):

    if !program_builtins_set.is_subset(&cairo0_builtins_set) {
        return Err(PreExecutionError::UnsupportedCairo0Builtin);
    }

Is it possible to know the unsupported builtin that is used?

Suggestion:

    let program_builtins: HashSet<&BuiltinName> =
        HashSet::from_iter(contract_class.program.iter_builtins();
    if !program_builtins.is_subset(&HashSet::from_iter(CAIRO0_BUILTINS_NAMES.iter()) {
        return Err(PreExecutionError::UnsupportedCairo0Builtin);
    }
    
    // Resolve initial PC from EP indicator.
    let entry_point_pc = resolve_entry_point_pc(call, &contract_class)?;

@meship-starkware meship-starkware force-pushed the meship/forbid_cairo1_builtins_calls_in_cairo0_contracts branch from ad0646b to 4f4dc91 Compare July 24, 2024 06:55
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 3 files reviewed, 3 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/execution/deprecated_entry_point_execution.rs line 92 at r2 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Is it possible to know the unsupported builtin that is used?

I subtract the sets instead of using the is_subset. The downside is that if the length of program_builtins_set is longer than cairo0_builtin_names, we still have to do the calculation, but there is no way around it if we want the builtins_names.
Assuming that the length of program_builtins_set is bounded by the number of our builtins, I think it's ok.

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


crates/blockifier/src/execution/deprecated_entry_point_execution.rs line 90 at r3 (raw file):

    let subtract_set = &program_builtins_set - &HashSet::from_iter(CAIRO0_BUILTINS_NAMES.iter());
    if !subtract_set.is_empty() {
        return Err(PreExecutionError::UnsupportedCairo0Builtin(

I used it so I could send the builtins set without using lifetime.
I think this would be ok, assuming the subtract set length is bounded by our builtins number.

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


crates/blockifier/src/execution/deprecated_entry_point_execution.rs line 88 at r3 (raw file):

    let program_builtins_set: HashSet<&BuiltinName> =
        HashSet::from_iter(contract_class.program.iter_builtins());
    let subtract_set = &program_builtins_set - &HashSet::from_iter(CAIRO0_BUILTINS_NAMES.iter());

Suggestion:

unsupported_builtins_set

crates/blockifier/src/execution/errors.rs line 48 at r3 (raw file):

    #[error("Requested contract address {:#064x} is not deployed.", .0.key())]
    UninitializedStorageAddress(ContractAddress),
    #[error("Called a builtin that is unsupported in a Cairo0 contract. Builtins: {0:?}.")]

Can you please paste an example error?

Suggestion:

"Called builtins: {0} are unsupported in a Cairo0 contract."

@meship-starkware meship-starkware force-pushed the meship/forbid_cairo1_builtins_calls_in_cairo0_contracts branch from 4f4dc91 to f373afb Compare July 24, 2024 11:37
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 3 files reviewed, 4 unresolved discussions (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/execution/deprecated_entry_point_execution.rs line 88 at r3 (raw file):

    let program_builtins_set: HashSet<&BuiltinName> =
        HashSet::from_iter(contract_class.program.iter_builtins());
    let subtract_set = &program_builtins_set - &HashSet::from_iter(CAIRO0_BUILTINS_NAMES.iter());

Done.


crates/blockifier/src/execution/errors.rs line 48 at r3 (raw file):

Previously, avi-starkware wrote…

Can you please paste an example error?

Called builtins: {range_check96, segment_arena, keccak} are unsupported in a Cairo0 contract

@liorgold2 liorgold2 closed this Jul 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 27, 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.

9 participants