Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow halo2 constraint names to have non static names #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,13 @@ mod tests {
assert_eq!(
prover.verify(),
Err(vec![VerifyFailure::Lookup {
name: "lookup",
name: "lookup".to_string(),
lookup_index: 0,
location: FailureLocation::InRegion {
region: (1, "Range check 6 bits").into(),
offset: 1,
},
}])
}]),
);
}

Expand All @@ -603,15 +603,15 @@ mod tests {
prover.verify(),
Err(vec![
VerifyFailure::Lookup {
name: "lookup",
name: "lookup".to_string(),
lookup_index: 0,
location: FailureLocation::InRegion {
region: (1, "Range check 6 bits").into(),
offset: 0,
},
},
VerifyFailure::Lookup {
name: "lookup",
name: "lookup".to_string(),
lookup_index: 0,
location: FailureLocation::InRegion {
region: (1, "Range check 6 bits").into(),
Expand Down Expand Up @@ -641,7 +641,7 @@ mod tests {
assert_eq!(
prover.verify(),
Err(vec![VerifyFailure::Lookup {
name: "lookup",
name: "lookup".to_string(),
lookup_index: 0,
location: FailureLocation::InRegion {
region: (1, "Range check 6 bits").into(),
Expand Down
8 changes: 4 additions & 4 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ impl<F: FromUniformBytes<64> + Ord> MockProver<F> {
assert!(table.binary_search(input).is_err());

Some(VerifyFailure::Lookup {
name: lookup.name,
name: lookup.name.clone(),
lookup_index,
location: FailureLocation::find_expressions(
&self.cs,
Expand Down Expand Up @@ -1342,7 +1342,7 @@ impl<F: FromUniformBytes<64> + Ord> MockProver<F> {
.filter_map(move |(input, input_row)| {
if table.binary_search(input).is_err() {
Some(VerifyFailure::Lookup {
name: lookup.name,
name: lookup.name.clone(),
lookup_index,
location: FailureLocation::find_expressions(
&self.cs,
Expand Down Expand Up @@ -1765,7 +1765,7 @@ mod tests {
assert_eq!(
prover.verify(),
Err(vec![VerifyFailure::Lookup {
name: "lookup",
name: "lookup".to_string(),
lookup_index: 0,
location: FailureLocation::InRegion {
region: (1, "Faulty synthesis").into(),
Expand Down Expand Up @@ -1897,7 +1897,7 @@ mod tests {
assert_eq!(
prover.verify(),
Err(vec![VerifyFailure::Lookup {
name: "lookup",
name: "lookup".to_string(),
lookup_index: 0,
location: FailureLocation::InRegion {
region: (2, "Faulty synthesis").into(),
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/dev/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub enum VerifyFailure {
/// A lookup input did not exist in its corresponding table.
Lookup {
/// The name of the lookup that is not satisfied.
name: &'static str,
name: String,
/// The index of the lookup that is not satisfied. These indices are assigned in
/// the order in which `ConstraintSystem::lookup` is called during
/// `Circuit::configure`.
Expand Down Expand Up @@ -277,7 +277,7 @@ impl Debug for VerifyFailure {
};

let debug = ConstraintCaseDebug {
constraint: *constraint,
constraint: constraint.clone(),
location: location.clone(),
cell_values: cell_values
.iter()
Expand Down
8 changes: 4 additions & 4 deletions halo2_proofs/src/dev/gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use crate::{

#[derive(Debug)]
struct Constraint {
name: &'static str,
name: String,
expression: String,
queries: BTreeSet<String>,
}

#[derive(Debug)]
struct Gate {
name: &'static str,
name: String,
constraints: Vec<Constraint>,
}

Expand Down Expand Up @@ -112,13 +112,13 @@ impl CircuitGates {
.gates
.iter()
.map(|gate| Gate {
name: gate.name(),
name: gate.name().to_string(),
constraints: gate
.polynomials()
.iter()
.enumerate()
.map(|(i, constraint)| Constraint {
name: gate.constraint_name(i),
name: gate.constraint_name(i).to_string(),
expression: constraint.evaluate(
&util::format_value,
&|selector| format!("S{}", selector.0),
Expand Down
51 changes: 29 additions & 22 deletions halo2_proofs/src/dev/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ impl fmt::Display for DebugColumn {
/// within a custom gate.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct VirtualCell {
name: &'static str,
name: String,
pub(super) column: Column,
pub(super) rotation: i32,
}

impl From<(Column, i32)> for VirtualCell {
fn from((column, rotation): (Column, i32)) -> Self {
VirtualCell {
name: "",
name: "".to_string(),
column,
rotation,
}
}
}

impl From<(&'static str, Column, i32)> for VirtualCell {
fn from((name, column, rotation): (&'static str, Column, i32)) -> Self {
impl<S: AsRef<str>> From<(S, Column, i32)> for VirtualCell {
fn from((name, column, rotation): (S, Column, i32)) -> Self {
VirtualCell {
name,
name: name.as_ref().to_string(),
column,
rotation,
}
Expand All @@ -103,7 +103,7 @@ impl From<(&'static str, Column, i32)> for VirtualCell {
impl From<plonk::VirtualCell> for VirtualCell {
fn from(c: plonk::VirtualCell) -> Self {
VirtualCell {
name: "",
name: "".to_string(),
column: c.column.into(),
rotation: c.rotation.0,
}
Expand All @@ -114,7 +114,7 @@ impl fmt::Display for VirtualCell {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}@{}", self.column, self.rotation)?;
if !self.name.is_empty() {
write!(f, "({})", self.name)?;
write!(f, "({})", self.name.as_str())?;
}
Ok(())
}
Expand All @@ -123,15 +123,15 @@ impl fmt::Display for VirtualCell {
/// Helper structure used to be able to inject Column annotations inside a `Display` or `Debug` call.
#[derive(Clone, Debug)]
pub(super) struct DebugVirtualCell {
name: &'static str,
name: String,
column: DebugColumn,
rotation: i32,
}

impl From<(&VirtualCell, Option<&HashMap<Column, String>>)> for DebugVirtualCell {
fn from(info: (&VirtualCell, Option<&HashMap<Column, String>>)) -> Self {
DebugVirtualCell {
name: info.0.name,
name: info.0.name.clone(),
column: DebugColumn::from((info.0.column, info.1)),
rotation: info.0.rotation,
}
Expand All @@ -149,30 +149,33 @@ impl fmt::Display for DebugVirtualCell {
}

/// Metadata about a configured gate within a circuit.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Gate {
/// The index of the active gate. These indices are assigned in the order in which
/// `ConstraintSystem::create_gate` is called during `Circuit::configure`.
pub(super) index: usize,
/// The name of the active gate. These are specified by the gate creator (such as
/// a chip implementation), and is not enforced to be unique.
pub(super) name: &'static str,
pub(super) name: String,
}

impl fmt::Display for Gate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Gate {} ('{}')", self.index, self.name)
write!(f, "Gate {} ('{}')", self.index, self.name.as_str())
}
}

impl From<(usize, &'static str)> for Gate {
fn from((index, name): (usize, &'static str)) -> Self {
Gate { index, name }
impl<S: AsRef<str>> From<(usize, S)> for Gate {
fn from((index, name): (usize, S)) -> Self {
Gate {
index,
name: name.as_ref().to_string(),
}
}
}

/// Metadata about a configured constraint within a circuit.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Constraint {
/// The gate containing the constraint.
pub(super) gate: Gate,
Expand All @@ -182,7 +185,7 @@ pub struct Constraint {
pub(super) index: usize,
/// The name of the constraint. This is specified by the gate creator (such as a chip
/// implementation), and is not enforced to be unique.
pub(super) name: &'static str,
pub(super) name: String,
}

impl fmt::Display for Constraint {
Expand All @@ -194,17 +197,21 @@ impl fmt::Display for Constraint {
if self.name.is_empty() {
String::new()
} else {
format!(" ('{}')", self.name)
format!(" ('{}')", self.name.as_str())
},
self.gate.index,
self.gate.name,
)
}
}

impl From<(Gate, usize, &'static str)> for Constraint {
fn from((gate, index, name): (Gate, usize, &'static str)) -> Self {
Constraint { gate, index, name }
impl<S: AsRef<str>> From<(Gate, usize, S)> for Constraint {
fn from((gate, index, name): (Gate, usize, S)) -> Self {
Constraint {
gate,
index,
name: name.as_ref().to_string(),
}
}
}

Expand Down Expand Up @@ -250,7 +257,7 @@ impl Debug for Region {

impl fmt::Display for Region {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Region {} ('{}')", self.index, self.name)
write!(f, "Region {} ('{}')", self.index, self.name.as_str())
}
}

Expand Down
Loading