Skip to content

Commit

Permalink
Merge with latest develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
spherel committed Aug 11, 2023
2 parents 992325b + 01f0b52 commit 82f4d6d
Show file tree
Hide file tree
Showing 11 changed files with 1,018 additions and 876 deletions.
965 changes: 535 additions & 430 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,21 @@ impl<'a, F: Field + Group> Assignment<F> for MockProver<'a, F> {
for (i, sub_range) in ranges.iter().enumerate() {
if sub_range.start < range_start {
// TODO: use more precise error type
log::error!(
"subCS_{} sub_range.start ({}) < range_start ({})",
i,
sub_range.start,
range_start
);
return Err(Error::Synthesis);
}
if i == ranges.len() - 1 && sub_range.end >= self.rw_rows.end {
if i == ranges.len() - 1 && sub_range.end > self.rw_rows.end {
log::error!(
"subCS_{} sub_range.end ({}) > self.rw_rows.end ({})",
i,
sub_range.end,
self.rw_rows.end
);
return Err(Error::Synthesis);
}
range_start = sub_range.end;
Expand Down Expand Up @@ -692,10 +704,11 @@ impl<'a, F: Field + Group> Assignment<F> for MockProver<'a, F> {
}

fn get_challenge(&self, challenge: Challenge) -> circuit::Value<F> {
match self.challenges.get(challenge.index()) {
None => circuit::Value::unknown(),
Some(v) => circuit::Value::known(*v),
if self.current_phase <= challenge.phase {
return circuit::Value::unknown();
}

circuit::Value::known(self.challenges[challenge.index()])
}

fn push_namespace<NR, N>(&mut self, _: N)
Expand Down Expand Up @@ -889,11 +902,11 @@ impl<'a, F: FieldExt> MockProver<'a, F> {
}

pub fn advice_values(&self, column: Column<Advice>) -> &[CellValue<F>] {
&self.advice[column.index()]
self.advice[column.index()]
}

pub fn fixed_values(&self, column: Column<Fixed>) -> &[CellValue<F>] {
&self.fixed[column.index()]
self.fixed[column.index()]
}

/// Returns `Ok(())` if this `MockProver` is satisfied, or a list of errors indicating
Expand Down
2 changes: 2 additions & 0 deletions halo2_proofs/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl<F: PrimeField + SerdeObject> SerdePrimeField for F {}
/// Convert a slice of `bool` into a `u8`.
///
/// Panics if the slice has length greater than 8.
#[allow(unused)]
pub fn pack(bits: &[bool]) -> u8 {
let mut value = 0u8;
assert!(bits.len() <= 8);
Expand All @@ -177,6 +178,7 @@ pub fn pack(bits: &[bool]) -> u8 {
}

/// Writes the first `bits.len()` bits of a `u8` into `bits`.
#[allow(unused)]
pub fn unpack(byte: u8, bits: &mut [bool]) {
for (bit_index, bit) in bits.iter_mut().enumerate() {
*bit = (byte >> bit_index) & 1 == 1;
Expand Down
22 changes: 7 additions & 15 deletions halo2_proofs/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ where
/// WITHOUT performing the expensive Montgomery reduction.
pub fn write<W: io::Write>(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> {
writer.write_all(&self.domain.k().to_be_bytes())?;
// the `fixed_commitments` here includes selectors
writer.write_all(&(self.fixed_commitments.len() as u32).to_be_bytes())?;
for commitment in &self.fixed_commitments {
commitment.write(writer, format)?;
Expand Down Expand Up @@ -121,21 +122,12 @@ where

let permutation = permutation::VerifyingKey::read(reader, &cs.permutation, format)?;

/*
// read selectors
let selectors: Vec<Vec<bool>> = vec![vec![false; 1 << k]; cs.num_selectors]
.into_iter()
.map(|mut selector| {
let mut selector_bytes = vec![0u8; (selector.len() + 7) / 8];
reader.read_exact(&mut selector_bytes)?;
for (bits, byte) in selector.chunks_mut(8).into_iter().zip(selector_bytes) {
crate::helpers::unpack(byte, bits);
}
Ok(selector)
})
.collect::<io::Result<_>>()?;
let (cs, _) = cs.compress_selectors(selectors.clone());
*/
// We already disable compressing selectors inside `compress_selectors::process`.
// So `selectors` values is not relevant here actually.
// The selector commitments are already in fixed_commitments.
let selectors: Vec<Vec<bool>> = vec![vec![false; 1 << k]; cs.num_selectors];
let (cs, _) = cs.compress_selectors(selectors);

Ok(Self::from_parts(
domain,
fixed_commitments,
Expand Down
16 changes: 8 additions & 8 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl TableColumn {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct Challenge {
index: usize,
phase: sealed::Phase,
pub(crate) phase: sealed::Phase,
}

impl Challenge {
Expand Down Expand Up @@ -571,12 +571,12 @@ pub trait Assignment<F: Field>: Sized + Send {
AR: Into<String>;

/// Fork
fn fork(&mut self, ranges: &[Range<usize>]) -> Result<Vec<Self>, Error> {
fn fork(&mut self, _ranges: &[Range<usize>]) -> Result<Vec<Self>, Error> {
unimplemented!("fork is not implemented by default")
}

/// Merge
fn merge(&mut self, sub_cs: Vec<Self>) -> Result<(), Error> {
fn merge(&mut self, _sub_cs: Vec<Self>) -> Result<(), Error> {
unimplemented!("merge is not implemented by default")
}

Expand Down Expand Up @@ -701,7 +701,7 @@ pub trait Circuit<F: Field> {
}

/// Low-degree expression representing an identity that must hold over the committed columns.
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
pub enum Expression<F> {
/// This is a constant polynomial
Constant(F),
Expand Down Expand Up @@ -1213,7 +1213,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)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VirtualCell {
pub(crate) column: Column<Any>,
pub(crate) rotation: Rotation,
Expand Down Expand Up @@ -1339,7 +1339,7 @@ impl<F: Field, C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>> IntoIterato
}

/// Gate
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Gate<F: Field> {
name: &'static str,
constraint_names: Vec<&'static str>,
Expand Down Expand Up @@ -1420,7 +1420,7 @@ pub struct ConstraintSystem<F: Field> {
pub(crate) lookups: Vec<mv_lookup::Argument<F>>,

// List of indexes of Fixed columns which are associated to a circuit-general Column tied to their annotation.
pub(crate) general_column_annotations: HashMap<metadata::Column, String>,
pub(crate) general_column_annotations: BTreeMap<metadata::Column, String>,

// Vector of fixed columns, which can be used to store constant values
// that are copied into advice columns.
Expand Down Expand Up @@ -1507,7 +1507,7 @@ impl<F: Field> Default for ConstraintSystem<F> {
permutation: permutation::Argument::new(),
lookups_map: BTreeMap::default(),
lookups: Vec::new(),
general_column_annotations: HashMap::new(),
general_column_annotations: BTreeMap::new(),
constants: vec![],
minimum_degree: None,
}
Expand Down
4 changes: 3 additions & 1 deletion halo2_proofs/src/plonk/circuit/compress_selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ where
// All provided selectors of degree 0 are assumed to be either concrete
// selectors or do not appear in a gate. Let's address these first.
selectors.retain(|selector| {
if selector.max_degree == 0 {
// here we disable any compression. Each selector will become a fixed column.
// if true || selector.max_degree == 0 {
if true {
// This is a complex selector, or a selector that does not appear in any
// gate constraint.
let expression = allocate_fixed_column();
Expand Down
16 changes: 15 additions & 1 deletion halo2_proofs/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl<'a, F: Field> Assignment<F> for Assembly<'a, F> {
}

if !self.rw_rows.contains(&row) {
log::error!("enable_selector: {:?}, row: {}", selector, row);
return Err(Error::Synthesis);
}

Expand All @@ -102,9 +103,21 @@ impl<'a, F: Field> Assignment<F> for Assembly<'a, F> {
for (i, sub_range) in ranges.iter().enumerate() {
if sub_range.start < range_start {
// TODO: use more precise error type
log::error!(
"subCS_{} sub_range.start ({}) < range_start ({})",
i,
sub_range.start,
range_start
);
return Err(Error::Synthesis);
}
if i == ranges.len() - 1 && sub_range.end >= self.rw_rows.end {
if i == ranges.len() - 1 && sub_range.end > self.rw_rows.end {
log::error!(
"subCS_{} sub_range.end ({}) > self.rw_rows.end ({})",
i,
sub_range.end,
self.rw_rows.end
);
return Err(Error::Synthesis);
}
range_start = sub_range.end;
Expand Down Expand Up @@ -219,6 +232,7 @@ impl<'a, F: Field> Assignment<F> for Assembly<'a, F> {
}

if !self.rw_rows.contains(&row) {
log::error!("assign_fixed: {:?}, row: {}", column, row);
return Err(Error::Synthesis);
}

Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/plonk/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt::{self, Debug};
pub(crate) mod prover;
pub(crate) mod verifier;

#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
pub struct Argument<F: Field> {
pub name: &'static str,
pub input_expressions: Vec<Expression<F>>,
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/plonk/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) mod verifier;
use std::io;

/// A permutation argument.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Argument {
/// A sequence of columns involved in the argument.
pub columns: Vec<Column<Any>>,
Expand Down
15 changes: 14 additions & 1 deletion halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,21 @@ where
let mut range_start = self.rw_rows.start;
for (i, sub_range) in ranges.iter().enumerate() {
if sub_range.start < range_start {
log::error!(
"subCS_{} sub_range.start ({}) < range_start ({})",
i,
sub_range.start,
range_start
);
return Err(Error::Synthesis);
}
if i == ranges.len() - 1 && sub_range.end >= self.rw_rows.end {
if i == ranges.len() - 1 && sub_range.end > self.rw_rows.end {
log::error!(
"subCS_{} sub_range.end ({}) > self.rw_rows.end ({})",
i,
sub_range.end,
self.rw_rows.end
);
return Err(Error::Synthesis);
}
range_start = sub_range.end;
Expand Down Expand Up @@ -286,6 +298,7 @@ where
}

if !self.rw_rows.contains(&row) {
log::error!("assign_advice: {:?}, row: {}", column, row);
return Err(Error::Synthesis);
}

Expand Down
Loading

0 comments on commit 82f4d6d

Please sign in to comment.