//! An implementation of the [`Groth16`] zkSNARK. //! //! [`Groth16`]: https://eprint.iacr.org/2016/260.pdf #![cfg_attr(not(feature = "std"), no_std)] #![warn( unused, future_incompatible, nonstandard_style, rust_2018_idioms, missing_docs )] #![allow(clippy::many_single_char_names, clippy::op_ref)] #![forbid(unsafe_code)] #[macro_use] extern crate ark_std; /// Reduce an R1CS instance to a *Quadratic Arithmetic Program* instance. pub mod r1cs_to_qap; /// Data structures used by the prover, verifier, and generator. pub mod data_structures; /// Generate public parameters for the Groth16 zkSNARK construction. pub mod generator; /// Create proofs for the Groth16 zkSNARK construction. pub mod prover; /// Verify proofs for the Groth16 zkSNARK construction. pub mod verifier; /// Constraints for the Groth16 verifier. #[cfg(feature = "r1cs")] pub mod constraints; #[cfg(test)] mod test; pub use self::{data_structures::*, verifier::*}; use ark_ec::pairing::Pairing; use ark_relations::gr1cs::{ConstraintSynthesizer, SynthesisError}; use ark_snark::*; use ark_std::{marker::PhantomData, rand::RngCore, vec::Vec}; use r1cs_to_qap::{LibsnarkReduction, R1CSToQAP}; /// The SNARK of [[Groth16]](https://eprint.iacr.org/2016/260.pdf). pub struct Groth16 { _p: PhantomData<(E, QAP)>, } impl SNARK for Groth16 { type ProvingKey = ProvingKey; type VerifyingKey = VerifyingKey; type Proof = Proof; type ProcessedVerifyingKey = PreparedVerifyingKey; type Error = SynthesisError; fn circuit_specific_setup, R: RngCore>( circuit: C, rng: &mut R, ) -> Result<(Self::ProvingKey, Self::VerifyingKey), Self::Error> where C: ConstraintSynthesizer, R: RngCore, { let pk = Self::generate_random_parameters_with_reduction(circuit, rng)?; let vk = pk.vk.clone(); Ok((pk, vk)) } fn prove, R: RngCore>( pk: &Self::ProvingKey, circuit: C, rng: &mut R, ) -> Result { Self::create_random_proof_with_reduction(circuit, pk, rng) } fn process_vk( circuit_vk: &Self::VerifyingKey, ) -> Result { Ok(prepare_verifying_key(circuit_vk)) } fn verify_with_processed_vk( circuit_pvk: &Self::ProcessedVerifyingKey, x: &[E::ScalarField], proof: &Self::Proof, ) -> Result { Ok(Self::verify_proof(&circuit_pvk, proof, &x)?) } } impl CircuitSpecificSetupSNARK for Groth16 {}