diff --git a/crates/proof-of-sql/Cargo.toml b/crates/proof-of-sql/Cargo.toml index f6d1e5804..4cbdd894e 100644 --- a/crates/proof-of-sql/Cargo.toml +++ b/crates/proof-of-sql/Cargo.toml @@ -83,11 +83,11 @@ workspace = true [[example]] name = "hello_world" -required-features = [ "blitzar", "test" ] +required-features = ["test"] [[example]] name = "posql_db" -required-features = [ "arrow", "blitzar" ] +required-features = [ "arrow" ] [[bench]] name = "posql_benches" diff --git a/crates/proof-of-sql/examples/hello_world/main.rs b/crates/proof-of-sql/examples/hello_world/main.rs index 26d025707..d8bf9633e 100644 --- a/crates/proof-of-sql/examples/hello_world/main.rs +++ b/crates/proof-of-sql/examples/hello_world/main.rs @@ -1,11 +1,14 @@ #![doc = include_str!("README.md")] - -use blitzar::{compute::init_backend, proof::InnerProductProof}; +use ark_std::test_rng; +use blitzar::compute::init_backend; use proof_of_sql::{ base::database::{ owned_table_utility::{bigint, owned_table, varchar}, OwnedTableTestAccessor, TestAccessor, }, + proof_primitive::dory::{ + DynamicDoryEvaluationProof, ProverSetup, PublicParameters, VerifierSetup, + }, sql::{parse::QueryExpr, proof::QueryProof}, }; use std::{ @@ -42,7 +45,11 @@ fn main() { init_backend(); end_timer(timer); let timer = start_timer("Loading data"); - let mut accessor = OwnedTableTestAccessor::::new_empty_with_setup(()); + let public_parameters = PublicParameters::test_rand(5, &mut test_rng()); + let prover_setup = ProverSetup::from(&public_parameters); + let verifier_setup = VerifierSetup::from(&public_parameters); + let mut accessor = + OwnedTableTestAccessor::::new_empty_with_setup(&prover_setup); accessor.add_table( "sxt.table".parse().unwrap(), owned_table([ @@ -61,11 +68,19 @@ fn main() { .unwrap(); end_timer(timer); let timer = start_timer("Generating Proof"); - let (proof, serialized_result) = - QueryProof::::new(query.proof_expr(), &accessor, &()); + let (proof, serialized_result) = QueryProof::::new( + query.proof_expr(), + &accessor, + &&prover_setup, + ); end_timer(timer); let timer = start_timer("Verifying Proof"); - let result = proof.verify(query.proof_expr(), &accessor, &serialized_result, &()); + let result = proof.verify( + query.proof_expr(), + &accessor, + &serialized_result, + &&verifier_setup, + ); end_timer(timer); match result { Ok(result) => { diff --git a/crates/proof-of-sql/examples/posql_db/main.rs b/crates/proof-of-sql/examples/posql_db/main.rs index 9ec7f2bc0..a9138ae11 100644 --- a/crates/proof-of-sql/examples/posql_db/main.rs +++ b/crates/proof-of-sql/examples/posql_db/main.rs @@ -9,17 +9,19 @@ use arrow::{ datatypes::{DataType, Field, Schema}, record_batch::RecordBatch, }; -use blitzar::proof::InnerProductProof; use clap::{arg, Parser, Subcommand, ValueEnum}; use commit_accessor::CommitAccessor; use csv_accessor::{read_record_batch_from_csv, CsvDataAccessor}; -use curve25519_dalek::RistrettoPoint; use itertools::Itertools; use proof_of_sql::{ base::{ commitment::TableCommitment, database::{SchemaAccessor, TableRef}, }, + proof_primitive::dory::{ + DynamicDoryCommitment, DynamicDoryEvaluationProof, ProverSetup, PublicParameters, + VerifierSetup, + }, sql::{parse::QueryExpr, proof::VerifiableQueryResult}, }; use proof_of_sql_parser::{Identifier, SelectStatement}; @@ -149,6 +151,11 @@ fn main() { println!("Warming up GPU..."); blitzar::compute::init_backend(); println!("Done."); + + let mut rng = ::from_seed([0u8; 32]); + let public_parameters = PublicParameters::rand(5, &mut rng); + let prover_setup = ProverSetup::from(&public_parameters); + let verifier_setup = VerifierSetup::from(&public_parameters); match args.command { Commands::Create { table, @@ -156,7 +163,7 @@ fn main() { data_types, } => { let commit_accessor = - CommitAccessor::::new(PathBuf::from(args.path.clone())); + CommitAccessor::::new(PathBuf::from(args.path.clone())); let csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path)); let schema = Schema::new( columns @@ -166,7 +173,7 @@ fn main() { .collect::>(), ); let batch = RecordBatch::new_empty(Arc::new(schema)); - let table_commitment = TableCommitment::try_from_record_batch(&batch, &()) + let table_commitment = TableCommitment::try_from_record_batch(&batch, &&prover_setup) .expect("Failed to create table commitment."); commit_accessor .write_commit(&table, &table_commitment) @@ -180,7 +187,7 @@ fn main() { file: file_path, } => { let mut commit_accessor = - CommitAccessor::::new(PathBuf::from(args.path.clone())); + CommitAccessor::::new(PathBuf::from(args.path.clone())); let csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path)); commit_accessor .load_commit(table_name) @@ -200,7 +207,7 @@ fn main() { .expect("Failed to write batch"); let timer = start_timer("Updating Commitment"); table_commitment - .try_append_record_batch(&append_batch, &()) + .try_append_record_batch(&append_batch, &&prover_setup) .expect("Failed to append batch"); end_timer(timer); commit_accessor @@ -209,7 +216,7 @@ fn main() { } Commands::Prove { query, file } => { let mut commit_accessor = - CommitAccessor::::new(PathBuf::from(args.path.clone())); + CommitAccessor::::new(PathBuf::from(args.path.clone())); let mut csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path.clone())); let tables = query.get_table_references("example".parse().unwrap()); for table in tables.into_iter().map(TableRef::new) { @@ -230,10 +237,10 @@ fn main() { let query = QueryExpr::try_new(query, "example".parse().unwrap(), &commit_accessor).unwrap(); let timer = start_timer("Generating Proof"); - let proof = VerifiableQueryResult::::new( + let proof = VerifiableQueryResult::::new( query.proof_expr(), &csv_accessor, - &(), + &&prover_setup, ); end_timer(timer); fs::write( @@ -244,7 +251,7 @@ fn main() { } Commands::Verify { query, file } => { let mut commit_accessor = - CommitAccessor::::new(PathBuf::from(args.path.clone())); + CommitAccessor::::new(PathBuf::from(args.path.clone())); let table_refs = query.get_table_references("example".parse().unwrap()); for table_ref in table_refs { let table_name = TableRef::new(table_ref); @@ -254,12 +261,13 @@ fn main() { } let query = QueryExpr::try_new(query, "example".parse().unwrap(), &commit_accessor).unwrap(); - let result: VerifiableQueryResult = + let result: VerifiableQueryResult = postcard::from_bytes(&fs::read(file).expect("Failed to read proof")) .expect("Failed to deserialize proof"); + let timer = start_timer("Verifying Proof"); let query_result = result - .verify(query.proof_expr(), &commit_accessor, &()) + .verify(query.proof_expr(), &commit_accessor, &&verifier_setup) .expect("Failed to verify proof"); end_timer(timer); println!( diff --git a/crates/proof-of-sql/examples/posql_db/run_example.sh b/crates/proof-of-sql/examples/posql_db/run_example.sh index 91f773fe4..133aea220 100644 --- a/crates/proof-of-sql/examples/posql_db/run_example.sh +++ b/crates/proof-of-sql/examples/posql_db/run_example.sh @@ -1,5 +1,5 @@ cd crates/proof-of-sql/examples/posql_db -cargo run --features="arrow blitzar" --example posql_db create -t sxt.table -c a,b -d BIGINT,VARCHAR -cargo run --features="arrow blitzar" --example posql_db append -t sxt.table -f hello_world.csv -cargo run --features="arrow blitzar" --example posql_db prove -q "SELECT b FROM sxt.table WHERE a = 2" -f hello.proof -cargo run --features="arrow blitzar" --example posql_db verify -q "SELECT b FROM sxt.table WHERE a = 2" -f hello.proof \ No newline at end of file +cargo run --features="arrow " --example posql_db create -t sxt.table -c a,b -d BIGINT,VARCHAR +cargo run --features="arrow " --example posql_db append -t sxt.table -f hello_world.csv +cargo run --features="arrow " --example posql_db prove -q "SELECT b FROM sxt.table WHERE a = 2" -f hello.proof +cargo run --features="arrow " --example posql_db verify -q "SELECT b FROM sxt.table WHERE a = 2" -f hello.proof \ No newline at end of file