snarkvm_synthesizer_snark/certificate/
mod.rsuse super::*;
mod bytes;
mod parse;
mod serialize;
#[derive(Clone, PartialEq, Eq)]
pub struct Certificate<N: Network> {
certificate: varuna::Certificate<N::PairingCurve>,
}
impl<N: Network> Certificate<N> {
pub(super) const fn new(certificate: varuna::Certificate<N::PairingCurve>) -> Self {
Self { certificate }
}
pub fn certify(
function_name: &str,
proving_key: &ProvingKey<N>,
verifying_key: &VerifyingKey<N>,
) -> Result<Certificate<N>> {
#[cfg(feature = "aleo-cli")]
let timer = std::time::Instant::now();
let universal_prover = N::varuna_universal_prover();
let fiat_shamir = N::varuna_fs_parameters();
let certificate = Varuna::<N>::prove_vk(universal_prover, fiat_shamir, verifying_key, proving_key)?;
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Certified '{function_name}': {} ms", timer.elapsed().as_millis()).dimmed());
Ok(Self::new(certificate))
}
pub fn verify(
&self,
function_name: &str,
assignment: &circuit::Assignment<N::Field>,
verifying_key: &VerifyingKey<N>,
) -> bool {
#[cfg(feature = "aleo-cli")]
let timer = std::time::Instant::now();
let universal_verifier = N::varuna_universal_verifier();
let fiat_shamir = N::varuna_fs_parameters();
#[allow(clippy::manual_unwrap_or_default)]
match Varuna::<N>::verify_vk(universal_verifier, fiat_shamir, assignment, verifying_key, self) {
Ok(is_valid) => {
#[cfg(feature = "aleo-cli")]
{
let elapsed = timer.elapsed().as_millis();
println!("{}", format!(" • Verified certificate for '{function_name}': {elapsed} ms").dimmed());
}
is_valid
}
Err(error) => {
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Certificate verification failed: {error}").dimmed());
false
}
}
}
}
impl<N: Network> Deref for Certificate<N> {
type Target = varuna::Certificate<N::PairingCurve>;
fn deref(&self) -> &Self::Target {
&self.certificate
}
}