From 3ffb363b0dd1608d182a4d7204d0199bcb495436 Mon Sep 17 00:00:00 2001 From: Federico Carrone Date: Thu, 13 Jul 2023 15:00:46 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0512563f..c4038daa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Starknet Stack Prover Lambdaworks -Disclaimer: This prover is still in development and may contain bugs. It is not intended to be used in production yet. We're a few weeks away to have it ready. +This prover is still in development and may contain bugs. It is not intended to be used in production yet. We're a few weeks away to have it ready. +We expect to have something working in a good state by mid August 2023. ## Main building blocks From c75b7ba9a159514a19fef1ae62beece35ef3e901 Mon Sep 17 00:00:00 2001 From: Mauro Toscano <12560266+MauroToscano@users.noreply.github.com> Date: Fri, 14 Jul 2023 07:28:54 -0300 Subject: [PATCH 2/3] Verify security level (#187) * Remove n so it captures smaller changes * Fix issue with queries * Restore change in benchmark * Fmt --- src/starks/verifier.rs | 5 +++++ tests/integration_tests.rs | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/starks/verifier.rs b/src/starks/verifier.rs index 6beb4643..d99d2c90 100644 --- a/src/starks/verifier.rs +++ b/src/starks/verifier.rs @@ -566,6 +566,11 @@ where A: AIR, FieldElement: ByteConversion, { + // Verify there are enough queries + if proof.query_list.len() < proof_options.fri_number_of_queries { + return false; + } + #[cfg(feature = "instruments")] println!("- Started step 1: Recover challenges"); #[cfg(feature = "instruments")] diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index b501e470..9b92b5a0 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -25,7 +25,7 @@ use lambdaworks_stark::{ quadratic_air::{self, QuadraticAIR, QuadraticPublicInputs}, simple_fibonacci::{self, FibonacciAIR, FibonacciPublicInputs}, }, - proof::options::ProofOptions, + proof::options::{ProofOptions, SecurityLevel}, prover::prove, trace::TraceTable, verifier::verify, @@ -336,3 +336,22 @@ fn test_verifier_rejects_proof_with_changed_output() { let proof = generate_cairo_proof(&malicious_trace, &pub_inputs, &proof_options).unwrap(); assert!(!verify_cairo_proof(&proof, &pub_inputs, &proof_options)); } + +#[test_log::test] +fn test_verifier_rejects_proof_with_different_security_params() { + let program_content = std::fs::read(cairo0_program_path("output_program.json")).unwrap(); + let (main_trace, pub_inputs) = + generate_prover_args(&program_content, &CairoVersion::V0, &None).unwrap(); + + let proof_options_prover = ProofOptions::new_secure(SecurityLevel::Conjecturable80Bits, 3); + + let proof = generate_cairo_proof(&main_trace, &pub_inputs, &proof_options_prover).unwrap(); + + let proof_options_verifier = ProofOptions::new_secure(SecurityLevel::Conjecturable128Bits, 3); + + assert!(!verify_cairo_proof( + &proof, + &pub_inputs, + &proof_options_verifier + )); +} From 9b462a3056474b602348745378c9740c5cb37833 Mon Sep 17 00:00:00 2001 From: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com> Date: Fri, 14 Jul 2023 08:02:27 -0300 Subject: [PATCH 3/3] Compare with Giza (#183) * [WIP] Add giza benchmark * Ignore and remove trace and memory files * Add giza benchmarks * Fix compile and lint * Add nightly install step * Refactor proof options usage --- .github/workflows/ci.yaml | 10 ++- .gitignore | 4 +- Cargo.toml | 10 ++- Makefile | 4 ++ benches/criterion_giza.rs | 128 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 benches/criterion_giza.rs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b94cf656..8de570d3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,7 +17,7 @@ jobs: - name: Checkout sources uses: actions/checkout@v3 - - name: Rustup toolchain install + - name: Rustup toolchain stable install uses: dtolnay/rust-toolchain@stable with: toolchain: stable @@ -30,8 +30,14 @@ jobs: with: command: check + # For giza benchmarks + - name: Rustup toolchain nightly install + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly + - name: Check benchmarks - run: cargo bench --no-run + run: cargo +nightly bench --no-run -F giza lint: name: Lint runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 0b0e24b2..4f653b47 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,8 @@ Cargo.lock **/proptest-regressions /output.txt flamegraph.svg -proving_system/stark/src/cairo_run/program.memory -proving_system/stark/src/cairo_run/program.trace +**/*.trace +**/*.memory **/.DS_Store **/*.swp diff --git a/Cargo.toml b/Cargo.toml index 4cdc703a..84bc3f20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,9 @@ serde_json = "1.0" num-integer = "0.1.45" itertools = "0.11.0" rayon = { version = "1.7.0", optional = true } +giza-core = { git = "https://github.com/lambdaclass/giza", branch = "remove_prints", optional = true } +giza-prover = { git = "https://github.com/lambdaclass/giza", branch = "remove_prints", optional = true } +giza-runner = { git = "https://github.com/lambdaclass/giza", branch = "remove_prints", optional = true } [dev-dependencies] proptest = "1.2.0" @@ -35,6 +38,7 @@ test_fiat_shamir = [] instruments = [] # This enables timing prints in prover and verifier metal = ["lambdaworks-math/metal"] parallel = ["dep:rayon"] +giza = ["dep:giza-core", "dep:giza-prover", "dep:giza-runner"] [[bench]] name = "criterion_prover" @@ -54,7 +58,11 @@ metal = ["lambdaworks-math/metal"] [[bench]] name = "criterion_verifier_70k" harness = false -metal = ["lambdaworks-math/metal"] + +[[bench]] +name = "criterion_giza" +harness = false + [profile.release] lto = true diff --git a/Makefile b/Makefile index 470f0d55..c60c63f9 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,10 @@ benchmarks_parallel: $(COMPILED_CAIRO0_PROGRAMS) benchmarks_parallel_all: $(COMPILED_CAIRO0_PROGRAMS) cargo bench -F parallel +# TODO: add trace and memory rules +benchmarks_giza: $(COMPILED_CAIRO0_PROGRAMS) + cargo +nightly bench --bench criterion_giza -F "parallel giza" + build_metal: cargo b --features metal --release diff --git a/benches/criterion_giza.rs b/benches/criterion_giza.rs new file mode 100644 index 00000000..9160623a --- /dev/null +++ b/benches/criterion_giza.rs @@ -0,0 +1,128 @@ +#[cfg(feature = "giza")] +use criterion::{black_box, measurement::WallTime, BenchmarkGroup}; +use criterion::{criterion_group, criterion_main, Criterion}; +#[cfg(feature = "giza")] +use lambdaworks_stark::{ + cairo::{ + air::generate_cairo_proof, + runner::run::{generate_prover_args, CairoVersion}, + }, + starks::proof::options::{self, SecurityLevel}, +}; +#[cfg(feature = "giza")] +pub mod functions; + +#[cfg(not(feature = "giza"))] +fn cairo_benches(_: &mut Criterion) { + println!("Enable giza feature to run giza benchmarks"); +} + +#[cfg(feature = "giza")] +fn cairo_benches(c: &mut Criterion) { + #[cfg(feature = "parallel")] + { + let num_threads: usize = std::env::var("NUM_THREADS") + .unwrap_or("8".to_string()) + .parse() + .unwrap(); + println!("Running benchmarks using {} threads", num_threads); + rayon::ThreadPoolBuilder::new() + .num_threads(num_threads) + .build_global() + .unwrap(); + }; + + let mut group = c.benchmark_group("CAIRO"); + group.sample_size(10); + let proof_options = options::ProofOptions::new_secure(SecurityLevel::Provable80Bits, 3); + + run_lambdaworks_bench( + &mut group, + &proof_options, + "lambdaworks/fibonacci/1000", + &cairo0_program_path("fibonacci_1000.json"), + ); + run_giza_bench( + &mut group, + &proof_options, + "giza/fibonacci/1000", + &cairo0_program_path("fibonacci_1000.json"), + &cairo0_program_path("fibonacci_1000.trace"), + &cairo0_program_path("fibonacci_1000.memory"), + ); + + run_lambdaworks_bench( + &mut group, + &proof_options, + "lambdaworks/fibonacci/10000", + &cairo0_program_path("fibonacci_10000.json"), + ); + run_giza_bench( + &mut group, + &proof_options, + "giza/fibonacci/10000", + &cairo0_program_path("fibonacci_10000.json"), + &cairo0_program_path("fibonacci_10000.trace"), + &cairo0_program_path("fibonacci_10000.memory"), + ); +} + +#[cfg(feature = "giza")] +fn cairo0_program_path(program_name: &str) -> String { + const CARGO_DIR: &str = env!("CARGO_MANIFEST_DIR"); + const PROGRAM_BASE_REL_PATH: &str = "/cairo_programs/cairo0/"; + let program_base_path = CARGO_DIR.to_string() + PROGRAM_BASE_REL_PATH; + program_base_path + program_name +} + +#[cfg(feature = "giza")] +fn run_lambdaworks_bench( + group: &mut BenchmarkGroup<'_, WallTime>, + proof_options: &options::ProofOptions, + benchname: &str, + program_path: &str, +) { + let program_content = std::fs::read(program_path).unwrap(); + let (main_trace, pub_inputs) = + generate_prover_args(&program_content, &CairoVersion::V0, &None).unwrap(); + + group.bench_function(benchname, |bench| { + bench.iter(|| { + black_box(generate_cairo_proof(&main_trace, &pub_inputs, proof_options).unwrap()) + }); + }); +} + +#[cfg(feature = "giza")] +fn run_giza_bench( + group: &mut BenchmarkGroup<'_, WallTime>, + proof_options: &options::ProofOptions, + benchname: &str, + program_path: &str, + trace_path: &str, + memory_path: &str, +) { + let proof_options = giza_prover::ProofOptions::with_proof_options( + Some(proof_options.fri_number_of_queries), + Some(proof_options.blowup_factor as usize), + Some(proof_options.grinding_factor as u32), + None, + None, + ); + + group.bench_function(benchname, |bench| { + bench.iter(|| { + let trace = giza_runner::ExecutionTrace::from_file( + program_path.into(), + trace_path.into(), + memory_path.into(), + None, + ); + + black_box(giza_prover::prove_trace(trace, &proof_options)).unwrap() + }); + }); +} + +criterion_group!(benches, cairo_benches); +criterion_main!(benches);