From fb69e46f15e0dc01182125961c934d2577fb5031 Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 22 Dec 2023 11:52:17 +0100 Subject: [PATCH] runner init --- .gitignore | 22 ++++++++++- runner/Cargo.toml | 12 ++++++ runner/resources/input.json | 20 ++++++++++ runner/src/main.rs | 35 ++++++++++++++++++ src/input_structs.cairo | 2 + src/input_structs/stark_config.cairo | 55 ++++++++++++++++++++++++++++ src/input_structs/stark_proof.cairo | 9 +++++ src/lib.cairo | 7 ++++ 8 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 runner/Cargo.toml create mode 100644 runner/resources/input.json create mode 100644 runner/src/main.rs create mode 100644 src/input_structs.cairo create mode 100644 src/input_structs/stark_config.cairo create mode 100644 src/input_structs/stark_proof.cairo diff --git a/.gitignore b/.gitignore index 73aa31e60..8c2c66468 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,22 @@ -target .snfoundry_cache/ + +# Generated by Cargo +# will have compiled files and executables +**/debug/ +**/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +**/Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Scarb +**/Scarb.lock + +# vscode +**/.vscode/ diff --git a/runner/Cargo.toml b/runner/Cargo.toml new file mode 100644 index 000000000..19b05eaed --- /dev/null +++ b/runner/Cargo.toml @@ -0,0 +1,12 @@ +[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] +anyhow = "1.0.76" +clap = { version = "4.4.11", features = ["derive"] } +serde = { version = "1.0.193", features = ["derive"] } +serde_json = "1.0.108" diff --git a/runner/resources/input.json b/runner/resources/input.json new file mode 100644 index 000000000..95f8baed7 --- /dev/null +++ b/runner/resources/input.json @@ -0,0 +1,20 @@ +[ + [ + [ + [ + 12, + [ + 24, + 9 + ] + ], + [ + 3, + [ + 24, + 9 + ] + ] + ] + ] +] diff --git a/runner/src/main.rs b/runner/src/main.rs new file mode 100644 index 000000000..6aa2d77ce --- /dev/null +++ b/runner/src/main.rs @@ -0,0 +1,35 @@ +use std::fs::File; +use std::io::BufReader; + +use clap::Parser; +use serde_json::Value; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + /// Path to the input file + #[clap(default_value = "resources/input.json")] + path: String, +} + +fn main() -> anyhow::Result<()> { + let args = Cli::parse(); + let file = File::open(args.path)?; + let reader = BufReader::new(file); + + let v: Value = serde_json::from_reader(reader)?; + + let flattened = flatten_recursively(&v); + + println!("{:?}", flattened.collect::>()); + + Ok(()) +} + +fn flatten_recursively(v: &Value) -> Box + '_> { + 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()), + } +} diff --git a/src/input_structs.cairo b/src/input_structs.cairo new file mode 100644 index 000000000..a87612e60 --- /dev/null +++ b/src/input_structs.cairo @@ -0,0 +1,2 @@ +mod stark_config; +mod stark_proof; diff --git a/src/input_structs/stark_config.cairo b/src/input_structs/stark_config.cairo new file mode 100644 index 000000000..1069fcdd2 --- /dev/null +++ b/src/input_structs/stark_config.cairo @@ -0,0 +1,55 @@ +#[derive(Drop)] +struct StarkConfig { + traces: TracesConfig, +// composition: TableCommitmentConfig, +// fri: FriConfig, +// proof_of_work: ProofOfWorkConfig, +// // Log2 of the trace domain size. +// log_trace_domain_size: felt252, +// // Number of queries to the last component, FRI. +// n_queries: felt252, +// // Log2 of the number of cosets composing the evaluation domain, where the coset size is the +// // trace length. +// log_n_cosets: felt252, +// // Number of layers that use a verifier friendly hash in each commitment. +// n_verifier_friendly_commitment_layers: felt252, +} + +#[derive(Drop)] +struct TracesConfig { + original: TableCommitmentConfig, + interaction: TableCommitmentConfig, +} + +#[derive(Drop)] +struct TableCommitmentConfig { + columns: felt252, + vector: VectorCommitmentConfig +} + +#[derive(Drop)] +struct VectorCommitmentConfig { + height: felt252, + verifier_friendly_commitment_layers: felt252, +} + +#[derive(Drop)] +struct FriConfig { + // Log2 of the size of the input layer to FRI. + log_input_size: felt252, + // Number of layers in the FRI. Inner + last layer. + n_layers: felt252, + // Array of size n_layers - 1, each entry is a configuration of a table commitment for the + // corresponding inner layer. + inner_layers: TableCommitmentConfig, + // Array of size n_layers, each entry represents the FRI step size, + // i.e. the number of FRI-foldings between layer i and i+1. + fri_step_sizes: felt252, + log_last_layer_degree_bound: felt252, +} + +#[derive(Drop)] +struct ProofOfWorkConfig { + // Proof of work difficulty (number of bits required to be 0). + n_bits: felt252, +} diff --git a/src/input_structs/stark_proof.cairo b/src/input_structs/stark_proof.cairo new file mode 100644 index 000000000..ec8856238 --- /dev/null +++ b/src/input_structs/stark_proof.cairo @@ -0,0 +1,9 @@ +use cairo_verifier::input_structs::stark_config::StarkConfig; + +#[derive(Drop)] +struct StarkProof { + config: StarkConfig, +// public_input: PublicInput, +// unsent_commitment: StarkUnsentCommitment, +// witness: StarkWitness, +} diff --git a/src/lib.cairo b/src/lib.cairo index 3e032ff8d..6f2ff6e78 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,3 +1,10 @@ mod channel; mod common; +mod input_structs; mod structs; + +use cairo_verifier::input_structs::stark_proof::StarkProof; + +fn main(stark_proof: StarkProof) -> (felt252, felt252) { + (stark_proof.config.traces.original.columns, stark_proof.config.traces.interaction.columns) +}