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 std::rc::Rc;
9use subroutines::{
10 pcs::PolynomialCommitmentScheme,
11 poly_iop::prelude::{PermutationCheck, ZeroCheck},
12};
13
14/// The proof for the HyperPlonk PolyIOP, consists of the following:
15/// - a batch commitment to all the witness MLEs
16/// - a batch opening to all the MLEs at certain index
17/// - the zero-check proof for checking custom gate-satisfiability
18/// - the permutation-check proof for checking the copy constraints
19#[derive(Clone, Debug, PartialEq)]
20pub struct HyperPlonkProof<E, PC, PCS>
21where
22 E: PairingEngine,
23 PC: PermutationCheck<E, PCS>,
24 PCS: PolynomialCommitmentScheme<E>,
25{
26 // PCS commit for witnesses
27 pub witness_merged_commit: PCS::Commitment,
28 pub witness_commits: Vec<PCS::Commitment>,
29 pub batch_prod_x_openings: PCS::BatchProof,
30 pub batch_witness_and_selector_openings: PCS::BatchProof,
31 pub perm_check_opening: PCS::Proof,
32 pub perm_check_eval: PCS::Evaluation,
33 // =======================================================================
34 // IOP proofs
35 // =======================================================================
36 // the custom gate zerocheck proof
37 pub zero_check_proof: <PC as ZeroCheck<E::Fr>>::ZeroCheckProof,
38 // the permutation check proof for copy constraints
39 pub perm_check_proof: PC::PermutationProof,
40}
41
42/// The HyperPlonk instance parameters, consists of the following:
43/// - the number of constraints
44/// - number of public input columns
45/// - the customized gate function
46#[derive(Clone, Debug, Default, PartialEq, Eq)]
47pub struct HyperPlonkParams {
48 /// the number of constraints
49 pub num_constraints: usize,
50 /// number of public input
51 // public input is only 1 column and is implicitly the first witness column.
52 // this size must not exceed number of constraints.
53 pub num_pub_input: usize,
54 /// customized gate function
55 pub gate_func: CustomizedGates,
56}
57
58impl HyperPlonkParams {
59 /// Number of variables in a multilinear system
60 pub fn num_variables(&self) -> usize {
61 log2(self.num_constraints) as usize
62 }
63
64 /// number of selector columns
65 pub fn num_selector_columns(&self) -> usize {
66 self.gate_func.num_selector_columns()
67 }
68
69 /// number of witness columns
70 pub fn num_witness_columns(&self) -> usize {
71 self.gate_func.num_witness_columns()
72 }
73}
74
75/// The HyperPlonk index, consists of the following:
76/// - HyperPlonk parameters
77/// - the wire permutation
78/// - the selector vectors
79#[derive(Clone, Debug, Default, PartialEq, Eq)]
80pub struct HyperPlonkIndex<F: PrimeField> {
81 pub params: HyperPlonkParams,
82 pub permutation: Vec<F>,
83 pub selectors: Vec<SelectorColumn<F>>,
84}
85
86impl<F: PrimeField> HyperPlonkIndex<F> {
87 /// Number of variables in a multilinear system
88 pub fn num_variables(&self) -> usize {
89 self.params.num_variables()
90 }
91
92 /// number of selector columns
93 pub fn num_selector_columns(&self) -> usize {
94 self.params.num_selector_columns()
95 }
96
97 /// number of witness columns
98 pub fn num_witness_columns(&self) -> usize {
99 self.params.num_witness_columns()
100 }
101}
102
103/// The HyperPlonk proving key, consists of the following:
104/// - the hyperplonk instance parameters
105/// - the preprocessed polynomials output by the indexer
106/// - the commitment to the selectors
107/// - the parameters for polynomial commitment
108#[derive(Clone, Debug, Default, PartialEq)]
109pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
110 /// Hyperplonk instance parameters
111 pub params: HyperPlonkParams,
112 /// The preprocessed permutation polynomials
113 pub permutation_oracle: Rc<DenseMultilinearExtension<E::Fr>>,
114 /// The preprocessed selector polynomials
115 pub selector_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
116 /// A commitment to the preprocessed selector polynomials
117 pub selector_commitments: Vec<PCS::Commitment>,
118 /// The parameters for PCS commitment
119 pub pcs_param: PCS::ProverParam,
120}
121
122/// The HyperPlonk verifying key, consists of the following:
123/// - the hyperplonk instance parameters
124/// - the commitments to the preprocessed polynomials output by the indexer
125/// - the parameters for polynomial commitment
126#[derive(Clone, Debug, Default, PartialEq)]
127pub struct HyperPlonkVerifyingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
128 /// Hyperplonk instance parameters
129 pub params: HyperPlonkParams,
130 /// The preprocessed permutation polynomials
131 pub permutation_oracle: Rc<DenseMultilinearExtension<E::Fr>>,
132 /// The parameters for PCS commitment
133 pub pcs_param: PCS::VerifierParam,
134 /// A commitment to the preprocessed selector polynomials
135 pub selector_commitments: Vec<PCS::Commitment>,
136 /// Permutation oracle's commitment
137 pub perm_com: PCS::Commitment,
138}