use std::time::Instant;
use log::info;
use serde::{de::DeserializeOwned, Serialize};
use crate::error::Result;
pub trait ProofScheme<'a> {
type PublicParams: Clone;
type SetupParams: Clone;
type PublicInputs: Clone + Serialize + DeserializeOwned;
type PrivateInputs;
type Proof: Clone + Serialize + DeserializeOwned;
type Requirements: Default;
fn setup(_: &Self::SetupParams) -> Result<Self::PublicParams>;
fn prove(
_: &Self::PublicParams,
_: &Self::PublicInputs,
_: &Self::PrivateInputs,
) -> Result<Self::Proof>;
fn prove_all_partitions(
pub_params: &Self::PublicParams,
pub_in: &Self::PublicInputs,
priv_in: &Self::PrivateInputs,
partition_count: usize,
) -> Result<Vec<Self::Proof>> {
info!("groth_proof_count: {}", partition_count);
info!("generating {} groth proofs.", partition_count);
let start = Instant::now();
let result = (0..partition_count)
.map(|k| {
info!("generating groth proof {}.", k);
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!("groth_proof_time: {:?}", proof_time);
proof
})
.collect::<Result<Vec<Self::Proof>>>();
let total_proof_time = start.elapsed();
info!("total_groth_proof_time: {:?}", total_proof_time);
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;