hyperplonk/hyperplonk/src/lib.rs
hyperplonk/src/lib.rsRaw
1// Copyright (c) 2023 Espresso Systems (espressosys.com)
2// This file is part of the HyperPlonk library.
3
4// You should have received a copy of the MIT License
5// along with the HyperPlonk library. If not, see <https://mit-license.org/>.
6
7//! Main module for the HyperPlonk SNARK.
8
9use ark_ec::pairing::Pairing;
10use errors::HyperPlonkErrors;
11use subroutines::{pcs::prelude::PolynomialCommitmentScheme, poly_iop::prelude::PermutationCheck};
12use witness::WitnessColumn;
13
14mod custom_gate;
15mod errors;
16mod mock;
17pub mod prelude;
18mod selectors;
19mod snark;
20mod structs;
21mod utils;
22mod witness;
23
24/// A trait for HyperPlonk SNARKs.
25/// A HyperPlonk is derived from ZeroChecks and PermutationChecks.
26pub trait HyperPlonkSNARK<E, PCS>: PermutationCheck<E, PCS>
27where
28 E: Pairing,
29 PCS: PolynomialCommitmentScheme<E>,
30{
31 type Index;
32 type ProvingKey;
33 type VerifyingKey;
34 type Proof;
35
36 /// Generate the preprocessed polynomials output by the indexer.
37 ///
38 /// Inputs:
39 /// - `index`: HyperPlonk index
40 /// - `pcs_srs`: Polynomial commitment structured reference string
41 /// Outputs:
42 /// - The HyperPlonk proving key, which includes the preprocessed
43 /// polynomials.
44 /// - The HyperPlonk verifying key, which includes the preprocessed
45 /// polynomial commitments
46 fn preprocess(
47 index: &Self::Index,
48 pcs_srs: &PCS::SRS,
49 ) -> Result<(Self::ProvingKey, Self::VerifyingKey), HyperPlonkErrors>;
50
51 /// Generate HyperPlonk SNARK proof.
52 ///
53 /// Inputs:
54 /// - `pk`: circuit proving key
55 /// - `pub_input`: online public input
56 /// - `witness`: witness assignment
57 /// Outputs:
58 /// - The HyperPlonk SNARK proof.
59 fn prove(
60 pk: &Self::ProvingKey,
61 pub_input: &[E::ScalarField],
62 witnesses: &[WitnessColumn<E::ScalarField>],
63 ) -> Result<Self::Proof, HyperPlonkErrors>;
64
65 /// Verify the HyperPlonk proof.
66 ///
67 /// Inputs:
68 /// - `vk`: verifying key
69 /// - `pub_input`: online public input
70 /// - `proof`: HyperPlonk SNARK proof challenges
71 /// Outputs:
72 /// - Return a boolean on whether the verification is successful
73 fn verify(
74 vk: &Self::VerifyingKey,
75 pub_input: &[E::ScalarField],
76 proof: &Self::Proof,
77 ) -> Result<bool, HyperPlonkErrors>;
78}