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

Add option to pass Sierra programs to cairo1-run #1719

Merged
merged 15 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: `cairo1-run` accepts Sierra programs [#1719](https://github.com/lambdaclass/cairo-vm/pull/1719)

* refactor(BREAKING): Use `BuiltinName` enum instead of string representation [#1722](https://github.com/lambdaclass/cairo-vm/pull/1722)
* `BuiltinName` moved from `crate::serde::deserialize_program` module to `crate::types::builtin_name`.
* Implement `BuiltinName` methods `to_str`, `to_str_with_suffix`, `from_str` & `from_str_with_suffix`.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cairo1-run/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords.workspace = true

[dependencies]
cairo-vm = {workspace = true, features = ["std", "cairo-1-hints", "clap"]}
serde_json = { workspace = true }

cairo-lang-sierra-type-size = { version = "2.5.4", default-features = false }
cairo-lang-sierra-ap-change = { version = "2.5.4", default-features = false }
Expand Down
14 changes: 13 additions & 1 deletion cairo1-run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Now that you have the dependencies necessary to run the tests, you can run:
make test
```

To execute a cairo 1 program
To execute a Cairo 1 program (either as Cairo 1 source file or Sierra)

```bash
cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo
Expand Down Expand Up @@ -68,3 +68,15 @@ The cairo1-run cli supports the following optional arguments:
* `--cairo_pie_output <CAIRO_PIE_OUTPUT>`: Receives the name of a file and outputs the Cairo PIE into it. Can only be used if proof_mode, is not enabled.

* `--append_return_values`: Adds extra instructions to the program in order to append the return values to the output builtin's segment. This is the default behaviour for proof_mode.

# Running scarb projects

First compile your project running `scarb build`


Then run the compiled project's sierra file located at `project_name/target/project_name.sierra.json`

Example:
```bash
cargo run path-to-project/target/project_name.sierra.json
```
19 changes: 13 additions & 6 deletions cairo1-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,21 @@
append_return_values: args.append_return_values,
};

let compiler_config = CompilerConfig {
replace_ids: true,
..CompilerConfig::default()
// Try to parse the file as a sierra program
let file = std::fs::read(&args.filename)?;
let sierra_program = match serde_json::from_slice(&file) {
Ok(program) => program,

Check warning on line 211 in cairo1-run/src/main.rs

View check run for this annotation

Codecov / codecov/patch

cairo1-run/src/main.rs#L211

Added line #L211 was not covered by tests
Err(_) => {
// If it fails, try to compile it as a cairo program
let compiler_config = CompilerConfig {
replace_ids: true,
..CompilerConfig::default()
};
compile_cairo_project_at_path(&args.filename, compiler_config)
.map_err(|err| Error::SierraCompilation(err.to_string()))?
}
};

let sierra_program = compile_cairo_project_at_path(&args.filename, compiler_config)
.map_err(|err| Error::SierraCompilation(err.to_string()))?;

let (runner, vm, _, serialized_output) =
cairo_run::cairo_run_program(&sierra_program, cairo_run_config)?;

Expand Down
Loading