arnaucube
arnaucube/hyperplonkPublic Self-hosted repository
hyperplonk/hyperplonk/src/structs.rs
hyperplonk/src/structs.rsRaw
  1//! Main module for the HyperPlonk PolyIOP.
  2
  3use crate::{custom_gate::CustomizedGates, selectors::SelectorColumn};
  4use ark_ec::PairingEngine;
  5use ark_ff::PrimeField;
  6use ark_poly::DenseMultilinearExtension;
  7use ark_std::log2;
  8use pcs::PolynomialCommitmentScheme;
  9use poly_iop::prelude::{PermutationCheck, ZeroCheck};
 10use std::rc::Rc;
 11
 12/// The proof for the HyperPlonk PolyIOP, consists of the following:
 13///   - a batch commitment to all the witness MLEs
 14///   - a batch opening to all the MLEs at certain index
 15///   - the zero-check proof for checking custom gate-satisfiability
 16///   - the permutation-check proof for checking the copy constraints
 17#[derive(Clone, Debug, Default, PartialEq)]
 18pub struct HyperPlonkProof<E, PC, PCS>
 19where
 20    E: PairingEngine,
 21    PC: PermutationCheck<E, PCS>,
 22    PCS: PolynomialCommitmentScheme<E>,
 23{
 24    // =======================================================================
 25    // witness related
 26    // =======================================================================
 27    // PCS commit for witnesses
 28    pub w_merged_com: PCS::Commitment,
 29    // Batch opening for witness commitment
 30    // - PermCheck eval: 1 point
 31    // - ZeroCheck evals: #witness points
 32    // - public input eval: 1 point
 33    pub w_merged_batch_opening: PCS::BatchProof,
 34    // Evaluations of Witness
 35    // - PermCheck eval: 1 point
 36    // - ZeroCheck evals: #witness points
 37    // - public input eval: 1 point
 38    pub w_merged_batch_evals: Vec<E::Fr>,
 39    // =======================================================================
 40    // prod(x) related
 41    // =======================================================================
 42    // prod(x)'s openings
 43    // - prod(0, x),
 44    // - prod(1, x),
 45    // - prod(x, 0),
 46    // - prod(x, 1),
 47    // - prod(1, ..., 1,0)
 48    pub prod_batch_openings: PCS::BatchProof,
 49    // prod(x)'s evaluations
 50    // - prod(0, x),
 51    // - prod(1, x),
 52    // - prod(x, 0),
 53    // - prod(x, 1),
 54    // - prod(1, ..., 1,0)
 55    pub prod_batch_evals: Vec<E::Fr>,
 56    // =======================================================================
 57    // selectors related
 58    // =======================================================================
 59    // PCS openings for selectors on zero check point
 60    pub selector_batch_opening: PCS::BatchProof,
 61    // Evaluates of selectors on zero check point
 62    pub selector_batch_evals: Vec<E::Fr>,
 63    // =======================================================================
 64    // IOP proofs
 65    // =======================================================================
 66    // the custom gate zerocheck proof
 67    pub zero_check_proof: <PC as ZeroCheck<E::Fr>>::ZeroCheckProof,
 68    // the permutation check proof for copy constraints
 69    pub perm_check_proof: PC::PermutationProof,
 70}
 71
 72/// The HyperPlonk instance parameters, consists of the following:
 73///   - the number of constraints
 74///   - number of public input columns
 75///   - the customized gate function
 76#[derive(Clone, Debug, Default, PartialEq, Eq)]
 77pub struct HyperPlonkParams {
 78    /// the number of constraints
 79    pub num_constraints: usize,
 80    /// number of public input
 81    // public input is only 1 column and is implicitly the first witness column.
 82    // this size must not exceed number of constraints.
 83    pub num_pub_input: usize,
 84    /// customized gate function
 85    pub gate_func: CustomizedGates,
 86}
 87
 88impl HyperPlonkParams {
 89    /// Number of variables in a multilinear system
 90    pub fn num_variables(&self) -> usize {
 91        log2(self.num_constraints) as usize
 92    }
 93
 94    /// number of selector columns
 95    pub fn num_selector_columns(&self) -> usize {
 96        self.gate_func.num_selector_columns()
 97    }
 98
 99    /// number of witness columns
100    pub fn num_witness_columns(&self) -> usize {
101        self.gate_func.num_witness_columns()
102    }
103}
104
105/// The HyperPlonk index, consists of the following:
106///   - HyperPlonk parameters
107///   - the wire permutation
108///   - the selector vectors
109#[derive(Clone, Debug, Default, PartialEq, Eq)]
110pub struct HyperPlonkIndex<F: PrimeField> {
111    pub params: HyperPlonkParams,
112    pub permutation: Vec<F>,
113    pub selectors: Vec<SelectorColumn<F>>,
114}
115
116impl<F: PrimeField> HyperPlonkIndex<F> {
117    /// Number of variables in a multilinear system
118    pub fn num_variables(&self) -> usize {
119        self.params.num_variables()
120    }
121
122    /// number of selector columns
123    pub fn num_selector_columns(&self) -> usize {
124        self.params.num_selector_columns()
125    }
126
127    /// number of witness columns
128    pub fn num_witness_columns(&self) -> usize {
129        self.params.num_witness_columns()
130    }
131}
132
133/// The HyperPlonk proving key, consists of the following:
134///   - the hyperplonk instance parameters
135///   - the preprocessed polynomials output by the indexer
136///   - the commitment to the selectors
137///   - the parameters for polynomial commitment
138#[derive(Clone, Debug, Default, PartialEq)]
139pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
140    /// Hyperplonk instance parameters
141    pub params: HyperPlonkParams,
142    /// The preprocessed permutation polynomials
143    pub permutation_oracle: Rc<DenseMultilinearExtension<E::Fr>>,
144    /// The preprocessed selector polynomials
145    pub selector_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
146    /// A commitment to the preprocessed selector polynomials
147    pub selector_com: PCS::Commitment,
148    /// The parameters for PCS commitment
149    pub pcs_param: PCS::ProverParam,
150}
151
152/// The HyperPlonk verifying key, consists of the following:
153///   - the hyperplonk instance parameters
154///   - the commitments to the preprocessed polynomials output by the indexer
155///   - the parameters for polynomial commitment
156#[derive(Clone, Debug, Default, PartialEq)]
157pub struct HyperPlonkVerifyingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
158    /// Hyperplonk instance parameters
159    pub params: HyperPlonkParams,
160    /// The preprocessed permutation polynomials
161    pub permutation_oracle: Rc<DenseMultilinearExtension<E::Fr>>,
162    /// The parameters for PCS commitment
163    pub pcs_param: PCS::VerifierParam,
164    /// A commitment to the preprocessed selector polynomials
165    pub selector_com: PCS::Commitment,
166    /// Permutation oracle's commitment
167    pub perm_com: PCS::Commitment,
168}