//! This module defines a collection of traits that define the behavior of a commitment engine //! We require the commitment engine to provide a commitment to vectors with a single group element use crate::{ errors::NovaError, traits::{AbsorbInROTrait, Group, TranscriptReprTrait}, }; use core::{ fmt::Debug, ops::{Add, AddAssign}, }; use serde::{Deserialize, Serialize}; use super::ScalarMul; /// Defines basic operations on commitments pub trait CommitmentOps: Add + AddAssign { } impl CommitmentOps for T where T: Add + AddAssign { } /// A helper trait for references with a commitment operation pub trait CommitmentOpsOwned: for<'r> CommitmentOps<&'r Rhs, Output> { } impl CommitmentOpsOwned for T where T: for<'r> CommitmentOps<&'r Rhs, Output> { } /// This trait defines the behavior of the commitment pub trait CommitmentTrait: Clone + Copy + Debug + Default + PartialEq + Eq + Send + Sync + TranscriptReprTrait + Serialize + for<'de> Deserialize<'de> + AbsorbInROTrait + CommitmentOps + CommitmentOpsOwned + ScalarMul { /// Holds the type of the compressed commitment type CompressedCommitment: Clone + Debug + PartialEq + Eq + Send + Sync + TranscriptReprTrait + Serialize + for<'de> Deserialize<'de>; /// Compresses self into a compressed commitment fn compress(&self) -> Self::CompressedCommitment; /// Returns the coordinate representation of the commitment fn to_coordinates(&self) -> (G::Base, G::Base, bool); /// Decompresses a compressed commitment into a commitment fn decompress(c: &Self::CompressedCommitment) -> Result; } /// A trait that ties different pieces of the commitment generation together pub trait CommitmentEngineTrait: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de> { /// Holds the type of the commitment key type CommitmentKey: Clone + Debug + Send + Sync + Serialize + for<'de> Deserialize<'de>; /// Holds the type of the commitment type Commitment: CommitmentTrait; /// Samples a new commitment key of a specified size fn setup(label: &'static [u8], n: usize) -> Self::CommitmentKey; /// Commits to the provided vector using the provided generators fn commit(ck: &Self::CommitmentKey, v: &[G::Scalar]) -> Self::Commitment; }