-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Okm165/scarb_bootloading
Scarb bootloading
- Loading branch information
Showing
19 changed files
with
197 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,5 +168,6 @@ bootloader*.json | |
*.memory | ||
*.trace | ||
|
||
cairo | ||
corelib | ||
# Added by cargo | ||
|
||
/target |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scarb 2.6.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["runner"] | ||
|
||
[workspace.package] | ||
edition = "2021" | ||
version = "0.1.0" | ||
|
||
[workspace.dependencies] | ||
cairo-lang-compiler = { version = "2.6.3", default-features = false } | ||
cairo-lang-sierra = { version = "2.6.3", default-features = false } | ||
cairo-vm = { git = "https://github.com/Okm165/cairo-vm.git", branch = "cairo1-cairo0bootloader"} | ||
cairo1-run = { git = "https://github.com/Okm165/cairo-vm.git", branch = "cairo1-cairo0bootloader"} | ||
clap = { version = "4.3.10", features = ["derive"] } | ||
serde_json = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cairo-vm
deleted from
b72f5a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "example" | ||
version = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "example" | ||
version = "0.1.0" | ||
edition = "2023_11" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "runner" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
cairo-lang-compiler.workspace = true | ||
cairo-lang-sierra.workspace = true | ||
cairo-vm.workspace = true | ||
cairo1-run.workspace = true | ||
clap.workspace = true | ||
serde_json.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use cairo1_run::FuncArg; | ||
use cairo_vm::Felt252; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct FuncArgs(pub Vec<FuncArg>); | ||
|
||
pub fn process_args(value: &str) -> Result<FuncArgs, String> { | ||
if value.is_empty() { | ||
return Ok(FuncArgs::default()); | ||
} | ||
let mut args = Vec::new(); | ||
let mut input = value.split(' '); | ||
while let Some(value) = input.next() { | ||
// First argument in an array | ||
if value.starts_with('[') { | ||
let mut array_arg = | ||
vec![Felt252::from_dec_str(value.strip_prefix('[').unwrap()).unwrap()]; | ||
// Process following args in array | ||
let mut array_end = false; | ||
while !array_end { | ||
if let Some(value) = input.next() { | ||
// Last arg in array | ||
if value.ends_with(']') { | ||
array_arg | ||
.push(Felt252::from_dec_str(value.strip_suffix(']').unwrap()).unwrap()); | ||
array_end = true; | ||
} else { | ||
array_arg.push(Felt252::from_dec_str(value).unwrap()) | ||
} | ||
} | ||
} | ||
// Finalize array | ||
args.push(FuncArg::Array(array_arg)) | ||
} else { | ||
// Single argument | ||
args.push(FuncArg::Single(Felt252::from_dec_str(value).unwrap())) | ||
} | ||
} | ||
Ok(FuncArgs(args)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use args::{process_args, FuncArgs}; | ||
use cairo1_run::Cairo1RunConfig; | ||
use cairo_vm::types::layout_name::LayoutName; | ||
use clap::{Parser, ValueHint}; | ||
use std::path::PathBuf; | ||
pub mod args; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(author, version, about, long_about = None)] | ||
struct Args { | ||
#[clap(long = "sierra_program", value_parser, value_hint=ValueHint::FilePath)] | ||
sierra_program: PathBuf, | ||
#[clap(long = "args", default_value = "", value_parser=process_args)] | ||
args: FuncArgs, | ||
#[clap(long = "cairo_pie_output", value_parser, value_hint=ValueHint::FilePath)] | ||
cairo_pie_output: PathBuf, | ||
} | ||
|
||
fn main() -> std::io::Result<()> { | ||
let args = Args::parse(); | ||
|
||
// Try to parse the file as a sierra program | ||
let file = std::fs::read(&args.sierra_program)?; | ||
let sierra_program: cairo_lang_sierra::program::Program = | ||
match serde_json::from_slice::<cairo_lang_sierra::program::VersionedProgram>(&file) { | ||
Ok(program) => program.into_v1().unwrap().program, | ||
Err(_) => panic!("program parsing failed"), | ||
}; | ||
|
||
let (runner, vm, _return_values, _serialized_output) = cairo1_run::cairo_run_program( | ||
&sierra_program, | ||
Cairo1RunConfig { | ||
args: &args.args.0, | ||
layout: LayoutName::all_cairo, | ||
finalize_builtins: true, | ||
serialize_output: true, | ||
append_return_values: true, | ||
..Default::default() | ||
}, | ||
) | ||
.unwrap(); | ||
|
||
runner | ||
.get_cairo_pie(&vm) | ||
.unwrap() | ||
.write_zip_file(&args.cairo_pie_output) | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[toolchain] | ||
channel = "stable" | ||
profile = "minimal" |