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 call_contract cairo native syscall #1548

Open
wants to merge 1 commit into
base: rdr/native-storage-read
Choose a base branch
from

Conversation

PearsonWhite
Copy link
Contributor

@PearsonWhite PearsonWhite commented Oct 23, 2024

Implements call_contract in NativeSyscallHandler.

@reviewable-StarkWare
Copy link

This change is Reviewable

@PearsonWhite PearsonWhite added the native integration Related with the integration of Cairo Native into the Blockifier label Oct 23, 2024
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

@rodrigo-pino rodrigo-pino force-pushed the rdr/native-storage-read branch 2 times, most recently from ceff54f to f9d4b21 Compare October 25, 2024 11:55
Copy link

Artifacts upload triggered. View details here

@PearsonWhite PearsonWhite marked this pull request as ready for review October 25, 2024 20:20
Copy link
Contributor Author

@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: 0 of 2 files reviewed, 1 unresolved discussion

a discussion (no related file):
In test_track_resources, the logic for what we expect has changed. Now, I'm not sure if the result is expected or not and I need clarification.

Previously, both the outer call and the inner call had to be (Cairo1 | Native) for the inner tracked_resource to be SierraGas.
Now, long as the inner is (Cairo1 | Native) I think SierraGas should be used.

Currently, one case fails: when outer is Cairo0 and inner is Cairo1, SierraGas is expected, but CairoSteps is used.
I've added a complete table of the results here in csv format:

Code snippet:

outer , inner , expected_outer , expected_inner , actual_outer , actual_expected , pass/fail
Cairo0 , Cairo0 , CairoSteps , CairoSteps , CairoSteps , CairoSteps , pass
Cairo0 , Cairo1 , CairoSteps , SierraGas , CairoSteps , CairoSteps , failed <--- Should this fail? Or is it expected?
Cairo1 , Cairo0 , SierraGas , CairoSteps , SierraGas , CairoSteps , pass
Cairo1 , Cairo1 , SierraGas , SierraGas , SierraGas , SierraGas , pass
Cairo0 , Native , CairoSteps , SierraGas , CairoSteps , SierraGas , pass
Native , Cairo1 , SierraGas , SierraGas , SierraGas , SierraGas , pass
Native , Cairo0 , SierraGas , CairoSteps , SierraGas , CairoSteps , pass
Cairo1 , Native , SierraGas , SierraGas , SierraGas , SierraGas , pass
Native , Native , SierraGas , SierraGas , SierraGas , SierraGas , pass

Copy link
Contributor

@varex83 varex83 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 2 files reviewed, 2 unresolved discussions (waiting on @PearsonWhite)


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

        let contract_address = ContractAddress::try_from(address)
            .expect("Failed to convert address argument to a ContractAddress");

Don't use expect, return runtime error instead

Copy link
Contributor

@varex83 varex83 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 2 files reviewed, 3 unresolved discussions (waiting on @PearsonWhite)


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

            caller_address: self.contract_address,
            call_type: CallType::Call,
            initial_gas: u64::try_from(*remaining_gas).unwrap(),

Use expect instead of unwrap here

Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

@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: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @varex83)


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

Previously, varex83 (Bohdan Ohorodnii) wrote…

Don't use expect, return runtime error instead

Done.


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

Previously, varex83 (Bohdan Ohorodnii) wrote…

Use expect instead of unwrap here

Done.

Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.55%. Comparing base (e63d1b9) to head (09de68c).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           rdr/native-storage-read    #1548      +/-   ##
===========================================================
+ Coverage                    68.48%   68.55%   +0.06%     
===========================================================
  Files                          102      102              
  Lines                        13662    13687      +25     
  Branches                     13662    13687      +25     
===========================================================
+ Hits                          9357     9383      +26     
+ Misses                        3904     3903       -1     
  Partials                       401      401              

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

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

@rodrigo-pino rodrigo-pino force-pushed the rdr/native-storage-read branch 2 times, most recently from 20227be to 9327187 Compare October 30, 2024 21:33
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.

Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @noaov1 and @varex83)

a discussion (no related file):

Previously, PearsonWhite wrote…

In test_track_resources, the logic for what we expect has changed. Now, I'm not sure if the result is expected or not and I need clarification.

Previously, both the outer call and the inner call had to be (Cairo1 | Native) for the inner tracked_resource to be SierraGas.
Now, long as the inner is (Cairo1 | Native) I think SierraGas should be used.

Currently, one case fails: when outer is Cairo0 and inner is Cairo1, SierraGas is expected, but CairoSteps is used.
I've added a complete table of the results here in csv format:

If I am not mistaken, if cairo0 contract calls cairo1 contract, we have decided to use the VM resources (meaning we do not use native in these cases), so both the outer and inner should be cairo steps in this case. @noaov1 could you please confirm


@rodrigo-pino rodrigo-pino force-pushed the rdr/native-storage-read branch 4 times, most recently from 1abefc7 to 4ac4cf9 Compare October 31, 2024 14:46
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

@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: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @noaov1 and @varex83)

a discussion (no related file):

Previously, meship-starkware (Meshi Peled) wrote…

If I am not mistaken, if cairo0 contract calls cairo1 contract, we have decided to use the VM resources (meaning we do not use native in these cases), so both the outer and inner should be cairo steps in this case. @noaov1 could you please confirm

This has been changed in a recent rebase. Now I think it is working as expected. See updated logic/comments in crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs.


Copy link

github-actions bot commented Nov 1, 2024

Artifacts upload triggered. View details here

Copy link
Contributor Author

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

Dismissed @varex83 from 2 discussions.
Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on @noaov1)

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 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

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 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

@rodrigo-pino rodrigo-pino force-pushed the rdr/native-storage-read branch 2 times, most recently from b977740 to e63d1b9 Compare November 7, 2024 15:32
Copy link

github-actions bot commented Nov 7, 2024

Artifacts upload triggered. View details here

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 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @PearsonWhite)

a discussion (no related file):

Previously, PearsonWhite wrote…

This has been changed in a recent rebase. Now I think it is working as expected. See updated logic/comments in crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs.

@meship-starkware you are right. Wrote some comment below.



crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 193 at r4 (raw file):

    #[cfg(feature = "cairo_native")]
    // If inner is Native, we expect inner to use SierraGas.
    // This overrides previous logic.

If the outer call uses cairo steps, then we choose to run all the inner calls also with VM resources.
This should not work, see here.

Code quote:

    // If inner is Native, we expect inner to use SierraGas.
    // This overrides previous logic.

Copy link

github-actions bot commented Nov 8, 2024

Artifacts upload triggered. View details here

Copy link
Contributor Author

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


crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs line 193 at r4 (raw file):

Previously, noaov1 (Noa Oved) wrote…

If the outer call uses cairo steps, then we choose to run all the inner calls also with VM resources.
This should not work, see here.

After rebasing, this no longer worked. Since this shouldn't have worked, that means the rebase fixed the execution logic, leaving only the test wrong. I've changed the logic for the test to match the VM. It should all be working as expected and passing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

6 participants