Skip to content

Commit

Permalink
feat: updated the examples to use the DynamicDoryEvaluationProof (#253
Browse files Browse the repository at this point in the history
)

# Rationale for this change

Our example code leverages the `InnerProductProof` commitment scheme.
While this is still valid, it is more difficult as an entry point to the
code because it requires Linux (and GPU by default).

# What changes are included in this PR?

Modified the examples completely to depend and run on
`DynamicDoryEvaluationProof` .

# Are these changes tested?

Yes, the existing test are enough with the same values

---------

Signed-off-by: Abinand P <[email protected]>
  • Loading branch information
Abiji-2020 authored Oct 11, 2024
1 parent 25db238 commit 1e33fcc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/proof-of-sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 21 additions & 6 deletions crates/proof-of-sql/examples/hello_world/main.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -42,7 +45,11 @@ fn main() {
init_backend();
end_timer(timer);
let timer = start_timer("Loading data");
let mut accessor = OwnedTableTestAccessor::<InnerProductProof>::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::<DynamicDoryEvaluationProof>::new_empty_with_setup(&prover_setup);
accessor.add_table(
"sxt.table".parse().unwrap(),
owned_table([
Expand All @@ -61,11 +68,19 @@ fn main() {
.unwrap();
end_timer(timer);
let timer = start_timer("Generating Proof");
let (proof, serialized_result) =
QueryProof::<InnerProductProof>::new(query.proof_expr(), &accessor, &());
let (proof, serialized_result) = QueryProof::<DynamicDoryEvaluationProof>::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) => {
Expand Down
32 changes: 20 additions & 12 deletions crates/proof-of-sql/examples/posql_db/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -149,14 +151,19 @@ fn main() {
println!("Warming up GPU...");
blitzar::compute::init_backend();
println!("Done.");

let mut rng = <ark_std::rand::rngs::StdRng as ark_std::rand::SeedableRng>::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,
columns,
data_types,
} => {
let commit_accessor =
CommitAccessor::<RistrettoPoint>::new(PathBuf::from(args.path.clone()));
CommitAccessor::<DynamicDoryCommitment>::new(PathBuf::from(args.path.clone()));
let csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path));
let schema = Schema::new(
columns
Expand All @@ -166,7 +173,7 @@ fn main() {
.collect::<Vec<_>>(),
);
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)
Expand All @@ -180,7 +187,7 @@ fn main() {
file: file_path,
} => {
let mut commit_accessor =
CommitAccessor::<RistrettoPoint>::new(PathBuf::from(args.path.clone()));
CommitAccessor::<DynamicDoryCommitment>::new(PathBuf::from(args.path.clone()));
let csv_accessor = CsvDataAccessor::new(PathBuf::from(args.path));
commit_accessor
.load_commit(table_name)
Expand All @@ -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
Expand All @@ -209,7 +216,7 @@ fn main() {
}
Commands::Prove { query, file } => {
let mut commit_accessor =
CommitAccessor::<RistrettoPoint>::new(PathBuf::from(args.path.clone()));
CommitAccessor::<DynamicDoryCommitment>::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) {
Expand All @@ -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::<InnerProductProof>::new(
let proof = VerifiableQueryResult::<DynamicDoryEvaluationProof>::new(
query.proof_expr(),
&csv_accessor,
&(),
&&prover_setup,
);
end_timer(timer);
fs::write(
Expand All @@ -244,7 +251,7 @@ fn main() {
}
Commands::Verify { query, file } => {
let mut commit_accessor =
CommitAccessor::<RistrettoPoint>::new(PathBuf::from(args.path.clone()));
CommitAccessor::<DynamicDoryCommitment>::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);
Expand All @@ -254,12 +261,13 @@ fn main() {
}
let query =
QueryExpr::try_new(query, "example".parse().unwrap(), &commit_accessor).unwrap();
let result: VerifiableQueryResult<InnerProductProof> =
let result: VerifiableQueryResult<DynamicDoryEvaluationProof> =
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!(
Expand Down
8 changes: 4 additions & 4 deletions crates/proof-of-sql/examples/posql_db/run_example.sh
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit 1e33fcc

Please sign in to comment.