mirror of https://github.com/zcash/halo2.git
Add ChallengeMid in middleware
This commit is contained in:
parent
3291b3c429
commit
34d35a84f9
|
@ -18,7 +18,7 @@ use crate::{
|
|||
EvaluationDomain,
|
||||
},
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, CompiledCircuitV2, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, CompiledCircuitV2, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
pub(crate) fn create_domain<C, ConcreteCircuit>(
|
||||
|
|
|
@ -4,8 +4,11 @@ use std::{fmt, marker::PhantomData};
|
|||
|
||||
use halo2_middleware::ff::Field;
|
||||
|
||||
use crate::plonk::{circuit::Column, Error, Selector, TableColumn};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, Fixed, Instance};
|
||||
use crate::plonk::{
|
||||
circuit::{Challenge, Column},
|
||||
Error, Selector, TableColumn,
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
mod value;
|
||||
|
|
|
@ -11,9 +11,9 @@ use crate::{
|
|||
table_layouter::{compute_table_lengths, SimpleTableLayouter},
|
||||
Cell, Column, Layouter, Region, RegionIndex, RegionStart, Table, Value,
|
||||
},
|
||||
plonk::{Assignment, Circuit, Error, FloorPlanner, Selector, TableColumn},
|
||||
plonk::{circuit::Challenge, Assignment, Circuit, Error, FloorPlanner, Selector, TableColumn},
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
/// A simple [`FloorPlanner`] that performs minimal optimizations.
|
||||
|
|
|
@ -8,9 +8,9 @@ use crate::{
|
|||
table_layouter::{compute_table_lengths, SimpleTableLayouter},
|
||||
Cell, Column, Layouter, Region, RegionIndex, RegionStart, Table, Value,
|
||||
},
|
||||
plonk::{Assignment, Circuit, Error, FloorPlanner, Selector, TableColumn},
|
||||
plonk::{circuit::Challenge, Assignment, Circuit, Error, FloorPlanner, Selector, TableColumn},
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
pub mod strategy;
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::circuit::{Layouter, Region, Value};
|
|||
use core::cmp::max;
|
||||
use core::ops::{Add, Mul};
|
||||
use halo2_middleware::circuit::{
|
||||
Advice, AdviceQueryMid, Any, Challenge, ColumnMid, ColumnType, ConstraintSystemV2Backend,
|
||||
Advice, AdviceQueryMid, Any, ChallengeMid, ColumnMid, ColumnType, ConstraintSystemV2Backend,
|
||||
ExpressionMid, Fixed, FixedQueryMid, GateV2Backend, Instance, InstanceQueryMid,
|
||||
};
|
||||
use halo2_middleware::ff::Field;
|
||||
|
@ -56,7 +56,26 @@ impl<C: ColumnType> Column<C> {
|
|||
|
||||
/// Return expression from column at a relative position
|
||||
pub fn query_cell<F: Field>(&self, at: Rotation) -> Expression<F> {
|
||||
self.column_type.query_cell(self.index, at)
|
||||
let expr_mid = self.column_type.query_cell::<F>(self.index, at);
|
||||
match expr_mid {
|
||||
ExpressionMid::Advice(q) => Expression::Advice(AdviceQuery {
|
||||
index: None,
|
||||
column_index: q.column_index,
|
||||
rotation: q.rotation,
|
||||
phase: sealed::Phase(q.phase),
|
||||
}),
|
||||
ExpressionMid::Fixed(q) => Expression::Fixed(FixedQuery {
|
||||
index: None,
|
||||
column_index: q.column_index,
|
||||
rotation: q.rotation,
|
||||
}),
|
||||
ExpressionMid::Instance(q) => Expression::Instance(InstanceQuery {
|
||||
index: None,
|
||||
column_index: q.column_index,
|
||||
rotation: q.rotation,
|
||||
}),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return expression from column at the current row
|
||||
|
@ -426,6 +445,48 @@ impl TableColumn {
|
|||
}
|
||||
}
|
||||
|
||||
/// A challenge squeezed from transcript after advice columns at the phase have been committed.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct Challenge {
|
||||
pub index: usize,
|
||||
pub phase: u8,
|
||||
}
|
||||
|
||||
impl Challenge {
|
||||
/// Index of this challenge.
|
||||
pub fn index(&self) -> usize {
|
||||
self.index
|
||||
}
|
||||
|
||||
/// Phase of this challenge.
|
||||
pub fn phase(&self) -> u8 {
|
||||
self.phase
|
||||
}
|
||||
|
||||
/// Return Expression
|
||||
pub fn expr<F: Field>(&self) -> Expression<F> {
|
||||
Expression::Challenge(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<ChallengeMid> for Challenge {
|
||||
fn into(self) -> ChallengeMid {
|
||||
ChallengeMid {
|
||||
index: self.index,
|
||||
phase: self.phase,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ChallengeMid> for Challenge {
|
||||
fn from(c: ChallengeMid) -> Self {
|
||||
Self {
|
||||
index: c.index,
|
||||
phase: c.phase,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This trait allows a [`Circuit`] to direct some backend to assign a witness
|
||||
/// for a constraint system.
|
||||
pub trait Assignment<F: Field> {
|
||||
|
@ -669,7 +730,7 @@ impl<F> Into<ExpressionMid<F>> for Expression<F> {
|
|||
column_index,
|
||||
rotation,
|
||||
}),
|
||||
Expression::Challenge(c) => ExpressionMid::Challenge(c),
|
||||
Expression::Challenge(c) => ExpressionMid::Challenge(c.into()),
|
||||
Expression::Negated(e) => ExpressionMid::Negated(Box::new((*e).into())),
|
||||
Expression::Sum(lhs, rhs) => {
|
||||
ExpressionMid::Sum(Box::new((*lhs).into()), Box::new((*rhs).into()))
|
||||
|
@ -1477,7 +1538,7 @@ impl QueriesMap {
|
|||
rotation: query.rotation,
|
||||
})
|
||||
}
|
||||
ExpressionMid::Challenge(c) => Expression::Challenge(*c),
|
||||
ExpressionMid::Challenge(c) => Expression::Challenge(c.clone().into()),
|
||||
ExpressionMid::Negated(e) => Expression::Negated(Box::new(self.as_expression(e))),
|
||||
ExpressionMid::Sum(lhs, rhs) => Expression::Sum(
|
||||
Box::new(self.as_expression(lhs)),
|
||||
|
|
|
@ -3,11 +3,11 @@ use std::ops::Range;
|
|||
use halo2_middleware::ff::Field;
|
||||
|
||||
use super::{
|
||||
circuit::{Assignment, Column, Selector},
|
||||
circuit::{Assignment, Challenge, Column, Selector},
|
||||
permutation, Error, LagrangeCoeff, Polynomial,
|
||||
};
|
||||
use crate::circuit::Value;
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
/// Assembly to be used in circuit synthesis.
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
//! Traits and structs for implementing circuit components.
|
||||
|
||||
use halo2_common::plonk::{
|
||||
circuit::Column,
|
||||
circuit::{Challenge, Column},
|
||||
permutation,
|
||||
sealed::{self, SealedPhase},
|
||||
Assignment, Circuit, ConstraintSystem, Error, FirstPhase, FloorPlanner, SecondPhase, Selector,
|
||||
ThirdPhase,
|
||||
};
|
||||
use halo2_common::poly::{batch_invert_assigned, Polynomial};
|
||||
use halo2_middleware::circuit::{
|
||||
Advice, Any, Challenge, CompiledCircuitV2, Fixed, Instance, PreprocessingV2,
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, CompiledCircuitV2, Fixed, Instance, PreprocessingV2};
|
||||
use halo2_middleware::ff::Field;
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
use std::collections::BTreeSet;
|
||||
|
|
|
@ -5,8 +5,8 @@ mod tests {
|
|||
|
||||
use super::SimpleFloorPlanner;
|
||||
use crate::dev::MockProver;
|
||||
use halo2_common::plonk::{Circuit, ConstraintSystem, Error};
|
||||
use halo2_middleware::circuit::{Advice, Column};
|
||||
use halo2_common::plonk::{circuit::Column, Circuit, ConstraintSystem, Error};
|
||||
use halo2_middleware::circuit::Advice;
|
||||
|
||||
#[test]
|
||||
fn not_enough_columns_for_constants() {
|
||||
|
|
|
@ -7,8 +7,8 @@ mod tests {
|
|||
use halo2curves::pasta::vesta;
|
||||
|
||||
use crate::dev::MockProver;
|
||||
use halo2_common::plonk::{Circuit, ConstraintSystem, Error};
|
||||
use halo2_middleware::circuit::{Advice, Column};
|
||||
use halo2_common::plonk::{circuit::Column, Circuit, ConstraintSystem, Error};
|
||||
use halo2_middleware::circuit::Advice;
|
||||
|
||||
#[test]
|
||||
fn not_enough_columns_for_constants() {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
fn test_slot_in() {
|
||||
use crate::circuit::layouter::RegionShape;
|
||||
use halo2_common::circuit::floor_planner::v1::strategy::slot_in;
|
||||
use halo2_middleware::circuit::{Any, Column};
|
||||
use halo2_common::plonk::circuit::Column;
|
||||
use halo2_middleware::circuit::Any;
|
||||
|
||||
let regions = vec![
|
||||
RegionShape {
|
||||
|
|
|
@ -12,14 +12,14 @@ use halo2_middleware::ff::FromUniformBytes;
|
|||
use halo2_common::{
|
||||
circuit,
|
||||
plonk::{
|
||||
circuit::Column,
|
||||
circuit::{Challenge, Column},
|
||||
permutation,
|
||||
sealed::{self, SealedPhase},
|
||||
Assignment, Circuit, ConstraintSystem, Error, Expression, FirstPhase, FloorPlanner, Phase,
|
||||
Selector,
|
||||
},
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, ColumnMid, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, ColumnMid, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
use halo2_common::multicore::{
|
||||
|
@ -1252,9 +1252,9 @@ mod tests {
|
|||
use super::{FailureLocation, MockProver, VerifyFailure};
|
||||
use crate::circuit::{Layouter, SimpleFloorPlanner, Value};
|
||||
use halo2_common::plonk::{
|
||||
Circuit, ConstraintSystem, Error, Expression, Selector, TableColumn,
|
||||
circuit::Column, Circuit, ConstraintSystem, Error, Expression, Selector, TableColumn,
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Column, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::poly::Rotation;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -15,10 +15,11 @@ use halo2_middleware::poly::Rotation;
|
|||
use halo2_common::{
|
||||
circuit::{layouter::RegionColumn, Value},
|
||||
plonk::{
|
||||
circuit::Column, Assignment, Circuit, ConstraintSystem, Error, FloorPlanner, Selector,
|
||||
circuit::{Challenge, Column},
|
||||
Assignment, Circuit, ConstraintSystem, Error, FloorPlanner, Selector,
|
||||
},
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
/// Measures a circuit to determine its costs, and explain what contributes to them.
|
||||
|
|
|
@ -8,9 +8,10 @@ use halo2_common::circuit::{
|
|||
AssignedCell, Cell, Layouter, Region, Table, Value,
|
||||
};
|
||||
use halo2_common::plonk::{
|
||||
circuit::Column, Assignment, Circuit, ConstraintSystem, Error, FloorPlanner, Selector,
|
||||
circuit::{Challenge, Column},
|
||||
Assignment, Circuit, ConstraintSystem, Error, FloorPlanner, Selector,
|
||||
};
|
||||
use halo2_middleware::circuit::{Advice, Any, Challenge, Fixed, Instance};
|
||||
use halo2_middleware::circuit::{Advice, Any, Fixed, Instance};
|
||||
use halo2_middleware::plonk::Assigned;
|
||||
|
||||
/// A helper type that augments a [`FloorPlanner`] with [`tracing`] spans and events.
|
||||
|
|
|
@ -11,8 +11,9 @@ pub use verifier::verify_proof;
|
|||
|
||||
pub use halo2_backend::plonk::{ProvingKey, VerifyingKey};
|
||||
pub use halo2_common::plonk::{
|
||||
circuit::Column, Circuit, ConstraintSystem, Error, Expression, FirstPhase, SecondPhase,
|
||||
Selector, TableColumn, ThirdPhase,
|
||||
circuit::{Challenge, Column},
|
||||
Circuit, ConstraintSystem, Error, Expression, FirstPhase, SecondPhase, Selector, TableColumn,
|
||||
ThirdPhase,
|
||||
};
|
||||
pub use halo2_middleware::circuit::{Advice, Challenge, Fixed, Instance};
|
||||
pub use halo2_middleware::circuit::{Advice, Fixed, Instance};
|
||||
pub use halo2_middleware::plonk::Assigned;
|
||||
|
|
|
@ -13,8 +13,8 @@ use halo2_backend::plonk::{
|
|||
use halo2_common::{
|
||||
circuit::{AssignedCell, Layouter, Region, SimpleFloorPlanner, Value},
|
||||
plonk::{
|
||||
circuit::Column, Circuit, ConstraintSystem, Error, Expression, FirstPhase, SecondPhase,
|
||||
Selector,
|
||||
circuit::{Challenge, Column},
|
||||
Circuit, ConstraintSystem, Error, Expression, FirstPhase, SecondPhase, Selector,
|
||||
},
|
||||
transcript::{
|
||||
Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer,
|
||||
|
@ -25,7 +25,7 @@ use halo2_frontend::{
|
|||
dev::MockProver,
|
||||
};
|
||||
use halo2_middleware::{
|
||||
circuit::{Advice, Challenge, Fixed, Instance},
|
||||
circuit::{Advice, Fixed, Instance},
|
||||
ff::Field,
|
||||
poly::Rotation,
|
||||
};
|
||||
|
|
|
@ -35,12 +35,12 @@ pub struct InstanceQueryMid {
|
|||
|
||||
/// A challenge squeezed from transcript after advice columns at the phase have been committed.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct Challenge {
|
||||
pub struct ChallengeMid {
|
||||
pub index: usize,
|
||||
pub phase: u8,
|
||||
}
|
||||
|
||||
impl Challenge {
|
||||
impl ChallengeMid {
|
||||
/// Index of this challenge.
|
||||
pub fn index(&self) -> usize {
|
||||
self.index
|
||||
|
@ -51,10 +51,10 @@ impl Challenge {
|
|||
self.phase
|
||||
}
|
||||
|
||||
/// Return Expression
|
||||
pub fn expr<F: Field>(&self) -> ExpressionMid<F> {
|
||||
ExpressionMid::Challenge(*self)
|
||||
}
|
||||
// /// Return Expression
|
||||
// pub fn expr<F: Field>(&self) -> ExpressionMid<F> {
|
||||
// ExpressionMid::Challenge(*self)
|
||||
// }
|
||||
}
|
||||
|
||||
/// Low-degree expression representing an identity that must hold over the committed columns.
|
||||
|
@ -69,7 +69,7 @@ pub enum ExpressionMid<F> {
|
|||
/// This is an instance (external) column queried at a certain relative location
|
||||
Instance(InstanceQueryMid),
|
||||
/// This is a challenge
|
||||
Challenge(Challenge),
|
||||
Challenge(ChallengeMid),
|
||||
/// This is a negated polynomial
|
||||
Negated(Box<ExpressionMid<F>>),
|
||||
/// This is the sum of two polynomials
|
||||
|
@ -166,6 +166,12 @@ pub struct CompiledCircuitV2<F: Field> {
|
|||
pub cs: ConstraintSystemV2Backend<F>,
|
||||
}
|
||||
|
||||
// TODO: The query_cell method is only used in the frontend, which uses Expression. By having this
|
||||
// trait implemented here we can only return ExpressionMid, which requires conversion to Expression
|
||||
// when used. On the other hand, it's difficult to move ColumnType to the frontend because this
|
||||
// trait is implemented for Any which is used in the backend. It would be great to find a way to
|
||||
// move all the `query_cell` implementations to the frontend and have them return `Expression`,
|
||||
// while keeping `Any` in the middleware.
|
||||
/// A column type
|
||||
pub trait ColumnType:
|
||||
'static + Sized + Copy + std::fmt::Debug + PartialEq + Eq + Into<Any>
|
||||
|
|
Loading…
Reference in New Issue