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 Aug 19, 2022
1 parent 6e564cf commit 3e4b27f
Show file tree
Hide file tree
Showing 4 changed files with 132 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(),
}
}

/// Returns commitments of fixed polynomials
pub fn fixed_commitments(&self) -> &Vec<C> {
&self.fixed_commitments
}

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

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

/// Minimal representation of a verification key that can be used to identify
Expand Down
97 changes: 93 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 {
/// Index of this column.
pub fn index(&self) -> usize {
self.index
}

Expand Down Expand Up @@ -280,6 +281,18 @@ pub struct FixedQuery {
pub(crate) rotation: Rotation,
}

impl FixedQuery {
/// Column index
pub fn column_index(&self) -> usize {
self.column_index
}

/// Rotation of this query
pub fn rotation(&self) -> Rotation {
self.rotation
}
}

/// Query of advice column at a certain relative location
#[derive(Copy, Clone, Debug)]
pub struct AdviceQuery {
Expand All @@ -291,6 +304,18 @@ pub struct AdviceQuery {
pub(crate) rotation: Rotation,
}

impl AdviceQuery {
/// Column index
pub fn column_index(&self) -> usize {
self.column_index
}

/// Rotation of this query
pub fn rotation(&self) -> Rotation {
self.rotation
}
}

/// Query of instance column at a certain relative location
#[derive(Copy, Clone, Debug)]
pub struct InstanceQuery {
Expand All @@ -302,6 +327,18 @@ pub struct InstanceQuery {
pub(crate) rotation: Rotation,
}

impl InstanceQuery {
/// Column index
pub fn column_index(&self) -> usize {
self.column_index
}

/// Rotation of this query
pub fn rotation(&self) -> Rotation {
self.rotation
}
}

/// A fixed column of a lookup table.
///
/// A lookup table can be loaded into this column via [`Layouter::assign_table`]. Columns
Expand Down Expand Up @@ -930,7 +967,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 +1091,9 @@ impl<F: Field, C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>> IntoIterato
}
}

/// Gate
#[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 +1112,8 @@ impl<F: Field> Gate<F> {
self.constraint_names[constraint_index]
}

pub(crate) fn polynomials(&self) -> &[Expression<F>] {
/// Returns constraints of this gate
pub fn polynomials(&self) -> &[Expression<F>] {
&self.polys
}

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

/// Returns number of fixed columns
pub fn num_fixed_columns(&self) -> usize {
self.num_fixed_columns
}

/// Returns number of advice columns
pub fn num_advice_columns(&self) -> usize {
self.num_advice_columns
}

/// Returns number of instance columns
pub fn num_instance_columns(&self) -> usize {
self.num_instance_columns
}

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

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

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

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

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

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

/// Returns constants
pub fn constants(&self) -> &Vec<Column<Fixed>> {
&self.constants
}
}

/// 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,
)
}

/// Returns input of this argument
pub fn input_expressions(&self) -> &Vec<Expression<F>> {
&self.input_expressions
}

/// Returns table of this argument
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> {
/// Returns commitments of sigma polynomials
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 3e4b27f

Please sign in to comment.