Skip to content

Commit

Permalink
feat: expose necessary structure of ConstraintSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 committed Jul 18, 2022
1 parent 653325e commit d88de9a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 11 deletions.
15 changes: 15 additions & 0 deletions halo2_proofs/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ impl<C: CurveAffine> VerifyingKey<C> {
cs: self.cs.pinned(),
}
}

/// Doc
pub fn fixed_commitments(&self) -> &Vec<C> {
&self.fixed_commitments
}

/// Doc
pub fn permutation(&self) -> &permutation::VerifyingKey<C> {
&self.permutation
}

/// Doc
pub fn cs(&self) -> &ConstraintSystem<C::Scalar> {
&self.cs
}
}

/// Minimal representation of a verification key that can be used to identify
Expand Down
56 changes: 52 additions & 4 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ impl<C: ColumnType> Column<C> {
Column { index, column_type }
}

pub(crate) fn index(&self) -> usize {
/// Doc
pub fn index(&self) -> usize {
self.index
}

Expand Down Expand Up @@ -930,7 +931,7 @@ pub(crate) struct PointIndex(pub usize);
/// A "virtual cell" is a PLONK cell that has been queried at a particular relative offset
/// within a custom gate.
#[derive(Clone, Debug)]
pub(crate) struct VirtualCell {
pub struct VirtualCell {
pub(crate) column: Column<Any>,
pub(crate) rotation: Rotation,
}
Expand Down Expand Up @@ -1054,8 +1055,9 @@ impl<F: Field, C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>> IntoIterato
}
}

/// Doc
#[derive(Clone, Debug)]
pub(crate) struct Gate<F: Field> {
pub struct Gate<F: Field> {
name: &'static str,
constraint_names: Vec<&'static str>,
polys: Vec<Expression<F>>,
Expand All @@ -1074,7 +1076,8 @@ impl<F: Field> Gate<F> {
self.constraint_names[constraint_index]
}

pub(crate) fn polynomials(&self) -> &[Expression<F>] {
/// Doc
pub fn polynomials(&self) -> &[Expression<F>] {
&self.polys
}

Expand Down Expand Up @@ -1648,6 +1651,51 @@ impl<F: Field> ConstraintSystem<F> {
// and the interstitial values.)
+ 1 // for at least one row
}

/// Doc
pub fn num_fixed_columns(&self) -> usize {
self.num_fixed_columns
}

/// Doc
pub fn num_advice_columns(&self) -> usize {
self.num_advice_columns
}

/// Doc
pub fn num_instance_columns(&self) -> usize {
self.num_instance_columns
}

/// Doc
pub fn gates(&self) -> &Vec<Gate<F>> {
&self.gates
}

/// Doc
pub fn advice_queries(&self) -> &Vec<(Column<Advice>, Rotation)> {
&self.advice_queries
}

/// Doc
pub fn instance_queries(&self) -> &Vec<(Column<Instance>, Rotation)> {
&self.instance_queries
}

/// Doc
pub fn fixed_queries(&self) -> &Vec<(Column<Fixed>, Rotation)> {
&self.fixed_queries
}

/// Doc
pub fn permutation(&self) -> &permutation::Argument {
&self.permutation
}

/// Doc
pub fn lookups(&self) -> &Vec<lookup::Argument<F>> {
&self.lookups
}
}

/// Exposes the "virtual cells" that can be queried while creating a custom gate or lookup
Expand Down
18 changes: 14 additions & 4 deletions halo2_proofs/src/plonk/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub(crate) mod prover;
pub(crate) mod verifier;

#[derive(Clone)]
pub(crate) struct Argument<F: Field> {
pub name: &'static str,
pub input_expressions: Vec<Expression<F>>,
pub table_expressions: Vec<Expression<F>>,
pub struct Argument<F: Field> {
pub(crate) name: &'static str,
pub(crate) input_expressions: Vec<Expression<F>>,
pub(crate) table_expressions: Vec<Expression<F>>,
}

impl<F: Field> Debug for Argument<F> {
Expand Down Expand Up @@ -81,4 +81,14 @@ impl<F: Field> Argument<F> {
2 + input_degree + table_degree,
)
}

/// Doc
pub fn input_expressions(&self) -> &Vec<Expression<F>> {
&self.input_expressions
}

/// Doc
pub fn table_expressions(&self) -> &Vec<Expression<F>> {
&self.table_expressions
}
}
13 changes: 10 additions & 3 deletions halo2_proofs/src/plonk/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::io;

/// A permutation argument.
#[derive(Debug, Clone)]
pub(crate) struct Argument {
pub struct Argument {
/// A sequence of columns involved in the argument.
pub(super) columns: Vec<Column<Any>>,
}
Expand Down Expand Up @@ -67,17 +67,24 @@ impl Argument {
}
}

pub(crate) fn get_columns(&self) -> Vec<Column<Any>> {
pub fn get_columns(&self) -> Vec<Column<Any>> {
self.columns.clone()
}
}

/// The verifying key for a single permutation argument.
#[derive(Clone, Debug)]
pub(crate) struct VerifyingKey<C: CurveAffine> {
pub struct VerifyingKey<C: CurveAffine> {
commitments: Vec<C>,
}

impl<C: CurveAffine> VerifyingKey<C> {
/// Doc
pub fn commitments(&self) -> &Vec<C> {
&self.commitments
}
}

/// The proving key for a single permutation argument.
#[derive(Clone, Debug)]
pub(crate) struct ProvingKey<C: CurveAffine> {
Expand Down

0 comments on commit d88de9a

Please sign in to comment.