pub mod errors;
pub mod key;
pub mod srs;
pub use key::{CommitKey, OpeningKey};
pub use srs::PublicParameters;
use crate::transcript::TranscriptProtocol;
use crate::util::powers_of;
use dusk_bls12_381::{G1Affine, G1Projective, Scalar};
use merlin::Transcript;
#[derive(Copy, Clone, Debug)]
pub struct Proof {
pub commitment_to_witness: Commitment,
pub evaluated_point: Scalar,
pub commitment_to_polynomial: Commitment,
}
#[derive(Debug)]
pub struct AggregateProof {
pub commitment_to_witness: Commitment,
pub evaluated_points: Vec<Scalar>,
pub commitments_to_polynomials: Vec<Commitment>,
}
impl AggregateProof {
pub fn with_witness(witness: Commitment) -> AggregateProof {
AggregateProof {
commitment_to_witness: witness,
evaluated_points: Vec::new(),
commitments_to_polynomials: Vec::new(),
}
}
pub fn add_part(&mut self, part: (Scalar, Commitment)) {
self.evaluated_points.push(part.0);
self.commitments_to_polynomials.push(part.1);
}
pub fn flatten(&self, transcript: &mut Transcript) -> Proof {
let challenge = transcript.challenge_scalar(b"aggregate_witness");
let powers = powers_of(&challenge, self.commitments_to_polynomials.len() - 1);
let flattened_poly_commitments: G1Projective = self
.commitments_to_polynomials
.iter()
.zip(powers.iter())
.map(|(poly, challenge)| poly.0 * challenge)
.sum();
let flattened_poly_evaluations: Scalar = self
.evaluated_points
.iter()
.zip(powers.iter())
.map(|(eval, challenge)| eval * challenge)
.fold(Scalar::zero(), |acc, current_val| acc + current_val);
Proof {
commitment_to_witness: self.commitment_to_witness,
evaluated_point: flattened_poly_evaluations,
commitment_to_polynomial: Commitment::from_projective(flattened_poly_commitments),
}
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Commitment(
pub G1Affine,
);
impl Commitment {
pub fn from_projective(g: G1Projective) -> Self {
Self(g.into())
}
pub fn from_affine(g: G1Affine) -> Self {
Self(g)
}
pub fn empty() -> Self {
Commitment(G1Affine::identity())
}
}
impl Default for Commitment {
fn default() -> Self {
Commitment::empty()
}
}