use crate::{
polycommit::sonic_pc,
snark::varuna::{ahp::indexer::*, CircuitVerifyingKey, SNARKMode},
};
use snarkvm_curves::PairingEngine;
use snarkvm_utilities::{
io::{self, Read, Write},
serialize::*,
FromBytes,
ToBytes,
};
use std::{cmp::Ordering, sync::Arc};
#[derive(Clone, Debug)]
pub struct CircuitProvingKey<E: PairingEngine, SM: SNARKMode> {
pub circuit_verifying_key: CircuitVerifyingKey<E>,
pub circuit: Arc<Circuit<E::Fr, SM>>,
pub committer_key: Arc<sonic_pc::CommitterKey<E>>,
}
impl<E: PairingEngine, SM: SNARKMode> ToBytes for CircuitProvingKey<E, SM> {
fn write_le<W: Write>(&self, mut writer: W) -> io::Result<()> {
CanonicalSerialize::serialize_compressed(&self.circuit_verifying_key, &mut writer)?;
CanonicalSerialize::serialize_compressed(&self.circuit, &mut writer)?;
self.committer_key.write_le(&mut writer)
}
}
impl<E: PairingEngine, SM: SNARKMode> FromBytes for CircuitProvingKey<E, SM> {
#[inline]
fn read_le<R: Read>(mut reader: R) -> io::Result<Self> {
let circuit_verifying_key = CanonicalDeserialize::deserialize_compressed(&mut reader)?;
let circuit = CanonicalDeserialize::deserialize_compressed(&mut reader)?;
let committer_key = Arc::new(FromBytes::read_le(&mut reader)?);
Ok(Self { circuit_verifying_key, circuit, committer_key })
}
}
impl<E: PairingEngine, SM: SNARKMode> PartialEq for CircuitProvingKey<E, SM> {
fn eq(&self, other: &Self) -> bool {
self.circuit.id == other.circuit.id
}
}
impl<E: PairingEngine, SM: SNARKMode> Eq for CircuitProvingKey<E, SM> {}
impl<E: PairingEngine, SM: SNARKMode> Ord for CircuitProvingKey<E, SM> {
fn cmp(&self, other: &Self) -> Ordering {
self.circuit.id.cmp(&other.circuit.id)
}
}
impl<E: PairingEngine, SM: SNARKMode> PartialOrd for CircuitProvingKey<E, SM> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}