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

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

PearsonWhite
Copy link

@PearsonWhite PearsonWhite commented Sep 16, 2024

Corresponding sequencer PR: NethermindEth/sequencer#19

PR: #2156

PearsonWhite added a commit that referenced this pull request Sep 16, 2024
@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.

@PearsonWhite PearsonWhite force-pushed the pwhite/contract_executor branch 2 times, most recently from 2e4d323 to f0baf42 Compare September 18, 2024 14:45
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.

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.

The change itself looks good and I've approved it. But before merging look into the following regression first.

Block 633333 fails with:

execute transaction #289: failed txn 1132083247661400189175640804679018936217786098286704013683829309015708481258 reason: L1 gas bounds (max amount: 1038, max price: 67469438047820) exceed balance (44664767982987702).

@PearsonWhite
Copy link
Author

The change itself looks good and I've approved it. But before merging look into the following regression first.

Block 633333 fails with:

execute transaction #289: failed txn 1132083247661400189175640804679018936217786098286704013683829309015708481258 reason: L1 gas bounds (max amount: 1038, max price: 67469438047820) exceed balance (44664767982987702).

Noted. I think it's fine for now as the gas changes will break things until we have all the starkware changes in our repo.

@PearsonWhite PearsonWhite merged commit 376b663 into native2.8.x-blockifier Sep 23, 2024
0 of 4 checks passed
@PearsonWhite PearsonWhite deleted the pwhite/contract_executor branch September 23, 2024 12:45
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