-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3df1300
commit 4fee58d
Showing
8 changed files
with
117 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
scarb build | ||
cd runner | ||
cargo run -- ../target/dev/cairo_verifier.sierra < resources/parserin.txt |
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,3 @@ | ||
fn main() { | ||
lalrpop::process_root().unwrap(); | ||
} |
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 @@ | ||
StarkProof(config=StarkConfig(traces=TracesConfig(original=TableCommitmentConfig(n_columns=12, vector=VectorCommitmentConfig(height=24, n_verifier_friendly_commitment_layers=9)), interaction=TableCommitmentConfig(n_columns=3, vector=VectorCommitmentConfig(height=24, n_verifier_friendly_commitment_layers=9))), composition=TableCommitmentConfig(n_columns=2, vector=VectorCommitmentConfig(height=24, n_verifier_friendly_commitment_layers=9)))) |
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,53 @@ | ||
use std::{ | ||
fmt::Display, | ||
ops::{Deref, DerefMut}, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Expr { | ||
Value(String), | ||
Array(Vec<String>), | ||
} | ||
|
||
impl Display for Expr { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Expr::Value(v) => write!(f, "{}", v), | ||
Expr::Array(v) => write!(f, "{:?}", v), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Exprs(pub Vec<Expr>); | ||
|
||
impl Display for Exprs { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "[")?; | ||
|
||
for (i, expr) in self.iter().enumerate() { | ||
if i != 0 { | ||
write!(f, ", ")?; | ||
} | ||
write!(f, "{}", expr)?; | ||
} | ||
|
||
write!(f, "]")?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Deref for Exprs { | ||
type Target = Vec<Expr>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for Exprs { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.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 |
---|---|---|
@@ -1,35 +1,36 @@ | ||
use std::fs::File; | ||
use std::io::BufReader; | ||
use std::io::{stdin, Read}; | ||
|
||
use cairo_args_runner::{run, WrappedArg}; | ||
use clap::Parser; | ||
use serde_json::Value; | ||
use lalrpop_util::lalrpop_mod; | ||
|
||
mod ast; | ||
|
||
lalrpop_mod!(pub parser); | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
/// Path to the input file | ||
#[clap(default_value = "resources/input.json")] | ||
path: String, | ||
/// Path to compiled sierra file | ||
target: String, | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let args = Cli::parse(); | ||
let file = File::open(args.path)?; | ||
let reader = BufReader::new(file); | ||
let cli = Cli::parse(); | ||
let mut input = String::new(); | ||
stdin().read_to_string(&mut input)?; | ||
|
||
let v: Value = serde_json::from_reader(reader)?; | ||
let parsed = parser::ExprParser::new() | ||
.parse(&input) | ||
.map_err(|e| anyhow::anyhow!("{}", e))?; | ||
let result = format!("{parsed}"); | ||
|
||
let flattened = flatten_recursively(&v); | ||
let target = cli.target; | ||
let function = "main"; | ||
let args: WrappedArg = serde_json::from_str(&result).unwrap(); | ||
|
||
println!("{:?}", flattened.collect::<Vec<u64>>()); | ||
let result = run(&target, &function, &args)?; | ||
|
||
println!("{result:?}"); | ||
Ok(()) | ||
} | ||
|
||
fn flatten_recursively(v: &Value) -> Box<dyn Iterator<Item = u64> + '_> { | ||
match v { | ||
Value::Array(array) => Box::new(array.iter().flat_map(flatten_recursively)), | ||
Value::Number(v) => Box::new(std::iter::once(v.as_u64().unwrap())), | ||
_ => Box::new(std::iter::empty()), | ||
} | ||
} |
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,28 @@ | ||
use crate::ast::{Expr, Exprs}; | ||
|
||
grammar; | ||
|
||
pub Expr: Exprs = { | ||
StructName "()" => Exprs(Vec::new()), | ||
StructName "(" <n:Comma<Arg>> ")" => Exprs(n.iter().flat_map(|x| x.iter().cloned()).collect()), | ||
}; | ||
|
||
Arg: Exprs = { | ||
ArgName "=" <n:Expr> => n, | ||
ArgName "=" <n:Num> => Exprs(vec![Expr::Value(n)]), | ||
ArgName "=" "[" <n:Comma<Num>> "]" => Exprs(vec![Expr::Array(n)]) | ||
}; | ||
|
||
Comma<T>: Vec<T> = { | ||
<mut v:(<T> ",")*> <e:T?> => match e { | ||
None => v, | ||
Some(e) => { | ||
v.push(e); | ||
v | ||
} | ||
} | ||
}; | ||
|
||
StructName: String = <s:r"[A-Z][A-Za-z]+"> => s.to_string(); | ||
ArgName: String = <s:r"[a-z_]+"> => s.to_string(); | ||
Num: String = <s:r"[0-9]+"> => s.to_string(); |
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