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