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/// - the commitments to all 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_commits: Vec<PCS::Commitment>,
28 pub batch_openings: PCS::BatchProof,
29 // =======================================================================
30 // IOP proofs
31 // =======================================================================
32 // the custom gate zerocheck proof
33 pub zero_check_proof: <PC as ZeroCheck<E::Fr>>::ZeroCheckProof,
34 // the permutation check proof for copy constraints
35 pub perm_check_proof: PC::PermutationProof,
36}
37
38/// The HyperPlonk instance parameters, consists of the following:
39/// - the number of constraints
40/// - number of public input columns
41/// - the customized gate function
42#[derive(Clone, Debug, Default, PartialEq, Eq)]
43pub struct HyperPlonkParams {
44 /// the number of constraints
45 pub num_constraints: usize,
46 /// number of public input
47 // public input is only 1 column and is implicitly the first witness column.
48 // this size must not exceed number of constraints.
49 pub num_pub_input: usize,
50 /// customized gate function
51 pub gate_func: CustomizedGates,
52}
53
54impl HyperPlonkParams {
55 /// Number of variables in a multilinear system
56 pub fn num_variables(&self) -> usize {
57 log2(self.num_constraints) as usize
58 }
59
60 /// number of selector columns
61 pub fn num_selector_columns(&self) -> usize {
62 self.gate_func.num_selector_columns()
63 }
64
65 /// number of witness columns
66 pub fn num_witness_columns(&self) -> usize {
67 self.gate_func.num_witness_columns()
68 }
69}
70
71/// The HyperPlonk index, consists of the following:
72/// - HyperPlonk parameters
73/// - the wire permutation
74/// - the selector vectors
75#[derive(Clone, Debug, Default, PartialEq, Eq)]
76pub struct HyperPlonkIndex<F: PrimeField> {
77 pub params: HyperPlonkParams,
78 pub permutation: Vec<F>,
79 pub selectors: Vec<SelectorColumn<F>>,
80}
81
82impl<F: PrimeField> HyperPlonkIndex<F> {
83 /// Number of variables in a multilinear system
84 pub fn num_variables(&self) -> usize {
85 self.params.num_variables()
86 }
87
88 /// number of selector columns
89 pub fn num_selector_columns(&self) -> usize {
90 self.params.num_selector_columns()
91 }
92
93 /// number of witness columns
94 pub fn num_witness_columns(&self) -> usize {
95 self.params.num_witness_columns()
96 }
97}
98
99/// The HyperPlonk proving key, consists of the following:
100/// - the hyperplonk instance parameters
101/// - the preprocessed polynomials output by the indexer
102/// - the commitment to the selectors and permutations
103/// - the parameters for polynomial commitment
104#[derive(Clone, Debug, Default, PartialEq)]
105pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
106 /// Hyperplonk instance parameters
107 pub params: HyperPlonkParams,
108 /// The preprocessed permutation polynomials
109 pub permutation_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
110 /// The preprocessed identity polynomials
111 pub id_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
112 /// The preprocessed selector polynomials
113 pub selector_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
114 /// Commitments to the preprocessed selector polynomials
115 pub selector_commitments: Vec<PCS::Commitment>,
116 /// Commitments to the preprocessed permutation polynomials
117 pub permutation_commitments: Vec<PCS::Commitment>,
118 /// Commitments to the preprocessed identity polynomials
119 pub id_commitments: Vec<PCS::Commitment>,
120 /// The parameters for PCS commitment
121 pub pcs_param: PCS::ProverParam,
122}
123
124/// The HyperPlonk verifying key, consists of the following:
125/// - the hyperplonk instance parameters
126/// - the commitments to the preprocessed polynomials output by the indexer
127/// - the parameters for polynomial commitment
128#[derive(Clone, Debug, Default, PartialEq)]
129pub struct HyperPlonkVerifyingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
130 /// Hyperplonk instance parameters
131 pub params: HyperPlonkParams,
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 oracles' commitments
137 pub perm_commitments: Vec<PCS::Commitment>,
138 /// Commitments to the preprocessed identity polynomials
139 pub id_commitments: Vec<PCS::Commitment>,
140}