use super::{G1Affine, G2Affine};
#[cfg(feature = "blitzar")]
use blitzar::compute::{ElementP2, MsmHandle};
pub struct PublicParameters {
pub(super) Gamma_1: Vec<G1Affine>,
pub(super) Gamma_2: Vec<G2Affine>,
pub(super) H_1: G1Affine,
pub(super) H_2: G2Affine,
pub(super) Gamma_2_fin: G2Affine,
pub(super) max_nu: usize,
#[cfg(feature = "blitzar")]
pub(super) blitzar_handle: MsmHandle<ElementP2<ark_bls12_381::g1::Config>>,
}
impl Clone for PublicParameters {
fn clone(&self) -> Self {
#[cfg(feature = "blitzar")]
let blitzar_handle = compute_handle(&self.Gamma_1);
Self {
Gamma_1: self.Gamma_1.clone(),
Gamma_2: self.Gamma_2.clone(),
H_1: self.H_1,
H_2: self.H_2,
Gamma_2_fin: self.Gamma_2_fin,
max_nu: self.max_nu,
#[cfg(feature = "blitzar")]
blitzar_handle,
}
}
}
#[cfg(feature = "blitzar")]
fn compute_handle(Gamma_1: &[G1Affine]) -> MsmHandle<ElementP2<ark_bls12_381::g1::Config>> {
let gs: Vec<_> = Gamma_1.iter().copied().map(Into::into).collect();
blitzar::compute::MsmHandle::new(&gs)
}
impl PublicParameters {
#[cfg(any(test, feature = "test"))]
pub fn rand<R>(max_nu: usize, rng: &mut R) -> Self
where
R: ark_std::rand::Rng + ?Sized,
{
use ark_std::UniformRand;
let (Gamma_1, Gamma_2) = super::rand_G_vecs(max_nu, rng);
let (H_1, H_2) = (G1Affine::rand(rng), G2Affine::rand(rng));
let Gamma_2_fin = G2Affine::rand(rng);
#[cfg(feature = "blitzar")]
let blitzar_handle = compute_handle(&Gamma_1);
Self {
Gamma_1,
Gamma_2,
max_nu,
H_1,
H_2,
Gamma_2_fin,
#[cfg(feature = "blitzar")]
blitzar_handle,
}
}
#[cfg(feature = "blitzar")]
#[tracing::instrument(name = "PublicParameters::blitzar_msm", level = "debug", skip_all)]
pub(super) fn blitzar_msm(
&self,
res: &mut [ElementP2<ark_bls12_381::g1::Config>],
element_num_bytes: u32,
scalars: &[u8],
) {
self.blitzar_handle.msm(res, element_num_bytes, scalars)
}
}