From 50c146a5ff23e1db99df59ca9920d249c8225d8c Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:48:27 +0200 Subject: [PATCH 01/16] ci: run example in ci --- .github/workflows/lint-and-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index be1f56d12..3703f52ac 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -118,6 +118,8 @@ jobs: run: cargo run --example dog_breeds - name: Run wood types example run: cargo run --example wood_types + - name: Run movies example + run: cargo run --example movies - name: Run posql_db example (With Blitzar) run: bash crates/proof-of-sql/examples/posql_db/run_example.sh - name: Run posql_db example (Without Blitzar) From df3e77b21b732e56a3f05eaacd719c9fdfca0811 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:49:40 +0200 Subject: [PATCH 02/16] feat: add movies dataset placeholder --- crates/proof-of-sql/examples/movies/movies.csv | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 crates/proof-of-sql/examples/movies/movies.csv diff --git a/crates/proof-of-sql/examples/movies/movies.csv b/crates/proof-of-sql/examples/movies/movies.csv new file mode 100644 index 000000000..e69de29bb From e05a75205fec691b57a49d35f8522f5c55d9bcd4 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:50:57 +0200 Subject: [PATCH 03/16] feat: add space example stub --- crates/proof-of-sql/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/proof-of-sql/Cargo.toml b/crates/proof-of-sql/Cargo.toml index 8b408d840..5a2f247c4 100644 --- a/crates/proof-of-sql/Cargo.toml +++ b/crates/proof-of-sql/Cargo.toml @@ -103,6 +103,10 @@ required-features = [ "arrow" ] name = "wood_types" required-features = [ "arrow" ] +[[example]] +name = “movies" +required-features = [ "arrow" ] + [[bench]] name = "posql_benches" harness = false From 94eb0b6c7b06e4c563faa529c861c6f38a8ba2de Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:51:35 +0200 Subject: [PATCH 04/16] feat: populate movies with first examples --- crates/proof-of-sql/examples/movies/movies.csv | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/proof-of-sql/examples/movies/movies.csv b/crates/proof-of-sql/examples/movies/movies.csv index e69de29bb..5567ca4f8 100644 --- a/crates/proof-of-sql/examples/movies/movies.csv +++ b/crates/proof-of-sql/examples/movies/movies.csv @@ -0,0 +1,4 @@ +id, title, year, genre, rating, duration +1, The Matrix, 1999, Action, 8.7, 136 +2, The Matrix Reloaded, 2003, Action, 7.2, 138 +3, The Matrix Revolutions, 2003, Action, 6.7, 129 \ No newline at end of file From 309d73aac130e16794cf610a1be4cd25a86a4834 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:52:59 +0200 Subject: [PATCH 05/16] feat: add example using postprocessing --- crates/proof-of-sql/examples/movies/main.rs | 112 ++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 crates/proof-of-sql/examples/movies/main.rs diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs new file mode 100644 index 000000000..23ac8599c --- /dev/null +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -0,0 +1,112 @@ + +//! This is a non-interactive example of using Proof of SQL with a movies dataset. +//! To run this, use `cargo run --release --example movies`. +//! +//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed, +//! you can run `cargo run --release --example movies --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation. + +use arrow::datatypes::SchemaRef; +use arrow_csv::{infer_schema_from_files, ReaderBuilder}; +use proof_of_sql::{ + base::database::{ + arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor, + TestAccessor, + }, + proof_primitive::dory::{ + DynamicDoryCommitment, DynamicDoryEvaluationProof, ProverSetup, PublicParameters, + VerifierSetup, + }, + sql::{parse::QueryExpr, postprocessing::apply_postprocessing_steps, proof::QueryProof}, +}; +use rand::{rngs::StdRng, SeedableRng}; +use std::{fs::File, time::Instant}; + +// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS. +// The `max_nu` should be set such that the maximum table size is less than `2^(2*max_nu-1)`. +const DORY_SETUP_MAX_NU: usize = 8; +// This should be a "nothing-up-my-sleeve" phrase or number. +const DORY_SEED: [u8; 32] = *b"ebab60d58dee4cc69658939b7c2a582d"; + +/// # Panics +/// Will panic if the query does not parse or the proof fails to verify. +fn prove_and_verify_query( + sql: &str, + accessor: &OwnedTableTestAccessor, + prover_setup: &ProverSetup, + verifier_setup: &VerifierSetup, +) { + // Parse the query: + println!("Parsing the query: {sql}..."); + let now = Instant::now(); + let query_plan = QueryExpr::::try_new( + sql.parse().unwrap(), + "movies".parse().unwrap(), + accessor, + ) + .unwrap(); + println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.); + + // Generate the proof and result: + print!("Generating proof..."); + let now = Instant::now(); + let (proof, provable_result) = QueryProof::::new( + query_plan.proof_expr(), + accessor, + &prover_setup, + ); + println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.); + + // Verify the result with the proof: + print!("Verifying proof..."); + let now = Instant::now(); + let result = proof + .verify( + query_plan.proof_expr(), + accessor, + &provable_result, + &verifier_setup, + ) + .unwrap(); + let result = apply_postprocessing_steps(result.table, query_plan.postprocessing()); + println!("Verified in {} ms.", now.elapsed().as_secs_f64() * 1000.); + + // Display the result + println!("Query Result:"); + println!("{result:?}"); +} + +fn main() { + let mut rng = StdRng::from_seed(DORY_SEED); + let public_parameters = PublicParameters::rand(DORY_SETUP_MAX_NU, &mut rng); + let prover_setup = ProverSetup::from(&public_parameters); + let verifier_setup = VerifierSetup::from(&public_parameters); + + let filename = "./crates/proof-of-sql/examples/movies/movies.csv"; + let inferred_schema = + SchemaRef::new(infer_schema_from_files(&[filename.to_string()], b',', None, true).unwrap()); + let posql_compatible_schema = get_posql_compatible_schema(&inferred_schema); + + let movies_batch = ReaderBuilder::new(posql_compatible_schema) + .with_header(true) + .build(File::open(filename).unwrap()) + .unwrap() + .next() + .unwrap() + .unwrap(); + + // Load the table into an "Accessor" so that the prover and verifier can access the data/commitments. + let mut accessor = + OwnedTableTestAccessor::::new_empty_with_setup(&prover_setup); + accessor.add_table( + "movies.movies".parse().unwrap(), + OwnedTable::try_from(movies_batch).unwrap(), + 0, + ); + + // Query 1: Count the total number of movies + prove_and_verify_query( + "SELECT COUNT(*) AS total_movies FROM movies", + &accessor, + &prover_setup, + &verifier_setup, + ); \ No newline at end of file From 88d3e1bf32fbac8ab63bc89642cac78d481eb605 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:53:58 +0200 Subject: [PATCH 06/16] feat: expand the queries --- crates/proof-of-sql/examples/movies/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index 23ac8599c..2300b3aa0 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -109,4 +109,13 @@ fn main() { &accessor, &prover_setup, &verifier_setup, - ); \ No newline at end of file + ); + + // Query 2: Find the top 5 highest-rated movies + prove_and_verify_query( + "SELECT title, rating FROM movies ORDER BY rating DESC LIMIT 5", + &accessor, + &prover_setup, + &verifier_setup, + ); +} \ No newline at end of file From 084cc052c24d05a6ea9d473e6499dfa59b4c9081 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:54:58 +0200 Subject: [PATCH 07/16] feat: further populate dataset --- crates/proof-of-sql/examples/movies/movies.csv | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/proof-of-sql/examples/movies/movies.csv b/crates/proof-of-sql/examples/movies/movies.csv index 5567ca4f8..b201bf612 100644 --- a/crates/proof-of-sql/examples/movies/movies.csv +++ b/crates/proof-of-sql/examples/movies/movies.csv @@ -1,4 +1,19 @@ id, title, year, genre, rating, duration 1, The Matrix, 1999, Action, 8.7, 136 2, The Matrix Reloaded, 2003, Action, 7.2, 138 -3, The Matrix Revolutions, 2003, Action, 6.7, 129 \ No newline at end of file +3, The Matrix Revolutions, 2003, Action, 6.7, 129 +4, Inception, 2010, Sci-Fi, 8.8, 148 +5, The Dark Knight, 2008, Action, 9.0, 152 +6, Pulp Fiction, 1994, Crime, 8.9, 154 +7, Forrest Gump, 1994, Drama, 8.8, 142 +8, The Shawshank Redemption, 1994, Drama, 9.3, 142 +9, The Godfather, 1972, Crime, 9.2, 175 +10, Fight Club, 1999, Drama, 8.8, 139 +11, The Lord of the Rings: The Fellowship of the Ring, 2001, Adventure, 8.8, 178 +12, Goodfellas, 1990, Crime, 8.7, 146 +13, The Silence of the Lambs, 1991, Thriller, 8.6, 118 +14, Schindler's List, 1993, Biography, 8.9, 195 +15, Interstellar, 2014, Sci-Fi, 8.6, 169 +16, The Green Mile, 1999, Crime, 8.6, 189 +17, Saving Private Ryan, 1998, War, 8.6, 169 +18, Gladiator, 2000, Action, 8.5, 155 \ No newline at end of file From 2eea92bf1d7d68645588af66fcaca238969553b9 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:57:24 +0200 Subject: [PATCH 08/16] feat: expand examples of queries --- crates/proof-of-sql/examples/movies/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index 2300b3aa0..a5cf40c84 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -118,4 +118,12 @@ fn main() { &prover_setup, &verifier_setup, ); + + // Query 3: Calculate the average duration of movies by genre + prove_and_verify_query( + "SELECT genre, AVG(duration) AS avg_duration FROM movies GROUP BY genre ORDER BY avg_duration DESC", + &accessor, + &prover_setup, + &verifier_setup, + ); } \ No newline at end of file From b72d449be8c01e950a562bdfbde18dbf24017526 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:57:59 +0200 Subject: [PATCH 09/16] feat: further populate data set to ensure robustnes --- crates/proof-of-sql/examples/movies/movies.csv | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/proof-of-sql/examples/movies/movies.csv b/crates/proof-of-sql/examples/movies/movies.csv index b201bf612..32b5b5160 100644 --- a/crates/proof-of-sql/examples/movies/movies.csv +++ b/crates/proof-of-sql/examples/movies/movies.csv @@ -16,4 +16,16 @@ id, title, year, genre, rating, duration 15, Interstellar, 2014, Sci-Fi, 8.6, 169 16, The Green Mile, 1999, Crime, 8.6, 189 17, Saving Private Ryan, 1998, War, 8.6, 169 -18, Gladiator, 2000, Action, 8.5, 155 \ No newline at end of file +18, Gladiator, 2000, Action, 8.5, 155 +19, The Avengers, 2012, Action, 8.0, 143 +20, Jurassic Park, 1993, Adventure, 8.1, 127 +21, The Lion King, 1994, Animation, 8.5, 88 +22, Titanic, 1997, Romance, 7.8, 194 +23, The Departed, 2006, Crime, 8.5, 151 +24, The Prestige, 2006, Mystery, 8.5, 130 +25, The Social Network, 2010, Biography, 7.7, 120 +26, Avatar, 2009, Action, 7.8, 162 +27, The Sixth Sense, 1999, Thriller, 8.1, 107 +28, The Usual Suspects, 1995, Crime, 8.5, 106 +29, Memento, 2000, Mystery, 8.4, 113 +30, Eternal Sunshine of the Spotless Mind, 2004, Romance, 8.3, 108 \ No newline at end of file From dc122ed68fd7e4469a1053d8d7a3081b4e4aa53f Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 11:58:38 +0200 Subject: [PATCH 10/16] feat: add harder queries to test --- crates/proof-of-sql/examples/movies/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index a5cf40c84..3b8fb5123 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -126,4 +126,12 @@ fn main() { &prover_setup, &verifier_setup, ); + + // Query 4: Find movies released in the 90s with a rating above 8.5 + prove_and_verify_query( + "SELECT title, year, rating FROM movies WHERE year >= 1990 AND year < 2000 AND rating > 8.5 ORDER BY rating DESC", + &accessor, + &prover_setup, + &verifier_setup, + ); } \ No newline at end of file From ed4e3a74933fa5552e9639e3492e017cb5e3df0c Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 12:04:35 +0200 Subject: [PATCH 11/16] fix: typo --- crates/proof-of-sql/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql/Cargo.toml b/crates/proof-of-sql/Cargo.toml index 5a2f247c4..6a4462216 100644 --- a/crates/proof-of-sql/Cargo.toml +++ b/crates/proof-of-sql/Cargo.toml @@ -104,7 +104,7 @@ name = "wood_types" required-features = [ "arrow" ] [[example]] -name = “movies" +name = "movies" required-features = [ "arrow" ] [[bench]] From d98be7865504b18eb7f1c1e66d1144db172e6bc0 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 12:19:40 +0200 Subject: [PATCH 12/16] fix: format --- crates/proof-of-sql/examples/movies/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index 3b8fb5123..f9be1efd4 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -134,4 +134,4 @@ fn main() { &prover_setup, &verifier_setup, ); -} \ No newline at end of file +} From 634d3fba9309476f12fd14ace7ea2330443bafc5 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 12:21:59 +0200 Subject: [PATCH 13/16] fix: format error --- crates/proof-of-sql/examples/movies/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index f9be1efd4..5f4963798 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -1,4 +1,3 @@ - //! This is a non-interactive example of using Proof of SQL with a movies dataset. //! To run this, use `cargo run --release --example movies`. //! From 943269641ea7513c1747fc6b2de10bcdfd037551 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 13:05:40 +0200 Subject: [PATCH 14/16] fix: replacing avg for sum in queries --- crates/proof-of-sql/examples/movies/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index 5f4963798..67156aa64 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -118,9 +118,12 @@ fn main() { &verifier_setup, ); - // Query 3: Calculate the average duration of movies by genre + // Query 3: Calculate the total duration and count of movies by genre + // Note: We're using SUM and COUNT instead of AVG because the current version + // of the SQL parser doesn't support the AVG function. You can calculate the + // average by dividing total_duration by movie_count. prove_and_verify_query( - "SELECT genre, AVG(duration) AS avg_duration FROM movies GROUP BY genre ORDER BY avg_duration DESC", + "SELECT genre, SUM(duration) AS total_duration, COUNT(*) AS movie_count FROM movies GROUP BY genre ORDER BY total_duration DESC", &accessor, &prover_setup, &verifier_setup, From 88d95d4e3d3e70b9de4a4238b108dac2660ebff6 Mon Sep 17 00:00:00 2001 From: AlejandroLanaspa Date: Wed, 23 Oct 2024 13:33:10 +0200 Subject: [PATCH 15/16] fix : queries not passing test --- crates/proof-of-sql/examples/movies/main.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs index 67156aa64..481eddc49 100644 --- a/crates/proof-of-sql/examples/movies/main.rs +++ b/crates/proof-of-sql/examples/movies/main.rs @@ -117,23 +117,4 @@ fn main() { &prover_setup, &verifier_setup, ); - - // Query 3: Calculate the total duration and count of movies by genre - // Note: We're using SUM and COUNT instead of AVG because the current version - // of the SQL parser doesn't support the AVG function. You can calculate the - // average by dividing total_duration by movie_count. - prove_and_verify_query( - "SELECT genre, SUM(duration) AS total_duration, COUNT(*) AS movie_count FROM movies GROUP BY genre ORDER BY total_duration DESC", - &accessor, - &prover_setup, - &verifier_setup, - ); - - // Query 4: Find movies released in the 90s with a rating above 8.5 - prove_and_verify_query( - "SELECT title, year, rating FROM movies WHERE year >= 1990 AND year < 2000 AND rating > 8.5 ORDER BY rating DESC", - &accessor, - &prover_setup, - &verifier_setup, - ); } From 0fde50b93dbee1b70635ce31d7e1021ad9465520 Mon Sep 17 00:00:00 2001 From: chilaraisxt Date: Wed, 30 Oct 2024 22:21:48 +0530 Subject: [PATCH 16/16] Removed movies example altogether --- crates/proof-of-sql/Cargo.toml | 7 - crates/proof-of-sql/examples/movies/main.rs | 120 ------------------ .../proof-of-sql/examples/movies/movies.csv | 31 ----- 3 files changed, 158 deletions(-) delete mode 100644 crates/proof-of-sql/examples/movies/main.rs delete mode 100644 crates/proof-of-sql/examples/movies/movies.csv diff --git a/crates/proof-of-sql/Cargo.toml b/crates/proof-of-sql/Cargo.toml index c4d508245..15178993b 100644 --- a/crates/proof-of-sql/Cargo.toml +++ b/crates/proof-of-sql/Cargo.toml @@ -103,10 +103,6 @@ required-features = ["arrow"] name = "wood_types" required-features = ["arrow"] -[[example]] -name = "movies" -required-features = [ "arrow" ] - [[example]] name = "dinosaurs" required-features = ["arrow"] @@ -159,9 +155,6 @@ required-features = [ "arrow" ] name = "vehicles" required-features = [ "arrow" ] -[[example]] -name = "movies" -required-features = [ "arrow" ] [[bench]] name = "posql_benches" diff --git a/crates/proof-of-sql/examples/movies/main.rs b/crates/proof-of-sql/examples/movies/main.rs deleted file mode 100644 index 481eddc49..000000000 --- a/crates/proof-of-sql/examples/movies/main.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! This is a non-interactive example of using Proof of SQL with a movies dataset. -//! To run this, use `cargo run --release --example movies`. -//! -//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed, -//! you can run `cargo run --release --example movies --no-default-features --features="arrow cpu-perf"` instead. It will be slower for proof generation. - -use arrow::datatypes::SchemaRef; -use arrow_csv::{infer_schema_from_files, ReaderBuilder}; -use proof_of_sql::{ - base::database::{ - arrow_schema_utility::get_posql_compatible_schema, OwnedTable, OwnedTableTestAccessor, - TestAccessor, - }, - proof_primitive::dory::{ - DynamicDoryCommitment, DynamicDoryEvaluationProof, ProverSetup, PublicParameters, - VerifierSetup, - }, - sql::{parse::QueryExpr, postprocessing::apply_postprocessing_steps, proof::QueryProof}, -}; -use rand::{rngs::StdRng, SeedableRng}; -use std::{fs::File, time::Instant}; - -// We generate the public parameters and the setups used by the prover and verifier for the Dory PCS. -// The `max_nu` should be set such that the maximum table size is less than `2^(2*max_nu-1)`. -const DORY_SETUP_MAX_NU: usize = 8; -// This should be a "nothing-up-my-sleeve" phrase or number. -const DORY_SEED: [u8; 32] = *b"ebab60d58dee4cc69658939b7c2a582d"; - -/// # Panics -/// Will panic if the query does not parse or the proof fails to verify. -fn prove_and_verify_query( - sql: &str, - accessor: &OwnedTableTestAccessor, - prover_setup: &ProverSetup, - verifier_setup: &VerifierSetup, -) { - // Parse the query: - println!("Parsing the query: {sql}..."); - let now = Instant::now(); - let query_plan = QueryExpr::::try_new( - sql.parse().unwrap(), - "movies".parse().unwrap(), - accessor, - ) - .unwrap(); - println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.); - - // Generate the proof and result: - print!("Generating proof..."); - let now = Instant::now(); - let (proof, provable_result) = QueryProof::::new( - query_plan.proof_expr(), - accessor, - &prover_setup, - ); - println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.); - - // Verify the result with the proof: - print!("Verifying proof..."); - let now = Instant::now(); - let result = proof - .verify( - query_plan.proof_expr(), - accessor, - &provable_result, - &verifier_setup, - ) - .unwrap(); - let result = apply_postprocessing_steps(result.table, query_plan.postprocessing()); - println!("Verified in {} ms.", now.elapsed().as_secs_f64() * 1000.); - - // Display the result - println!("Query Result:"); - println!("{result:?}"); -} - -fn main() { - let mut rng = StdRng::from_seed(DORY_SEED); - let public_parameters = PublicParameters::rand(DORY_SETUP_MAX_NU, &mut rng); - let prover_setup = ProverSetup::from(&public_parameters); - let verifier_setup = VerifierSetup::from(&public_parameters); - - let filename = "./crates/proof-of-sql/examples/movies/movies.csv"; - let inferred_schema = - SchemaRef::new(infer_schema_from_files(&[filename.to_string()], b',', None, true).unwrap()); - let posql_compatible_schema = get_posql_compatible_schema(&inferred_schema); - - let movies_batch = ReaderBuilder::new(posql_compatible_schema) - .with_header(true) - .build(File::open(filename).unwrap()) - .unwrap() - .next() - .unwrap() - .unwrap(); - - // Load the table into an "Accessor" so that the prover and verifier can access the data/commitments. - let mut accessor = - OwnedTableTestAccessor::::new_empty_with_setup(&prover_setup); - accessor.add_table( - "movies.movies".parse().unwrap(), - OwnedTable::try_from(movies_batch).unwrap(), - 0, - ); - - // Query 1: Count the total number of movies - prove_and_verify_query( - "SELECT COUNT(*) AS total_movies FROM movies", - &accessor, - &prover_setup, - &verifier_setup, - ); - - // Query 2: Find the top 5 highest-rated movies - prove_and_verify_query( - "SELECT title, rating FROM movies ORDER BY rating DESC LIMIT 5", - &accessor, - &prover_setup, - &verifier_setup, - ); -} diff --git a/crates/proof-of-sql/examples/movies/movies.csv b/crates/proof-of-sql/examples/movies/movies.csv deleted file mode 100644 index 32b5b5160..000000000 --- a/crates/proof-of-sql/examples/movies/movies.csv +++ /dev/null @@ -1,31 +0,0 @@ -id, title, year, genre, rating, duration -1, The Matrix, 1999, Action, 8.7, 136 -2, The Matrix Reloaded, 2003, Action, 7.2, 138 -3, The Matrix Revolutions, 2003, Action, 6.7, 129 -4, Inception, 2010, Sci-Fi, 8.8, 148 -5, The Dark Knight, 2008, Action, 9.0, 152 -6, Pulp Fiction, 1994, Crime, 8.9, 154 -7, Forrest Gump, 1994, Drama, 8.8, 142 -8, The Shawshank Redemption, 1994, Drama, 9.3, 142 -9, The Godfather, 1972, Crime, 9.2, 175 -10, Fight Club, 1999, Drama, 8.8, 139 -11, The Lord of the Rings: The Fellowship of the Ring, 2001, Adventure, 8.8, 178 -12, Goodfellas, 1990, Crime, 8.7, 146 -13, The Silence of the Lambs, 1991, Thriller, 8.6, 118 -14, Schindler's List, 1993, Biography, 8.9, 195 -15, Interstellar, 2014, Sci-Fi, 8.6, 169 -16, The Green Mile, 1999, Crime, 8.6, 189 -17, Saving Private Ryan, 1998, War, 8.6, 169 -18, Gladiator, 2000, Action, 8.5, 155 -19, The Avengers, 2012, Action, 8.0, 143 -20, Jurassic Park, 1993, Adventure, 8.1, 127 -21, The Lion King, 1994, Animation, 8.5, 88 -22, Titanic, 1997, Romance, 7.8, 194 -23, The Departed, 2006, Crime, 8.5, 151 -24, The Prestige, 2006, Mystery, 8.5, 130 -25, The Social Network, 2010, Biography, 7.7, 120 -26, Avatar, 2009, Action, 7.8, 162 -27, The Sixth Sense, 1999, Thriller, 8.1, 107 -28, The Usual Suspects, 1995, Crime, 8.5, 106 -29, Memento, 2000, Mystery, 8.4, 113 -30, Eternal Sunshine of the Spotless Mind, 2004, Romance, 8.3, 108 \ No newline at end of file