use crate::{
errors::SpartanError,
traits::{Engine, TranscriptReprTrait},
};
use core::fmt::Debug;
use serde::{Deserialize, Serialize};
pub trait CommitmentTrait<E: Engine>:
Clone
+ Debug
+ PartialEq
+ Eq
+ Send
+ Sync
+ TranscriptReprTrait<E::GE>
+ Serialize
+ for<'de> Deserialize<'de>
{
}
pub trait PCSEngineTrait<E: Engine>: Clone + Send + Sync {
type CommitmentKey: Clone + Debug + Send + Sync + Serialize + for<'de> Deserialize<'de>;
type VerifierKey: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
type Commitment: CommitmentTrait<E>;
type Blind: Clone + Debug + Send + Sync + PartialEq + Eq + Serialize + for<'de> Deserialize<'de>;
type EvaluationArgument: Clone + Debug + Send + Sync + Serialize + for<'de> Deserialize<'de>;
fn setup(
label: &'static [u8],
n: usize,
width: usize,
) -> (Self::CommitmentKey, Self::VerifierKey);
fn blind(ck: &Self::CommitmentKey, n: usize) -> Self::Blind;
fn commit(
ck: &Self::CommitmentKey,
v: &[E::Scalar],
r: &Self::Blind,
is_small: bool,
) -> Result<Self::Commitment, SpartanError>;
fn check_commitment(comm: &Self::Commitment, n: usize, width: usize) -> Result<(), SpartanError>;
fn rerandomize_commitment(
ck: &Self::CommitmentKey,
comm: &Self::Commitment,
r_old: &Self::Blind,
r_new: &Self::Blind,
) -> Result<Self::Commitment, SpartanError>;
fn combine_commitments(comms: &[Self::Commitment]) -> Result<Self::Commitment, SpartanError>;
fn combine_blinds(blinds: &[Self::Blind]) -> Result<Self::Blind, SpartanError>;
fn prove(
ck: &Self::CommitmentKey,
ck_eval: &Self::CommitmentKey,
transcript: &mut E::TE,
comm: &Self::Commitment,
poly: &[E::Scalar],
blind: &Self::Blind,
point: &[E::Scalar],
comm_eval: &Self::Commitment,
blind_eval: &Self::Blind,
) -> Result<Self::EvaluationArgument, SpartanError>;
fn verify(
vk: &Self::VerifierKey,
ck_eval: &Self::CommitmentKey,
transcript: &mut E::TE,
comm: &Self::Commitment,
point: &[E::Scalar],
comm_eval: &Self::Commitment,
arg: &Self::EvaluationArgument,
) -> Result<(), SpartanError>;
}
pub trait FoldingEngineTrait<E: Engine>: PCSEngineTrait<E> {
fn fold_commitments(
comms: &[Self::Commitment],
weights: &[E::Scalar],
) -> Result<Self::Commitment, SpartanError>;
fn fold_blinds(
blinds: &[Self::Blind],
weights: &[E::Scalar],
) -> Result<Self::Blind, SpartanError>;
}