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

parser standardized #144

Merged
merged 4 commits into from
Sep 9, 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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo/", rev = "447
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser", rev = "97a04bbee07330311b38d6f4cecfed3acb237626"}
cairo-vm = "0.9.2"
cairo-vm = "1.0.1"
clap = { version = "4.5.2", features = ["derive"] }
itertools = "0.13.0"
num-bigint = "0.4.4"
runner = { path = "runner" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
swiftness_proof_parser = { git = "https://github.com/iosis-tech/swiftness", rev = "a53d65ecbd7acf4611b0d587d815f4e9d4d493ed"}
thiserror = "1.0"
4 changes: 2 additions & 2 deletions examples/starknet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"

[dependencies]
anyhow.workspace = true
cairo-proof-parser.workspace = true
clap.workspace = true
itertools.workspace = true
runner.workspace = true
serde_json.workspace = true
serde.workspace = true
serde.workspace = true
swiftness_proof_parser.workspace = true
20 changes: 9 additions & 11 deletions examples/starknet/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cairo_proof_parser::parse;
use clap::Parser;
use itertools::chain;
use runner::{CairoVersion, VecFelt252};
use runner::{transform::StarkProofExprs, CairoVersion, VecFelt252};
use std::io::{stdin, Read};
use swiftness_proof_parser::parse;

#[derive(Parser)]
#[command(author, version, about)]
Expand All @@ -17,13 +17,13 @@ fn main() -> anyhow::Result<()> {
let mut input = String::new();
stdin().read_to_string(&mut input)?;

let parsed = parse(input)?;

let config: VecFelt252 = serde_json::from_str(&parsed.config.to_string()).unwrap();
let public_input: VecFelt252 = serde_json::from_str(&parsed.public_input.to_string()).unwrap();
let stark_proof: StarkProofExprs = parse(input)?.into();
let config: VecFelt252 = serde_json::from_str(&stark_proof.config.to_string()).unwrap();
let public_input: VecFelt252 =
serde_json::from_str(&stark_proof.public_input.to_string()).unwrap();
let unsent_commitment: VecFelt252 =
serde_json::from_str(&parsed.unsent_commitment.to_string()).unwrap();
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();
serde_json::from_str(&stark_proof.unsent_commitment.to_string()).unwrap();
let witness: VecFelt252 = serde_json::from_str(&stark_proof.witness.to_string()).unwrap();

let proof = chain!(
config.into_iter(),
Expand All @@ -32,9 +32,7 @@ fn main() -> anyhow::Result<()> {
witness.into_iter()
);

let calldata = chain!(proof, vec![cli.cairo_version.into()].into_iter());

let calldata_string = calldata
let calldata_string = chain!(proof, vec![cli.cairo_version.into()].into_iter())
.map(|f| f.to_string())
.collect::<Vec<String>>()
.join(" ");
Expand Down
2 changes: 1 addition & 1 deletion runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ cairo-lang-casm.workspace = true
cairo-lang-runner.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-utils.workspace = true
cairo-proof-parser.workspace = true
cairo-vm.workspace = true
clap.workspace = true
itertools.workspace = true
num-bigint.workspace = true
serde_json.workspace = true
serde.workspace = true
swiftness_proof_parser.workspace = true
thiserror.workspace = true
2 changes: 2 additions & 0 deletions runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod transform;
pub mod vec252;

use cairo_felt::Felt252;
use clap::ValueEnum;
pub use vec252::VecFelt252;
Expand Down
33 changes: 17 additions & 16 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
mod transform;
mod vec252;
use crate::vec252::VecFelt252;

use crate::vec252::VecFelt252;
use cairo_lang_runner::{Arg, ProfilingInfoCollectionConfig, RunResultValue, SierraCasmRunner};
use cairo_lang_sierra::program::VersionedProgram;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use cairo_proof_parser::parse;
use clap::Parser;
use itertools::{chain, Itertools};
use runner::CairoVersion;
use std::{
fs,
io::{stdin, Read},
};
use swiftness_proof_parser::parse;
use transform::StarkProofExprs;

const ENTRYPOINT: &str = "main";

#[derive(Parser)]
#[command(author, version, about)]
Expand All @@ -28,15 +32,14 @@ fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let mut input = String::new();
stdin().read_to_string(&mut input)?;
let parsed = parse(input)?;

let function = "main";

let config: VecFelt252 = serde_json::from_str(&parsed.config.to_string()).unwrap();
let public_input: VecFelt252 = serde_json::from_str(&parsed.public_input.to_string()).unwrap();
let stark_proof: StarkProofExprs = parse(input)?.into();
let config: VecFelt252 = serde_json::from_str(&stark_proof.config.to_string()).unwrap();
let public_input: VecFelt252 =
serde_json::from_str(&stark_proof.public_input.to_string()).unwrap();
let unsent_commitment: VecFelt252 =
serde_json::from_str(&parsed.unsent_commitment.to_string()).unwrap();
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();
serde_json::from_str(&stark_proof.unsent_commitment.to_string()).unwrap();
let witness: VecFelt252 = serde_json::from_str(&stark_proof.witness.to_string()).unwrap();

let proof = chain!(
config.into_iter(),
Expand All @@ -59,16 +62,14 @@ fn main() -> anyhow::Result<()> {
)
.unwrap();

let func = runner.find_function(function).unwrap();
let proof_arg = Arg::Array(proof.into_iter().map(Arg::Value).collect_vec());
let cairo_version_arg = Arg::Value(cli.cairo_version.into());
let args = &[proof_arg, cairo_version_arg];
let func = runner.find_function(ENTRYPOINT).unwrap();
let args = &[
Arg::Array(proof.into_iter().map(Arg::Value).collect_vec()),
Arg::Value(cli.cairo_version.into()),
];
let result = runner
.run_function_with_starknet_context(func, args, Some(u32::MAX as usize), Default::default())
.unwrap();
// let profiling_processor =
// ProfilingInfoProcessor::new(None, sierra_program.program, UnorderedHashMap::default());
// let processed_profiling_info = profiling_processor.process(&result.profiling_info.unwrap());

println!("gas_counter: {}", result.gas_counter.unwrap());
println!("n_steps: {}", result.memory.len());
Expand Down
Loading
Loading