From 1894707d01b84acd912eb9c9601974443c847c69 Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 30 Dec 2023 18:46:51 +0100 Subject: [PATCH 1/8] new runner version --- Scarb.toml | 3 --- run.sh | 2 +- runner/Cargo.toml | 2 +- runner/src/ast.rs | 2 +- runner/src/main.rs | 6 +++--- src/input_structs/stark_config.cairo | 12 ++++++------ src/input_structs/stark_proof.cairo | 2 +- src/lib.cairo | 5 ++++- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index de3a004cb..73d345695 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,6 +1,3 @@ [package] name = "cairo_verifier" version = "0.1.0" - -[lib] -sierra-text = true diff --git a/run.sh b/run.sh index ccb737935..0070727a7 100755 --- a/run.sh +++ b/run.sh @@ -2,4 +2,4 @@ scarb build cd runner -cargo run --release -- ../target/dev/cairo_verifier.sierra < resources/parserin.txt +cargo run --release -- ../target/dev/cairo_verifier.sierra.json < resources/parserin.txt diff --git a/runner/Cargo.toml b/runner/Cargo.toml index 707a80401..80145e467 100644 --- a/runner/Cargo.toml +++ b/runner/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0.76" -cairo-args-runner = "0.1.1" +cairo-args-runner = "1.0.0" clap = { version = "4.4.11", features = ["derive"] } lalrpop-util = { version = "0.20.0", features = ["lexer", "unicode"] } serde = { version = "1.0.193", features = ["derive"] } diff --git a/runner/src/ast.rs b/runner/src/ast.rs index 9085ee2dc..9266409c6 100644 --- a/runner/src/ast.rs +++ b/runner/src/ast.rs @@ -26,7 +26,7 @@ impl Display for Expr { write!(f, "]")?; Ok(()) - }, + } } } } diff --git a/runner/src/main.rs b/runner/src/main.rs index 2da2c038d..b116c60e2 100644 --- a/runner/src/main.rs +++ b/runner/src/main.rs @@ -1,6 +1,6 @@ use std::io::{stdin, Read}; -use cairo_args_runner::{run, WrappedArg}; +use cairo_args_runner::{run, Arg, VecFelt252}; use clap::Parser; use lalrpop_util::lalrpop_mod; @@ -27,9 +27,9 @@ fn main() -> anyhow::Result<()> { let target = cli.target; let function = "main"; - let args: WrappedArg = serde_json::from_str(&result).unwrap(); + let args: VecFelt252 = serde_json::from_str(&result).unwrap(); - let result = run(&target, &function, &args)?; + let result = run(&target, &function, &[Arg::Array(args.to_vec())])?; println!("{result:?}"); Ok(()) diff --git a/src/input_structs/stark_config.cairo b/src/input_structs/stark_config.cairo index 4e4c27c67..147f4e474 100644 --- a/src/input_structs/stark_config.cairo +++ b/src/input_structs/stark_config.cairo @@ -1,4 +1,4 @@ -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] struct StarkConfig { traces: TracesConfig, composition: TableCommitmentConfig, @@ -15,25 +15,25 @@ struct StarkConfig { // n_verifier_friendly_commitment_layers: felt252, } -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] struct TracesConfig { original: TableCommitmentConfig, interaction: TableCommitmentConfig, } -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] struct TableCommitmentConfig { columns: felt252, vector: VectorCommitmentConfig } -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] struct VectorCommitmentConfig { height: felt252, verifier_friendly_commitment_layers: felt252, } -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] struct FriConfig { // Log2 of the size of the input layer to FRI. log_input_size: felt252, @@ -48,7 +48,7 @@ struct FriConfig { log_last_layer_degree_bound: felt252, } -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] 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 index 01919b43b..f6c969b43 100644 --- a/src/input_structs/stark_proof.cairo +++ b/src/input_structs/stark_proof.cairo @@ -1,6 +1,6 @@ use cairo_verifier::input_structs::stark_config::StarkConfig; -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Serde)] struct StarkProof { config: StarkConfig, // public_input: PublicInput, diff --git a/src/lib.cairo b/src/lib.cairo index 5ba23f5ea..c16bc4bb8 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -8,6 +8,9 @@ mod vector_commitment; use cairo_verifier::input_structs::stark_proof::StarkProof; -fn main(stark_proof: StarkProof) -> (felt252, felt252) { + +fn main(x: Array) -> (felt252, felt252) { + let mut x_span = x.span(); + let stark_proof: StarkProof = Serde::deserialize(ref x_span).unwrap(); (stark_proof.config.traces.original.columns, stark_proof.config.traces.interaction.columns) } From e4a3a6f808d2cbf3ed6e76dba9224a1d3f6e54f4 Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 30 Dec 2023 18:48:09 +0100 Subject: [PATCH 2/8] apply clippy --- runner/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/src/main.rs b/runner/src/main.rs index b116c60e2..6ff865bae 100644 --- a/runner/src/main.rs +++ b/runner/src/main.rs @@ -29,7 +29,7 @@ fn main() -> anyhow::Result<()> { let function = "main"; let args: VecFelt252 = serde_json::from_str(&result).unwrap(); - let result = run(&target, &function, &[Arg::Array(args.to_vec())])?; + let result = run(&target, function, &[Arg::Array(args.to_vec())])?; println!("{result:?}"); Ok(()) From 20781d72d22b1a04af5628621e7ee22f38a0687c Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 30 Dec 2023 19:16:00 +0100 Subject: [PATCH 3/8] StarkConfig parsed --- src/input_structs/stark_config.cairo | 38 ++++++++++++++-------------- src/input_structs/stark_proof.cairo | 2 +- src/lib.cairo | 3 +-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/input_structs/stark_config.cairo b/src/input_structs/stark_config.cairo index 147f4e474..92b6e4192 100644 --- a/src/input_structs/stark_config.cairo +++ b/src/input_structs/stark_config.cairo @@ -1,39 +1,39 @@ -#[derive(Copy, Drop, Serde)] +#[derive(Drop, Serde)] 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, + 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(Copy, Drop, Serde)] +#[derive(Drop, Serde)] struct TracesConfig { original: TableCommitmentConfig, interaction: TableCommitmentConfig, } -#[derive(Copy, Drop, Serde)] +#[derive(Drop, Serde)] struct TableCommitmentConfig { columns: felt252, vector: VectorCommitmentConfig } -#[derive(Copy, Drop, Serde)] +#[derive(Drop, Serde)] struct VectorCommitmentConfig { height: felt252, verifier_friendly_commitment_layers: felt252, } -#[derive(Copy, Drop, Serde)] +#[derive(Drop, Serde)] struct FriConfig { // Log2 of the size of the input layer to FRI. log_input_size: felt252, @@ -41,14 +41,14 @@ struct FriConfig { 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, + inner_layers: Array, // 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, + fri_step_sizes: Array, log_last_layer_degree_bound: felt252, } -#[derive(Copy, Drop, Serde)] +#[derive(Drop, Serde)] 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 index f6c969b43..f4f3fa55c 100644 --- a/src/input_structs/stark_proof.cairo +++ b/src/input_structs/stark_proof.cairo @@ -1,6 +1,6 @@ use cairo_verifier::input_structs::stark_config::StarkConfig; -#[derive(Copy, Drop, Serde)] +#[derive(Drop, Serde)] struct StarkProof { config: StarkConfig, // public_input: PublicInput, diff --git a/src/lib.cairo b/src/lib.cairo index c16bc4bb8..c1d190018 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -9,8 +9,7 @@ mod vector_commitment; use cairo_verifier::input_structs::stark_proof::StarkProof; -fn main(x: Array) -> (felt252, felt252) { +fn main(x: Array) { let mut x_span = x.span(); let stark_proof: StarkProof = Serde::deserialize(ref x_span).unwrap(); - (stark_proof.config.traces.original.columns, stark_proof.config.traces.interaction.columns) } From 0d39ab8d39820093f6a58a4aa7f11f3e4a51c288 Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 30 Dec 2023 20:50:17 +0100 Subject: [PATCH 4/8] PublicInput --- runner/src/ast.rs | 2 +- runner/src/main.rs | 2 +- src/input_structs.cairo | 1 + src/input_structs/public_input.cairo | 16 ++++++++++++++++ src/input_structs/stark_proof.cairo | 4 +++- 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/input_structs/public_input.cairo diff --git a/runner/src/ast.rs b/runner/src/ast.rs index 9266409c6..a56e8db19 100644 --- a/runner/src/ast.rs +++ b/runner/src/ast.rs @@ -12,7 +12,7 @@ pub enum Expr { impl Display for Expr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Expr::Value(v) => write!(f, "{v}"), + Expr::Value(v) => write!(f, "\"{v}\""), Expr::Array(v) => { write!(f, "[")?; diff --git a/runner/src/main.rs b/runner/src/main.rs index 6ff865bae..5f6c7dbc4 100644 --- a/runner/src/main.rs +++ b/runner/src/main.rs @@ -23,7 +23,7 @@ fn main() -> anyhow::Result<()> { let parsed = parser::CairoParserOutputParser::new() .parse(&input) .map_err(|e| anyhow::anyhow!("{}", e))?; - let result = format!("{parsed}"); + let result = parsed.to_string(); let target = cli.target; let function = "main"; diff --git a/src/input_structs.cairo b/src/input_structs.cairo index a87612e60..6257aea34 100644 --- a/src/input_structs.cairo +++ b/src/input_structs.cairo @@ -1,2 +1,3 @@ +mod public_input; mod stark_config; mod stark_proof; diff --git a/src/input_structs/public_input.cairo b/src/input_structs/public_input.cairo new file mode 100644 index 000000000..63250014d --- /dev/null +++ b/src/input_structs/public_input.cairo @@ -0,0 +1,16 @@ +#[derive(Drop, Serde)] +struct PublicInput { + log_n_steps: felt252, + range_check_min: felt252, + range_check_max: felt252, + layout: felt252, + dynamic_params: Array, + n_segments: felt252, + segments: Array, + padding_addr: felt252, + padding_value: felt252, + main_page_len: felt252, + main_page: Array, + n_continuous_pages: felt252, + continuous_page_headers: Array, +} diff --git a/src/input_structs/stark_proof.cairo b/src/input_structs/stark_proof.cairo index f4f3fa55c..81ab05ae0 100644 --- a/src/input_structs/stark_proof.cairo +++ b/src/input_structs/stark_proof.cairo @@ -1,9 +1,11 @@ use cairo_verifier::input_structs::stark_config::StarkConfig; +use cairo_verifier::input_structs::public_input::PublicInput; + #[derive(Drop, Serde)] struct StarkProof { config: StarkConfig, -// public_input: PublicInput, + public_input: PublicInput, // unsent_commitment: StarkUnsentCommitment, // witness: StarkWitness, } From 00c970dcd17cea881cc24bd2b887000681e94c38 Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 30 Dec 2023 22:37:21 +0100 Subject: [PATCH 5/8] StarkUnsentCommitment --- src/input_structs.cairo | 1 + src/input_structs/stark_proof.cairo | 8 +++--- .../stark_unsent_commitment.cairo | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/input_structs/stark_unsent_commitment.cairo diff --git a/src/input_structs.cairo b/src/input_structs.cairo index 6257aea34..73f27c3a0 100644 --- a/src/input_structs.cairo +++ b/src/input_structs.cairo @@ -1,3 +1,4 @@ mod public_input; mod stark_config; mod stark_proof; +mod stark_unsent_commitment; diff --git a/src/input_structs/stark_proof.cairo b/src/input_structs/stark_proof.cairo index 81ab05ae0..73363d4af 100644 --- a/src/input_structs/stark_proof.cairo +++ b/src/input_structs/stark_proof.cairo @@ -1,11 +1,13 @@ -use cairo_verifier::input_structs::stark_config::StarkConfig; -use cairo_verifier::input_structs::public_input::PublicInput; +use cairo_verifier::input_structs::{ + stark_config::StarkConfig, public_input::PublicInput, + stark_unsent_commitment::StarkUnsentCommitment, +}; #[derive(Drop, Serde)] struct StarkProof { config: StarkConfig, public_input: PublicInput, -// unsent_commitment: StarkUnsentCommitment, + unsent_commitment: StarkUnsentCommitment, // witness: StarkWitness, } diff --git a/src/input_structs/stark_unsent_commitment.cairo b/src/input_structs/stark_unsent_commitment.cairo new file mode 100644 index 000000000..737c8991b --- /dev/null +++ b/src/input_structs/stark_unsent_commitment.cairo @@ -0,0 +1,25 @@ +#[derive(Drop, Serde)] +struct StarkUnsentCommitment { + traces: TracesUnsentCommitment, + composition: felt252, + oods_values: Array, + fri: FriUnsentCommitment, + proof_of_work: ProofOfWorkUnsentCommitment, +} + +#[derive(Drop, Serde)] +struct TracesUnsentCommitment { + original: felt252, + interaction: felt252, +} + +#[derive(Drop, Serde)] +struct FriUnsentCommitment { + inner_layers: Array, + last_layer_coefficients: Array, +} + +#[derive(Drop, Serde)] +struct ProofOfWorkUnsentCommitment { + nonce: felt252, +} From d13b6b1d97aed4f860806e2499eb569e2e60f32c Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 30 Dec 2023 22:54:40 +0100 Subject: [PATCH 6/8] partial StarkWitness --- src/input_structs.cairo | 1 + src/input_structs/stark_proof.cairo | 4 +-- src/input_structs/stark_witness.cairo | 41 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/input_structs/stark_witness.cairo diff --git a/src/input_structs.cairo b/src/input_structs.cairo index 73f27c3a0..f0e05a778 100644 --- a/src/input_structs.cairo +++ b/src/input_structs.cairo @@ -2,3 +2,4 @@ mod public_input; mod stark_config; mod stark_proof; mod stark_unsent_commitment; +mod stark_witness; diff --git a/src/input_structs/stark_proof.cairo b/src/input_structs/stark_proof.cairo index 73363d4af..b81942347 100644 --- a/src/input_structs/stark_proof.cairo +++ b/src/input_structs/stark_proof.cairo @@ -1,6 +1,6 @@ use cairo_verifier::input_structs::{ stark_config::StarkConfig, public_input::PublicInput, - stark_unsent_commitment::StarkUnsentCommitment, + stark_unsent_commitment::StarkUnsentCommitment, stark_witness::StarkWitness, }; @@ -9,5 +9,5 @@ struct StarkProof { config: StarkConfig, public_input: PublicInput, unsent_commitment: StarkUnsentCommitment, -// witness: StarkWitness, + witness: StarkWitness, } diff --git a/src/input_structs/stark_witness.cairo b/src/input_structs/stark_witness.cairo new file mode 100644 index 000000000..627d755e4 --- /dev/null +++ b/src/input_structs/stark_witness.cairo @@ -0,0 +1,41 @@ +#[derive(Drop, Serde)] +struct StarkWitness { + traces_decommitment: TracesDecommitment, + traces_witness: TracesWitness, + interaction: TableCommitmentWitness, + composition_decommitment: TableDecommitment, + composition_witness: TableCommitmentWitness, +} + +#[derive(Drop, Serde)] +struct TracesDecommitment { + original: TableDecommitment, + interaction: TableDecommitment, +} + +#[derive(Drop, Serde)] +struct TableDecommitment { + n_values: felt252, + values: Array, +} + +#[derive(Drop, Serde)] +struct TracesWitness { + original: TableCommitmentWitness, +} + +#[derive(Drop, Serde)] +struct TableCommitmentWitness { + vector: VectorCommitmentWitness, +} + +#[derive(Drop, Serde)] +struct VectorCommitmentWitness { + n_authentications: felt252, + authentications: Array, +} + +#[derive(Drop, Serde)] +struct FriWitness { + layers: Array>, +} From deddf85dbc9f8f2a8ab4fd7e84036f835a780b5c Mon Sep 17 00:00:00 2001 From: Neo Date: Sun, 31 Dec 2023 11:25:57 +0100 Subject: [PATCH 7/8] FriWitness --- runner/src/parser.lalrpop | 10 ++++++++++ src/input_structs/stark_witness.cairo | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/runner/src/parser.lalrpop b/runner/src/parser.lalrpop index daa655768..c7e825989 100644 --- a/runner/src/parser.lalrpop +++ b/runner/src/parser.lalrpop @@ -11,6 +11,7 @@ CairoParserOutputInner: Exprs = { => Exprs(vec![Expr::Value(n)]), "[" > "]" => Exprs(vec![Expr::Array(n.iter().flat_map(|x| x.iter().cloned()).collect())]), StructName "()" => Exprs(Vec::new()), + "FriWitness" "(" "layers=" "[" > "]" ")" => Exprs(vec![Expr::Array(n.iter().flat_map(|x| x.iter().cloned()).collect())]), StructName "(" > ")" => Exprs(n.iter().flat_map(|x| x.iter().cloned()).collect()), }; @@ -18,6 +19,15 @@ Arg: Exprs = { ArgName "=" => n, }; +FriWitnessLayers: Exprs = { + "," "[" > "]" => Exprs(vec![Expr::Value(n)].into_iter().chain(a.into_iter().map(|x| Expr::Value(x))).collect()), + StructName "(" ArgName "=" StructName "(" ")" ")" => n, +}; + +FriWitnessLayersArgs: Exprs = { + ArgName "=" "," ArgName "=" "[" > "]" => Exprs(vec![Expr::Value(n)].into_iter().chain(a.into_iter().map(|x| Expr::Value(x))).collect()), +}; + Comma: Vec = { ",")*> => match e { None => v, diff --git a/src/input_structs/stark_witness.cairo b/src/input_structs/stark_witness.cairo index 627d755e4..845addcbd 100644 --- a/src/input_structs/stark_witness.cairo +++ b/src/input_structs/stark_witness.cairo @@ -5,6 +5,7 @@ struct StarkWitness { interaction: TableCommitmentWitness, composition_decommitment: TableDecommitment, composition_witness: TableCommitmentWitness, + fri_witness: FriWitness, } #[derive(Drop, Serde)] @@ -37,5 +38,5 @@ struct VectorCommitmentWitness { #[derive(Drop, Serde)] struct FriWitness { - layers: Array>, + layers: Array, } From 87fd1e2d1ff24e209f4bea943c5b03a1840f907a Mon Sep 17 00:00:00 2001 From: Neo Date: Sun, 31 Dec 2023 11:48:55 +0100 Subject: [PATCH 8/8] clippy --- runner/src/parser.lalrpop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runner/src/parser.lalrpop b/runner/src/parser.lalrpop index c7e825989..f63f3199e 100644 --- a/runner/src/parser.lalrpop +++ b/runner/src/parser.lalrpop @@ -20,12 +20,12 @@ Arg: Exprs = { }; FriWitnessLayers: Exprs = { - "," "[" > "]" => Exprs(vec![Expr::Value(n)].into_iter().chain(a.into_iter().map(|x| Expr::Value(x))).collect()), + "," "[" > "]" => Exprs(vec![Expr::Value(n)].into_iter().chain(a.into_iter().map(Expr::Value)).collect()), StructName "(" ArgName "=" StructName "(" ")" ")" => n, }; FriWitnessLayersArgs: Exprs = { - ArgName "=" "," ArgName "=" "[" > "]" => Exprs(vec![Expr::Value(n)].into_iter().chain(a.into_iter().map(|x| Expr::Value(x))).collect()), + ArgName "=" "," ArgName "=" "[" > "]" => Exprs(vec![Expr::Value(n)].into_iter().chain(a.into_iter().map(Expr::Value)).collect()), }; Comma: Vec = {