use super::*;
mod bytes;
mod parse;
mod serialize;
use std::collections::BTreeMap;
#[derive(Clone, PartialEq, Eq)]
pub struct VerifyingKey<N: Network> {
verifying_key: Arc<varuna::CircuitVerifyingKey<N::PairingCurve>>,
}
impl<N: Network> VerifyingKey<N> {
pub const fn new(verifying_key: Arc<varuna::CircuitVerifyingKey<N::PairingCurve>>) -> Self {
Self { verifying_key }
}
pub fn verify(&self, function_name: &str, inputs: &[N::Field], proof: &Proof<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();
match Varuna::<N>::verify(universal_verifier, fiat_shamir, self, inputs, proof) {
Ok(is_valid) => {
#[cfg(feature = "aleo-cli")]
println!(
"{}",
format!(" • Verified '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()
);
is_valid
}
Err(error) => {
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Verifier failed: {error}").dimmed());
false
}
}
}
#[allow(clippy::type_complexity)]
pub fn verify_batch(locator: &str, inputs: Vec<(VerifyingKey<N>, Vec<Vec<N::Field>>)>, proof: &Proof<N>) -> bool {
#[cfg(feature = "aleo-cli")]
let timer = std::time::Instant::now();
let keys_to_inputs: BTreeMap<_, _> =
inputs.iter().map(|(verifying_key, inputs)| (verifying_key.deref(), inputs.as_slice())).collect();
let universal_verifier = N::varuna_universal_verifier();
let fiat_shamir = N::varuna_fs_parameters();
match Varuna::<N>::verify_batch(universal_verifier, fiat_shamir, &keys_to_inputs, proof) {
Ok(is_valid) => {
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Verified '{locator}' (in {} ms)", timer.elapsed().as_millis()).dimmed());
is_valid
}
Err(error) => {
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Verifier failed: {error}").dimmed());
false
}
}
}
}
impl<N: Network> Deref for VerifyingKey<N> {
type Target = varuna::CircuitVerifyingKey<N::PairingCurve>;
fn deref(&self) -> &Self::Target {
&self.verifying_key
}
}