snarkvm_synthesizer_snark/proving_key/
mod.rsuse super::*;
mod bytes;
mod parse;
mod serialize;
use std::collections::BTreeMap;
#[derive(Clone)]
pub struct ProvingKey<N: Network> {
proving_key: Arc<varuna::CircuitProvingKey<N::PairingCurve, varuna::VarunaHidingMode>>,
}
impl<N: Network> ProvingKey<N> {
pub const fn new(proving_key: Arc<varuna::CircuitProvingKey<N::PairingCurve, varuna::VarunaHidingMode>>) -> Self {
Self { proving_key }
}
pub fn prove<R: Rng + CryptoRng>(
&self,
function_name: &str,
assignment: &circuit::Assignment<N::Field>,
rng: &mut R,
) -> Result<Proof<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 proof = Proof::new(Varuna::<N>::prove(universal_prover, fiat_shamir, self, assignment, rng)?);
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Executed '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed());
Ok(proof)
}
#[allow(clippy::type_complexity)]
pub fn prove_batch<R: Rng + CryptoRng>(
locator: &str,
assignments: &[(ProvingKey<N>, Vec<circuit::Assignment<N::Field>>)],
rng: &mut R,
) -> Result<Proof<N>> {
#[cfg(feature = "aleo-cli")]
let timer = std::time::Instant::now();
let num_expected_instances = assignments.len();
let instances: BTreeMap<_, _> = assignments
.iter()
.map(|(proving_key, assignments)| (proving_key.deref(), assignments.as_slice()))
.collect();
ensure!(instances.len() == num_expected_instances, "Incorrect number of proving keys for batch proof");
let universal_prover = N::varuna_universal_prover();
let fiat_shamir = N::varuna_fs_parameters();
let batch_proof = Proof::new(Varuna::<N>::prove_batch(universal_prover, fiat_shamir, &instances, rng)?);
#[cfg(feature = "aleo-cli")]
println!("{}", format!(" • Executed '{locator}' (in {} ms)", timer.elapsed().as_millis()).dimmed());
Ok(batch_proof)
}
}
impl<N: Network> Deref for ProvingKey<N> {
type Target = varuna::CircuitProvingKey<N::PairingCurve, varuna::VarunaHidingMode>;
fn deref(&self) -> &Self::Target {
&self.proving_key
}
}