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

Native contract executor #2156

Open
wants to merge 11 commits into
base: native2.8.x-blockifier
Choose a base branch
from

Conversation

PearsonWhite
Copy link

@PearsonWhite PearsonWhite commented Sep 16, 2024

Corresponding sequencer PR: NethermindEth/sequencer#19

PR: #2156

Unused functions had to do with saving/loading compiled contracts
to/from disk, but were never used. Juno seems to run fine without them.
@PearsonWhite PearsonWhite marked this pull request as ready for review September 16, 2024 20:30
@PearsonWhite PearsonWhite added the cairo native Changes to make Cairo Native work with Juno label Sep 16, 2024
Copy link

@xrvdg xrvdg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContractExecutor::new does not do any caching to disk. The compile_and_load, load_compiled_contract and others needs to be reworked with ContractExecutor::save and ContractExecutor::load.

@PearsonWhite
Copy link
Author

ContractExecutor::new does not do any caching to disk. The compile_and_load, load_compiled_contract and others needs to be reworked with ContractExecutor::save and ContractExecutor::load.

ContractExecutor's entrypoints are not public, so we must either:

  1. Make them public. Then we can remove entry_points and Hash from NativeContractClassV1. (It looks like NativeContractClassV1 doesn't use PartialEq for anything). This would make NativeContractClassV1 a nothing more than a wrapper around ContractExecutor.
  2. Create save/load functions for NativeContractClassV1 to save/load class hash. The de/serialization would de/serialize hash, entrypoints, and then use (executor.save/load).

@xrvdg
Copy link

xrvdg commented Sep 18, 2024

ContractExecutor's entrypoints are not public, so we must either:

Those don't have to be public, it's handled by the load/save of ContractExecutor. The NativeContractEntryPoints are there to have a translation for starknet selector to function id. We are in talks with LambdaClass to have the interface different, but for now it is like this.

It looks like NativeContractClassV1 doesn't use PartialEq for anything

The PartialEq follows from the PartialEq on ContractClass which is due to a test.

Copy link

@xrvdg xrvdg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two points to address:

  • caching has no effect if it's always invalidated
  • format the code with cargo fmt.

and the minimum supported Rust version is now 1.80.1.

Comment on lines 294 to 298
let executor = ContractExecutor::load(&library_output_path).unwrap_or({
let executor = ContractExecutor::new(&sierra_program, OptLevel::Default)?;
executor.save(&library_output_path)?;
executor
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always compile and save the contract as the argument to unwrap_or is eagerly evaluated. Use unwrap_or_else instead.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, load and save needlessly borrow the library_output_path.

Copy link
Author

@PearsonWhite PearsonWhite Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always compile and save the contract as the argument to unwrap_or is eagerly evaluated. Use unwrap_or_else instead.

Changed to or_else so I could still use "?" operator. Had to specify the type though since it couldn't figure it out.

Furthermore, load and save needlessly borrow the library_output_path.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cairo native Changes to make Cairo Native work with Juno
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants