hyperplonk/hyperplonk/src/structs.rs
hyperplonk/src/structs.rsRaw
1//! Main module for the HyperPlonk PolyIOP.
2
3use crate::{custom_gate::CustomizedGates, prelude::HyperPlonkErrors, 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 /// evaluate the identical polynomial
71 pub fn eval_id_oracle<F: PrimeField>(&self, point: &[F]) -> Result<F, HyperPlonkErrors> {
72 let len = self.num_variables() + (log2(self.num_witness_columns()) as usize);
73 if point.len() != len {
74 return Err(HyperPlonkErrors::InvalidParameters(format!(
75 "ID oracle point length = {}, expected {}",
76 point.len(),
77 len,
78 )));
79 }
80
81 let mut res = F::zero();
82 let mut base = F::one();
83 for &v in point.iter() {
84 res += base * v;
85 base += base;
86 }
87 Ok(res)
88 }
89}
90
91/// The HyperPlonk index, consists of the following:
92/// - HyperPlonk parameters
93/// - the wire permutation
94/// - the selector vectors
95#[derive(Clone, Debug, Default, PartialEq, Eq)]
96pub struct HyperPlonkIndex<F: PrimeField> {
97 pub params: HyperPlonkParams,
98 pub permutation: Vec<F>,
99 pub selectors: Vec<SelectorColumn<F>>,
100}
101
102impl<F: PrimeField> HyperPlonkIndex<F> {
103 /// Number of variables in a multilinear system
104 pub fn num_variables(&self) -> usize {
105 self.params.num_variables()
106 }
107
108 /// number of selector columns
109 pub fn num_selector_columns(&self) -> usize {
110 self.params.num_selector_columns()
111 }
112
113 /// number of witness columns
114 pub fn num_witness_columns(&self) -> usize {
115 self.params.num_witness_columns()
116 }
117}
118
119/// The HyperPlonk proving key, consists of the following:
120/// - the hyperplonk instance parameters
121/// - the preprocessed polynomials output by the indexer
122/// - the commitment to the selectors and permutations
123/// - the parameters for polynomial commitment
124#[derive(Clone, Debug, Default, PartialEq)]
125pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
126 /// Hyperplonk instance parameters
127 pub params: HyperPlonkParams,
128 /// The preprocessed permutation polynomials
129 pub permutation_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
130 /// The preprocessed selector polynomials
131 pub selector_oracles: Vec<Rc<DenseMultilinearExtension<E::Fr>>>,
132 /// Commitments to the preprocessed selector polynomials
133 pub selector_commitments: Vec<PCS::Commitment>,
134 /// Commitments to the preprocessed permutation polynomials
135 pub permutation_commitments: Vec<PCS::Commitment>,
136 /// The parameters for PCS commitment
137 pub pcs_param: PCS::ProverParam,
138}
139
140/// The HyperPlonk verifying key, consists of the following:
141/// - the hyperplonk instance parameters
142/// - the commitments to the preprocessed polynomials output by the indexer
143/// - the parameters for polynomial commitment
144#[derive(Clone, Debug, Default, PartialEq)]
145pub struct HyperPlonkVerifyingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
146 /// Hyperplonk instance parameters
147 pub params: HyperPlonkParams,
148 /// The parameters for PCS commitment
149 pub pcs_param: PCS::VerifierParam,
150 /// A commitment to the preprocessed selector polynomials
151 pub selector_commitments: Vec<PCS::Commitment>,
152 /// Permutation oracles' commitments
153 pub perm_commitments: Vec<PCS::Commitment>,
154}