-
Notifications
You must be signed in to change notification settings - Fork 184
/
main.rs
91 lines (89 loc) · 3.02 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![doc = include_str!("README.md")]
use ark_std::test_rng;
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::VerifiableQueryResult},
};
use std::{
io::{stdout, Write},
time::Instant,
};
/// # Panics
///
/// Will panic if flushing the output fails, which can happen due to issues with the underlying output stream.
fn start_timer(message: &str) -> Instant {
print!("{message}...");
stdout().flush().unwrap();
Instant::now()
}
/// # Panics
///
/// This function does not panic under normal circumstances but may panic if the internal printing fails due to issues with the output stream.
fn end_timer(instant: Instant) {
println!(" {:?}", instant.elapsed());
}
/// # Panics
///
/// - Will panic if the GPU initialization fails during `init_backend`.
/// - Will panic if the table reference cannot be parsed in `add_table`.
/// - Will panic if the offset provided to `add_table` is invalid.
/// - Will panic if the query string cannot be parsed in `QueryExpr::try_new`.
/// - Will panic if the table reference cannot be parsed in `QueryExpr::try_new`.
/// - Will panic if the query expression creation fails.
/// - Will panic if printing fails during error handling.
fn main() {
#[cfg(feature = "blitzar")]
{
let timer = start_timer("Warming up GPU");
proof_of_sql::base::commitment::init_backend();
end_timer(timer);
}
let timer = start_timer("Loading data");
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([
bigint("a", [1, 2, 3, 2]),
varchar("b", ["hi", "hello", "there", "world"]),
]),
0,
);
end_timer(timer);
let timer = start_timer("Parsing Query");
let query = QueryExpr::try_new(
"SELECT b FROM table WHERE a = 2".parse().unwrap(),
"sxt".into(),
&accessor,
)
.unwrap();
end_timer(timer);
let timer = start_timer("Generating Proof");
let verifiable_result = VerifiableQueryResult::<DynamicDoryEvaluationProof>::new(
query.proof_expr(),
&accessor,
&&prover_setup,
);
end_timer(timer);
let timer = start_timer("Verifying Proof");
let result = verifiable_result.verify(query.proof_expr(), &accessor, &&verifier_setup);
end_timer(timer);
match result {
Ok(result) => {
println!("Valid proof!");
println!("Query result: {:?}", result.table);
}
Err(e) => {
println!("Error: {e:?}");
}
}
}