#![no_std]
#![warn(
unused,
future_incompatible,
nonstandard_style,
rust_2018_idioms,
missing_docs
)]
#![forbid(unsafe_code)]
use ark_ff::PrimeField;
use ark_relations::gr1cs::ConstraintSynthesizer;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{
fmt::Debug,
rand::{CryptoRng, RngCore},
};
pub trait SNARK<F: PrimeField> {
type ProvingKey: Clone + CanonicalSerialize + CanonicalDeserialize;
type VerifyingKey: Clone + CanonicalSerialize + CanonicalDeserialize;
type Proof: Clone + CanonicalSerialize + CanonicalDeserialize;
type ProcessedVerifyingKey: Clone + CanonicalSerialize + CanonicalDeserialize;
type Error: 'static + ark_std::error::Error;
fn circuit_specific_setup<C: ConstraintSynthesizer<F>, R: RngCore + CryptoRng>(
circuit: C,
rng: &mut R,
) -> Result<(Self::ProvingKey, Self::VerifyingKey), Self::Error>;
fn prove<C: ConstraintSynthesizer<F>, R: RngCore + CryptoRng>(
circuit_pk: &Self::ProvingKey,
circuit: C,
rng: &mut R,
) -> Result<Self::Proof, Self::Error>;
fn verify(
circuit_vk: &Self::VerifyingKey,
public_input: &[F],
proof: &Self::Proof,
) -> Result<bool, Self::Error> {
let pvk = Self::process_vk(circuit_vk)?;
Self::verify_with_processed_vk(&pvk, public_input, proof)
}
fn process_vk(
circuit_vk: &Self::VerifyingKey,
) -> Result<Self::ProcessedVerifyingKey, Self::Error>;
fn verify_with_processed_vk(
circuit_pvk: &Self::ProcessedVerifyingKey,
public_input: &[F],
proof: &Self::Proof,
) -> Result<bool, Self::Error>;
}
pub trait CircuitSpecificSetupSNARK<F: PrimeField>: SNARK<F> {
fn setup<C: ConstraintSynthesizer<F>, R: RngCore + CryptoRng>(
circuit: C,
rng: &mut R,
) -> Result<(Self::ProvingKey, Self::VerifyingKey), Self::Error> {
<Self as SNARK<F>>::circuit_specific_setup(circuit, rng)
}
}
pub enum UniversalSetupIndexError<Bound, E> {
NeedLargerBound(Bound),
Other(E),
}
pub trait UniversalSetupSNARK<F: PrimeField>: SNARK<F> {
type ComputationBound: Clone + Default + Debug;
type PublicParameters: Clone + Debug;
fn universal_setup<R: RngCore + CryptoRng>(
compute_bound: &Self::ComputationBound,
rng: &mut R,
) -> Result<Self::PublicParameters, Self::Error>;
fn index<C: ConstraintSynthesizer<F>, R: RngCore + CryptoRng>(
pp: &Self::PublicParameters,
circuit: C,
rng: &mut R,
) -> Result<
(Self::ProvingKey, Self::VerifyingKey),
UniversalSetupIndexError<Self::ComputationBound, Self::Error>,
>;
}