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
92
93
94
95
96
97
98
99
100
101
102
103
use std::time::Instant;
use crate::error::Result;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use crate::SP_LOG;
pub trait ProofScheme<'a> {
type PublicParams: Clone;
type SetupParams;
type PublicInputs: Clone;
type PrivateInputs;
type Proof: Clone + Serialize + DeserializeOwned;
type Requirements: Default;
fn setup(_: &Self::SetupParams) -> Result<Self::PublicParams>;
fn prove<'b>(
_: &'b Self::PublicParams,
_: &'b Self::PublicInputs,
_: &'b Self::PrivateInputs,
) -> Result<Self::Proof>;
fn prove_all_partitions<'b>(
pub_params: &'b Self::PublicParams,
pub_in: &'b Self::PublicInputs,
priv_in: &'b Self::PrivateInputs,
partition_count: usize,
) -> Result<Vec<Self::Proof>> {
info!(SP_LOG, "groth_proof_count: {}", partition_count; "target" => "stats");
info!(SP_LOG, "generating {} groth proofs.", partition_count; "target" => "groth_proving");
let start = Instant::now();
let result = (0..partition_count)
.map(|k| {
info!(SP_LOG, "generating groth proof {}.", k; "target" => "groth_proving");
let start = Instant::now();
let partition_pub_in = Self::with_partition((*pub_in).clone(), Some(k));
let proof = Self::prove(pub_params, &partition_pub_in, priv_in);
let proof_time = start.elapsed();
info!(SP_LOG, "groth_proof_time: {:?}", proof_time; "target" => "stats");
proof
})
.collect::<Result<Vec<Self::Proof>>>();
let total_proof_time = start.elapsed();
info!(SP_LOG, "total_groth_proof_time: {:?}", total_proof_time; "target" => "stats");
result
}
fn verify(
_pub_params: &Self::PublicParams,
_pub_inputs: &Self::PublicInputs,
_proof: &Self::Proof,
) -> Result<bool> {
unimplemented!();
}
fn verify_all_partitions(
pub_params: &Self::PublicParams,
pub_in: &Self::PublicInputs,
proofs: &[Self::Proof],
) -> Result<bool> {
for (k, proof) in proofs.iter().enumerate() {
let partition_pub_in = Self::with_partition((*pub_in).clone(), Some(k));
if !Self::verify(pub_params, &partition_pub_in, proof)? {
return Ok(false);
}
}
Ok(true)
}
fn with_partition(pub_in: Self::PublicInputs, _k: Option<usize>) -> Self::PublicInputs {
pub_in
}
fn satisfies_requirements(
_pub_params: &Self::PublicParams,
_requirements: &Self::Requirements,
_partitions: usize,
) -> bool {
true
}
}
#[derive(Default)]
pub struct NoRequirements;