diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 40bcdd4fd..f5b3e8e37 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -114,24 +114,6 @@ jobs: run: cargo run --example hello_world --no-default-features --features="test" - name: Run space example run: cargo run --example space - - name: Run dog breeds example - run: cargo run --example dog_breeds - - name: Run wood types example - run: cargo run --example wood_types - - name: Run dinosaurs example - run: cargo run --example dinosaurs - - name: Run books example - run: cargo run --example books - - name: Run brands example - run: cargo run --example brands - - name: Run avocado-prices example - run: cargo run --example avocado-prices - - name: Run plastics example - run: cargo run --example plastics - - name: Run sushi example - run: cargo run --example sushi - - name: Run tech_gadget_prices example - run: cargo run --example tech_gadget_prices - 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) @@ -245,4 +227,4 @@ jobs: - name: Install solhint run: npm install -g solhint - name: Run tests - run: solhint -c 'crates/proof-of-sql/.solhint.json' 'crates/proof-of-sql/**/*.sol' -w 0 + run: solhint -c 'crates/proof-of-sql/.solhint.json' 'crates/proof-of-sql/**/*.sol' -w 0 \ No newline at end of file diff --git a/crates/proof-of-sql/Cargo.toml b/crates/proof-of-sql/Cargo.toml index de70a5ee0..99a22d441 100644 --- a/crates/proof-of-sql/Cargo.toml +++ b/crates/proof-of-sql/Cargo.toml @@ -155,6 +155,14 @@ required-features = [ "arrow" ] name = "vehicles" required-features = [ "arrow" ] +[[example]] +name = "countries" +required-features = [ "arrow" ] + +[[example]] +name = "rockets" +required-features = [ "arrow" ] + [[bench]] name = "posql_benches" harness = false diff --git a/crates/proof-of-sql/examples/tech_gadget_prices/main.rs b/crates/proof-of-sql/examples/tech_gadget_prices/main.rs index c7fce8405..2ae44ee29 100644 --- a/crates/proof-of-sql/examples/tech_gadget_prices/main.rs +++ b/crates/proof-of-sql/examples/tech_gadget_prices/main.rs @@ -1,5 +1,8 @@ -//! Example to use Proof of SQL with a tech gadget prices dataset. -//! To run, use `cargo run --example tech_gadget_prices`. +//! This is a non-interactive example of using Proof of SQL with a `tech_gadget_prices` dataset. +//! To run this, use cargo run --release --example `tech_gadget_prices`. +//! +//! NOTE: If this doesn't work because you do not have the appropriate GPU drivers installed, +//! you can run cargo run --release --example `tech_gadget_prices` --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}; @@ -12,25 +15,26 @@ use proof_of_sql::{ sql::{parse::QueryExpr, proof::QueryProof}, }; use rand::{rngs::StdRng, SeedableRng}; -use std::{fs::File, time::Instant}; +use std::{error::Error, fs::File, time::Instant}; const DORY_SETUP_MAX_NU: usize = 8; const DORY_SEED: [u8; 32] = *b"tech-gadget-prices-dataset-seed!"; + fn prove_and_verify_query( sql: &str, accessor: &OwnedTableTestAccessor, prover_setup: &ProverSetup, verifier_setup: &VerifierSetup, -) { +) -> Result<(), Box> { println!("Parsing the query: {sql}..."); let now = Instant::now(); let query_plan = QueryExpr::::try_new( - sql.parse().unwrap(), - "tech_gadget_prices".parse().unwrap(), + sql.parse()?, + "tech_gadget_prices".parse()?, accessor, - ) - .unwrap(); + )?; println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.); + print!("Generating proof..."); let now = Instant::now(); let (proof, provable_result) = QueryProof::::new( @@ -39,42 +43,39 @@ fn prove_and_verify_query( &prover_setup, ); println!("Done in {} ms.", now.elapsed().as_secs_f64() * 1000.); + print!("Verifying proof..."); let now = Instant::now(); - let result = proof - .verify( - query_plan.proof_expr(), - accessor, - &provable_result, - &verifier_setup, - ) - .unwrap(); + let result = proof.verify( + query_plan.proof_expr(), + accessor, + &provable_result, + &verifier_setup, + )?; println!("Verified in {} ms.", now.elapsed().as_secs_f64() * 1000.); println!("Query Result:"); println!("{:?}", result.table); + Ok(()) } -fn main() { +fn main() -> Result<(), Box> { 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 = "./tech_gadget_prices/tech_gadget_prices.csv"; - let data_batch = ReaderBuilder::new(SchemaRef::new( - infer_schema_from_files(&[filename.to_string()], b',', None, true).unwrap(), - )) - .with_header(true) - .build(File::open(filename).unwrap()) - .unwrap() - .next() - .unwrap() - .unwrap(); + let schema = infer_schema_from_files(&[filename.to_string()], b',', None, true)?; + let data_batch = ReaderBuilder::new(SchemaRef::new(schema)) + .with_header(true) + .build(File::open(filename)?)? + .next() + .ok_or("No data found in CSV file")??; let accessor = OwnedTableTestAccessor::::new_from_table( - "tech_gadget_prices.prices".parse().unwrap(), - OwnedTable::try_from(data_batch).unwrap(), + "tech_gadget_prices.prices".parse()?, + OwnedTable::try_from(data_batch)?, 0, &prover_setup, ); @@ -84,23 +85,24 @@ fn main() { &accessor, &prover_setup, &verifier_setup, - ); + )?; prove_and_verify_query( "SELECT Brand, COUNT(*) AS total FROM prices GROUP BY Brand ORDER BY total", &accessor, &prover_setup, &verifier_setup, - ); + )?; prove_and_verify_query( "SELECT Name, Price FROM prices WHERE Category = 'Smartphone' ORDER BY Price DESC LIMIT 3", &accessor, &prover_setup, &verifier_setup, - ); + )?; prove_and_verify_query( "SELECT Name, ReleaseYear FROM prices WHERE Price > 500 ORDER BY ReleaseYear DESC", &accessor, &prover_setup, &verifier_setup, - ); + )?; + Ok(()) }