arnaucube
arnaucube/hyperplonkPublic Self-hosted repository
hyperplonk/poly-iop/src/hyperplonk/mod.rs
poly-iop/src/hyperplonk/mod.rsRaw
  1//! Main module for the HyperPlonk PolyIOP.
  2
  3use crate::{errors::PolyIOPErrors, perm_check::PermutationCheck, zero_check::ZeroCheck};
  4use ark_ff::PrimeField;
  5use ark_poly::DenseMultilinearExtension;
  6use std::rc::Rc;
  7use transcript::IOPTranscript;
  8
  9/// A trait for HyperPlonk Poly-IOPs
 10pub trait HyperPlonkPIOP<F: PrimeField> {
 11    type Parameters;
 12    type ProvingKey;
 13    type Proof;
 14    type SubClaim;
 15
 16    /// Generate the preprocessed polynomials output by the indexer.
 17    ///
 18    /// Inputs:
 19    /// - `params`: HyperPlonk instance parameters
 20    /// - `permutation`: the permutation for the copy constraints
 21    /// - `selectors`: the list of selector vectors for custom gates
 22    /// Outputs:
 23    /// - The HyperPlonk proving key, which includes the preprocessed
 24    ///   polynomials.
 25    fn preprocess(
 26        params: &Self::Parameters,
 27        permutation: &[F],
 28        selectors: &[&[F]],
 29    ) -> Result<Self::ProvingKey, PolyIOPErrors>;
 30
 31    /// Generate HyperPlonk PIOP proof.
 32    ///
 33    /// Inputs:
 34    /// - `pk`: circuit proving key
 35    /// - `pub_input`: online public input
 36    /// - `witness`: witness assignement
 37    /// - `transcript`: the transcript used for generating pseudorandom
 38    ///   challenges
 39    /// Outputs:
 40    /// - The HyperPlonk PIOP proof.
 41    fn prove(
 42        pk: &Self::ProvingKey,
 43        pub_input: &[F],
 44        witness: &[&[F]],
 45        transcript: &mut IOPTranscript<F>,
 46    ) -> Result<Self::Proof, PolyIOPErrors>;
 47
 48    /// Verify the HyperPlonk proof and generate the evaluation subclaims to be
 49    /// checked later by the SNARK verifier.
 50    ///
 51    /// Inputs:
 52    /// - `params`: instance parameter
 53    /// - `pub_input`: online public input
 54    /// - `proof`: HyperPlonk PIOP proof
 55    /// - `transcript`: the transcript used for generating pseudorandom
 56    ///   challenges
 57    /// Outputs:
 58    /// - Return error if the verification fails, otherwise return the
 59    ///   evaluation subclaim
 60    fn verify(
 61        params: &Self::Parameters,
 62        pub_input: &[F],
 63        proof: &Self::Proof,
 64        transcript: &mut IOPTranscript<F>,
 65    ) -> Result<Self::SubClaim, PolyIOPErrors>;
 66}
 67
 68/// The sub-claim for the HyperPlonk PolyIOP, consists of the following:
 69///   - the SubClaim for the zero-check PIOP
 70///   - the SubClaim for the permutation-check PIOP
 71///   - the SubClaim for public input consistency
 72#[derive(Clone, Debug, Default, PartialEq)]
 73pub struct HyperPlonkSubClaim<F: PrimeField, ZC: ZeroCheck<F>, PC: PermutationCheck<F>> {
 74    /// the SubClaim for the custom gate zerocheck
 75    pub zero_check_sub_claim: ZC::ZeroCheckSubClaim,
 76    /// the SubClaim for the permutation check
 77    pub perm_check_sub_claim: PC::PermutationCheckSubClaim,
 78    /// the public input consistency check
 79    pub pub_input_sub_claim: (Vec<F>, F), // (point, expected_eval)
 80}
 81
 82/// The proof for the HyperPlonk PolyIOP, consists of the following:
 83///   - the zero-check proof for checking custom gate-satisfiability
 84///   - the permutation-check proof for checking the copy constraints
 85#[derive(Clone, Debug, Default, PartialEq)]
 86pub struct HyperPlonkProof<F: PrimeField, ZC: ZeroCheck<F>, PC: PermutationCheck<F>> {
 87    /// the custom gate zerocheck proof
 88    pub zero_check_proof: ZC::Proof,
 89    /// the permutation check proof for copy constraints
 90    pub perm_check_proof: PC::Proof,
 91}
 92
 93/// The HyperPlonk instance parameters, consists of the following:
 94///   - the number of variables in the poly-IOP
 95///   - binary log of the number of public input variables
 96///   - binary log of the number of selectors
 97///   - binary log of the number of witness wires
 98///   - the customized gate function
 99#[derive(Clone, Debug, Default, PartialEq)]
100pub struct HyperPlonkParams {
101    /// the number of variables in polys
102    pub nv: usize,
103    /// binary log of the public input length
104    pub log_pub_input_len: usize,
105    // binary log of the number of selectors
106    pub log_n_selectors: usize,
107    /// binary log of the number of witness wires
108    pub log_n_wires: usize,
109    /// customized gate function
110    // TODO: define a struct for it.
111    pub gate_func: Vec<Vec<usize>>,
112}
113
114/// The HyperPlonk proving key, consists of the following:
115///   - the hyperplonk instance parameters
116///   - the preprocessed polynomials output by the indexer
117#[derive(Clone, Debug, Default, PartialEq)]
118pub struct HyperPlonkProvingKey<F: PrimeField> {
119    /// hyperplonk instance parameters
120    pub params: HyperPlonkParams,
121    /// the preprocessed index polynomials
122    pub index_oracles: Vec<Rc<DenseMultilinearExtension<F>>>,
123}
124
125#[cfg(test)]
126mod test {}