use crate::errors::NovaError;
#[cfg(feature = "io")]
use crate::provider::ptau::PtauFileError;
use crate::traits::{AbsorbInRO2Trait, AbsorbInROTrait, Engine, TranscriptReprTrait};
use core::{
fmt::Debug,
ops::{Add, Mul, MulAssign, Range},
};
use num_integer::Integer;
use num_traits::ToPrimitive;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use serde::{Deserialize, Serialize};
pub trait ScalarMul<Rhs, Output = Self>: Mul<Rhs, Output = Output> + MulAssign<Rhs> {}
impl<T, Rhs, Output> ScalarMul<Rhs, Output> for T where T: Mul<Rhs, Output = Output> + MulAssign<Rhs>
{}
pub trait CommitmentTrait<E: Engine>:
Clone
+ Copy
+ Debug
+ Default
+ PartialEq
+ Eq
+ Send
+ Sync
+ TranscriptReprTrait<E::GE>
+ Serialize
+ for<'de> Deserialize<'de>
+ AbsorbInROTrait<E>
+ AbsorbInRO2Trait<E>
+ Add<Self, Output = Self>
+ ScalarMul<E::Scalar>
{
fn to_coordinates(&self) -> (E::Base, E::Base, bool);
}
pub trait Len {
fn length(&self) -> usize;
}
pub trait CommitmentEngineTrait<E: Engine>: Clone + Send + Sync {
type CommitmentKey: Len + Clone + Debug + Send + Sync + Serialize + for<'de> Deserialize<'de>;
type DerandKey: Clone + Debug + Send + Sync + Serialize + for<'de> Deserialize<'de>;
type Commitment: CommitmentTrait<E>;
#[cfg(feature = "io")]
fn load_setup(
reader: &mut (impl std::io::Read + std::io::Seek),
label: &'static [u8],
n: usize,
) -> Result<Self::CommitmentKey, PtauFileError>;
#[cfg(feature = "io")]
fn save_setup(
ck: &Self::CommitmentKey,
writer: &mut (impl std::io::Write + std::io::Seek),
) -> Result<(), PtauFileError>;
fn setup(label: &'static [u8], n: usize)
-> Result<Self::CommitmentKey, crate::errors::NovaError>;
fn derand_key(ck: &Self::CommitmentKey) -> Self::DerandKey;
fn commit(ck: &Self::CommitmentKey, v: &[E::Scalar], r: &E::Scalar) -> Self::Commitment;
fn batch_commit(
ck: &Self::CommitmentKey,
v: &[Vec<E::Scalar>],
r: &[E::Scalar],
) -> Vec<Self::Commitment> {
assert!(v.len() == r.len());
v.par_iter()
.zip(r.par_iter())
.map(|(v_i, r_i)| Self::commit(ck, v_i, r_i))
.collect()
}
fn commit_sparse_binary(
ck: &Self::CommitmentKey,
non_zero_indices: &[usize],
r: &E::Scalar,
) -> Self::Commitment;
fn commit_small<T: Integer + Into<u64> + Copy + Sync + ToPrimitive>(
ck: &Self::CommitmentKey,
v: &[T],
r: &E::Scalar,
) -> Self::Commitment;
fn commit_small_range<T: Integer + Into<u64> + Copy + Sync + ToPrimitive>(
ck: &Self::CommitmentKey,
v: &[T],
r: &E::Scalar,
range: Range<usize>,
max_num_bits: usize,
) -> Self::Commitment;
fn batch_commit_small<T: Integer + Into<u64> + Copy + Sync + ToPrimitive>(
ck: &Self::CommitmentKey,
v: &[Vec<T>],
r: &[E::Scalar],
) -> Vec<Self::Commitment> {
assert!(v.len() == r.len());
v.par_iter()
.zip(r.par_iter())
.map(|(v_i, r_i)| Self::commit_small(ck, v_i, r_i))
.collect()
}
fn derandomize(
dk: &Self::DerandKey,
commit: &Self::Commitment,
r: &E::Scalar,
) -> Self::Commitment;
fn ck_to_coordinates(ck: &Self::CommitmentKey) -> Vec<(E::Base, E::Base)>;
fn ck_to_group_elements(ck: &Self::CommitmentKey) -> Vec<E::GE>;
fn ck_derive_by_address(
ck: &Self::CommitmentKey,
addresses: &[usize],
table_size: usize,
) -> Result<Self::CommitmentKey, NovaError>;
}