-
Notifications
You must be signed in to change notification settings - Fork 25
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(cairo_native): add a binary crate for cairo_native compilation #1945
Conversation
Artifacts upload triggered. View details here |
74ce4c4
to
66b14ea
Compare
Artifacts upload triggered. View details here |
Artifacts upload triggered. View details here |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1945 +/- ##
===========================================
+ Coverage 40.10% 77.11% +37.00%
===========================================
Files 26 373 +347
Lines 1895 39696 +37801
Branches 1895 39696 +37801
===========================================
+ Hits 760 30610 +29850
- Misses 1100 6808 +5708
- Partials 35 2278 +2243 ☔ View full report in Codecov by Sentry. |
66b14ea
to
32a4e79
Compare
Artifacts upload triggered. View details here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 9 files at r1, all commit messages.
Reviewable status: 4 of 9 files reviewed, 4 unresolved discussions (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/Cargo.toml
line 13 at r2 (raw file):
cairo-native = "0.2.0-alpha.4" clap = { version = "4.5.4", features = ["derive"] } serde_json = "1.0.68"
Update and add a todo to check consistency with the blockifier
Code quote:
cairo-lang-sierra = "2.8.4"
cairo-lang-starknet-classes = "2.8.4"
cairo-native = "0.2.0-alpha.4"
clap = { version = "4.5.4", features = ["derive"] }
serde_json = "1.0.68"
crates/bin/starknet-native-compile/src/test.rs
line 13 at r2 (raw file):
#[test] fn test_save_and_load_contract() {
Add a negative test: a class that cannot be compiled
crates/bin/starknet-native-compile/src/main.rs
line 24 at r2 (raw file):
const DEFAULT_OUTPUT_FILE: &str = "./output.so"; fn main() {
Add todos the restrict time and memory
crates/bin/starknet-native-compile/src/main.rs
line 43 at r2 (raw file):
process::exit(1); }); println!("Compilation successful. Elapsed: {:?}", start.elapsed());
Move into a func and test the func
Code quote:
let args = Args::parse();
let path = args.path;
let output = args.output.unwrap_or_else(|| DEFAULT_OUTPUT_FILE.to_string());
println!("Loading Sierra program from file: {:?}", &path);
let sierra_program = load_sierra_program_from_file(&path);
println!("Compiling Sierra program into file {:?}", &output);
let start = std::time::Instant::now();
let mut contract_executor = AotContractExecutor::new(&sierra_program, OptLevel::default())
.unwrap_or_else(|err| {
eprintln!("Error compiling Sierra program: {}", err);
process::exit(1);
});
contract_executor.save(output.clone()).unwrap_or_else(|err| {
eprintln!("Error saving compiled program: {}", err);
process::exit(1);
});
println!("Compilation successful. Elapsed: {:?}", start.elapsed());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 9 files reviewed, 5 unresolved discussions (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/test_files/faulty_account.sierra.json
line 2 at r2 (raw file):
{ "sierra_program": [
Take erc20 or account instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 9 files reviewed, 6 unresolved discussions (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/src/test.rs
line 10 at r2 (raw file):
const TEST_FILE: &str = "./test_files/faulty_account.sierra.json"; const TEST_OUTPUT: &str = "./target/test_output.so";
Better to remove this
Code quote:
const TEST_OUTPUT: &str = "./target/test_output.so";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 9 files reviewed, 6 unresolved discussions (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/src/test.rs
line 10 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Better to remove this
Try to be consistent with sierra to casm
32a4e79
to
a5e641d
Compare
Artifacts upload triggered. View details here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 9 files at r1, 3 of 3 files at r3, all commit messages.
Reviewable status: 7 of 9 files reviewed, 6 unresolved discussions (waiting on @noaov1 and @Yoni-Starkware)
crates/bin/starknet-native-compile/src/test.rs
line 10 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Try to be consistent with sierra to casm
I moved the testing to the crate that does the sierra to casm compilation in #1998
crates/bin/starknet-native-compile/src/test.rs
line 13 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Add a negative test: a class that cannot be compiled
Added in #1998
a5e641d
to
580e598
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 9 files reviewed, 6 unresolved discussions (waiting on @noaov1 and @Yoni-Starkware)
crates/bin/starknet-native-compile/Cargo.toml
line 13 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Update and add a todo to check consistency with the blockifier
Done.
crates/bin/starknet-native-compile/src/main.rs
line 24 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Add todos the restrict time and memory
Done.
crates/bin/starknet-native-compile/src/main.rs
line 43 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Move into a func and test the func
The testing will be done through starknet_sierra_compile
in #1998.
crates/bin/starknet-native-compile/test_files/faulty_account.sierra.json
line 2 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Take erc20 or account instead
I am using the test contract used in the crate starknet_sierra_compile
.
Artifacts upload triggered. View details here |
There was a problem hiding this 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 r2, 2 of 3 files at r4.
Reviewable status: 7 of 9 files reviewed, 7 unresolved discussions (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/src/main.rs
line 20 at r4 (raw file):
} const DEFAULT_OUTPUT_FILE: &str = "./output.so";
Remove the default value (no reason to do this so far)
Code quote:
/// The output file name (default: output.so).
output: Option<String>,
}
const DEFAULT_OUTPUT_FILE: &str = "./output.so";
crates/bin/starknet-native-compile/build.rs
line 3 at r4 (raw file):
use std::path::Path; // This build script sets the env var CAIRO_NATIVE_RUNTIME_LIBRARY to an absolute path to the runtime library.
Document why this is needed
Code quote:
// This build script sets the env var CAIRO_NATIVE_RUNTIME_LIBRARY to an absolute path to the runtime library.
crates/bin/starknet-native-compile/build.rs
line 17 at r4 (raw file):
let blockifier_path = out_dir .ancestors() .nth(3)
Document why 3
Code quote:
.nth(3)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 7 of 9 files reviewed, 6 unresolved discussions (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/src/utils.rs
line 11 at r4 (raw file):
let raw_contract_class = std::fs::read_to_string(path).unwrap_or_else(|err| { eprintln!("Error reading Sierra file: {}", err); process::exit(1);
Is this the right way to go?
Why not returning Result throughout the code?
Can main return result?
Code quote:
process::exit(1);
crates/bin/starknet-native-compile/src/main.rs
line 28 at r4 (raw file):
let output = args.output.unwrap_or_else(|| DEFAULT_OUTPUT_FILE.to_string()); println!("Loading Sierra program from file: {:?}", &path);
We are not going to see these prints in the blockifier run, right?
Code quote:
println!("Loading Sierra program from file: {:?}", &path);
crates/bin/starknet-native-compile/src/main.rs
line 33 at r4 (raw file):
println!("Compiling Sierra program into file {:?}", &output); let start = std::time::Instant::now(); let mut contract_executor = AotContractExecutor::new(&sierra_program, OptLevel::default())
What is this? what are the options? do we want to pass argument for it?
Code quote:
OptLevel::default()
Artifacts upload triggered. View details here |
5cd6e57
to
264bf17
Compare
Artifacts upload triggered. View details here |
Benchmark movements: |
There was a problem hiding this 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 r5, 1 of 2 files at r6.
Reviewable status: 6 of 9 files reviewed, 6 unresolved discussions (waiting on @avi-starkware and @noaov1)
Previously, Yoni-Starkware (Yoni) wrote…
These are the options. It indicates the level of optimization the compiler should employ while compiling code. I am not sure what impact this config has, so I just put it on default. Nethermind did the same in their PRs. The According to ChatGPT, the higher the optimization the longer the compilation time, but the performance of the compiled code should improve, though it could increase the binary file size and its memory usage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 of 9 files reviewed, 6 unresolved discussions (waiting on @noaov1 and @Yoni-Starkware)
crates/bin/starknet-native-compile/src/main.rs
line 20 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Remove the default value (no reason to do this so far)
Done.
crates/bin/starknet-native-compile/src/main.rs
line 28 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
We are not going to see these prints in the blockifier run, right?
They will appear, unfortunately...
They were used for debugging. I removed all of them.
crates/bin/starknet-native-compile/src/utils.rs
line 11 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Is this the right way to go?
Why not returning Result throughout the code?
Can main return result?
Because it is a binary running in another process. It can only output stdout
and stderr
.
crates/bin/starknet-native-compile/build.rs
line 3 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Document why this is needed
I removed the file. The env var is needed to run the compiled binary, not to build it. It would make more sense to set it correctly in the crate that uses the compiled binary.
crates/bin/starknet-native-compile/build.rs
line 17 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Document why 3
I removed the build.rs
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 9 files at r1, 1 of 2 files at r5, 1 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @avi-starkware and @noaov1)
crates/bin/starknet-native-compile/src/main.rs
line 33 at r4 (raw file):
Previously, avi-starkware wrote…
These are the options.
It indicates the level of optimization the compiler should employ while compiling code. I am not sure what impact this config has, so I just put it on default. Nethermind did the same in their PRs.
The
OptLevel
is plugged into LLVM here.According to ChatGPT, the higher the optimization the longer the compilation time, but the performance of the compiled code should improve, though it could increase the binary file size and its memory usage.
Add a todo to configure the opt level after testing it. It might speed things up
264bf17
to
874d900
Compare
Artifacts upload triggered. View details here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 7 of 9 files reviewed, 1 unresolved discussion (waiting on @noaov1 and @Yoni-Starkware)
crates/bin/starknet-native-compile/src/main.rs
line 33 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Add a todo to configure the opt level after testing it. It might speed things up
Done.
There was a problem hiding this 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 r8, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @noaov1)
874d900
to
fa12a02
Compare
Artifacts upload triggered. View details here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @noaov1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @noaov1)
No description provided.