Skip to content

Commit

Permalink
running pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Dec 25, 2023
1 parent 3df1300 commit 4fee58d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 21 deletions.
5 changes: 5 additions & 0 deletions run.sh
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
5 changes: 5 additions & 0 deletions runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ edition = "2021"

[dependencies]
anyhow = "1.0.76"
cairo-args-runner = "0.1.1"
clap = { version = "4.4.11", features = ["derive"] }
lalrpop-util = { version = "0.20.0", features = ["lexer", "unicode"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"

[build-dependencies]
lalrpop = "0.20.0"
3 changes: 3 additions & 0 deletions runner/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
lalrpop::process_root().unwrap();
}
1 change: 1 addition & 0 deletions runner/resources/parserin.txt
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))))
53 changes: 53 additions & 0 deletions runner/src/ast.rs
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
}
}
41 changes: 21 additions & 20 deletions runner/src/main.rs
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()),
}
}
28 changes: 28 additions & 0 deletions runner/src/parser.lalrpop
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();
2 changes: 1 addition & 1 deletion src/input_structs/stark_config.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[derive(Copy, Drop)]
struct StarkConfig {
traces: TracesConfig,
// composition: TableCommitmentConfig,
composition: TableCommitmentConfig,
// fri: FriConfig,
// proof_of_work: ProofOfWorkConfig,
// // Log2 of the trace domain size.
Expand Down

0 comments on commit 4fee58d

Please sign in to comment.