diff --git a/benches/src/main.rs b/benches/src/main.rs index 9a0884d85..541e73a71 100644 --- a/benches/src/main.rs +++ b/benches/src/main.rs @@ -30,7 +30,7 @@ fn main() -> anyhow::Result<()> { let sierra_program = serde_json::from_str::(&fs::read_to_string(cli.target)?)?.into_v1()?; - BENCH_FUNCTION_LIST.into_iter().for_each(|f_name| { + BENCH_FUNCTION_LIST.iter().for_each(|f_name| { let result = bench(sierra_program.program.to_owned(), f_name).unwrap(); println!("Function: {f_name}"); diff --git a/examples/starknet/Cargo.toml b/examples/starknet/Cargo.toml index c3b1fd794..b940f6f01 100644 --- a/examples/starknet/Cargo.toml +++ b/examples/starknet/Cargo.toml @@ -6,11 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1" -cairo-felt = "0.9" -cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser" } -itertools = "0.12.0" -num-bigint = "0.4" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -thiserror = "1.0" \ No newline at end of file +anyhow.workspace = true +cairo-args-runner.workspace = true +clap.workspace = true +cairo-proof-parser.workspace = true +serde.workspace = true +serde_json.workspace = true \ No newline at end of file diff --git a/examples/starknet/src/main.rs b/examples/starknet/src/main.rs index aab6df2e7..679885d20 100644 --- a/examples/starknet/src/main.rs +++ b/examples/starknet/src/main.rs @@ -1,29 +1,13 @@ -mod vec252; -use crate::vec252::VecFelt252; +use cairo_args_runner::VecFelt252; use cairo_proof_parser::parse; -use itertools::{chain, Itertools}; -use std::{ - io::{stdin, Read}, -}; +use std::io::{stdin, Read}; 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())?; - let public_input: VecFelt252 = serde_json::from_str(&parsed.public_input.to_string())?; - let unsent_commitment: VecFelt252 = - serde_json::from_str(&parsed.unsent_commitment.to_string())?; - let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string())?; - - let proof = chain!( - config.to_vec(), - public_input.to_vec(), - unsent_commitment.to_vec(), - witness.to_vec() - ) - .collect_vec(); + let exprs = parse(input)?.to_string(); + let proof: VecFelt252 = serde_json::from_str(&exprs).unwrap(); let proof_string = proof .iter() diff --git a/examples/starknet/src/vec252.rs b/examples/starknet/src/vec252.rs deleted file mode 100644 index 33444d891..000000000 --- a/examples/starknet/src/vec252.rs +++ /dev/null @@ -1,118 +0,0 @@ -use std::{ops::Deref, str::FromStr}; - -use cairo_felt::Felt252; -use serde::{de::Visitor, Deserialize}; -use serde_json::Value; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum VecFelt252Error { - #[error("failed to parse number: {0}")] - NumberParseError(#[from] std::num::ParseIntError), - #[error("failed to parse bigint: {0}")] - BigIntParseError(#[from] num_bigint::ParseBigIntError), - #[error("number out of range")] - NumberOutOfRange, -} - -/// `VecFelt252` is a wrapper around a vector of `Arg`. -/// -/// It provides convenience methods for working with a vector of `Arg` and implements -/// `Deref` to allow it to be treated like a vector of `Arg`. -#[derive(Debug, Clone)] -pub struct VecFelt252(Vec); - -impl VecFelt252 { - /// Creates a new `VecFelt252` from a vector of `Arg`. - /// - /// # Arguments - /// - /// * `args` - A vector of `Arg`. - /// - /// # Returns - /// - /// * `VecFelt252` - A new `VecFelt252` instance. - #[must_use] - pub fn new(args: Vec) -> Self { - Self(args) - } -} - -impl Deref for VecFelt252 { - type Target = Vec; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl From for Vec { - fn from(args: VecFelt252) -> Self { - args.0 - } -} - -impl From> for VecFelt252 { - fn from(args: Vec) -> Self { - Self(args) - } -} - -impl VecFelt252 { - fn visit_seq_helper(seq: &[Value]) -> Result { - let iterator = seq.iter(); - let mut args = Vec::new(); - - for arg in iterator { - match arg { - Value::Number(n) => { - let n = n.as_u64().ok_or(VecFelt252Error::NumberOutOfRange)?; - args.push(Felt252::from(n)); - } - Value::String(n) => { - let n = num_bigint::BigUint::from_str(n)?; - args.push(Felt252::from_bytes_be(&n.to_bytes_be())); - } - Value::Array(a) => { - args.push(Felt252::from(a.len())); - let result = Self::visit_seq_helper(a)?; - args.extend(result.0); - } - _ => (), - } - } - - Ok(Self::new(args)) - } -} - -impl<'de> Visitor<'de> for VecFelt252 { - type Value = VecFelt252; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("a list of arguments") - } - fn visit_seq(self, mut seq: A) -> Result - where - A: serde::de::SeqAccess<'de>, - { - let mut args = Vec::new(); - while let Some(arg) = seq.next_element()? { - match arg { - Value::Number(n) => args.push(Value::Number(n)), - Value::String(n) => args.push(Value::String(n)), - Value::Array(a) => args.push(Value::Array(a)), - _ => return Err(serde::de::Error::custom("Invalid type")), - } - } - - Self::visit_seq_helper(&args).map_err(|e| serde::de::Error::custom(e.to_string())) - } -} - -impl<'de> Deserialize<'de> for VecFelt252 { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - deserializer.deserialize_seq(VecFelt252(Vec::new())) - } -} diff --git a/runner/src/main.rs b/runner/src/main.rs index 283a283dd..858851621 100644 --- a/runner/src/main.rs +++ b/runner/src/main.rs @@ -1,9 +1,7 @@ -use std::io::{stdin, Read}; - -use cairo_args_runner::{Arg, Felt252, VecFelt252}; use clap::Parser; - +use std::io::{stdin, Read}; use cairo_proof_parser::parse; +use cairo_args_runner::{Arg, Felt252, VecFelt252}; #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -25,7 +23,6 @@ fn main() -> anyhow::Result<()> { } fn run(parsed: String, target: String) -> anyhow::Result> { - let target = target; let function = "main"; let args: VecFelt252 = serde_json::from_str(&parsed).unwrap(); Ok(cairo_args_runner::run(