Skip to content

Commit

Permalink
chore: revert .cell() and constrain_equal to standard API (#11)
Browse files Browse the repository at this point in the history
* chore: revert `.cell()` and `constrain_equal` to standard API

* feat: public Cell
  • Loading branch information
jonathanpwang committed Aug 27, 2023
1 parent bce1523 commit 5946707
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
6 changes: 3 additions & 3 deletions halo2_proofs/benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn criterion_benchmark(c: &mut Criterion) {
region.assign_fixed(self.config.sb, 0, FF::ZERO);
region.assign_fixed(self.config.sc, 0, FF::ONE);
region.assign_fixed(self.config.sm, 0, FF::ONE);
Ok((*lhs.cell(), *rhs.cell(), *out.cell()))
Ok((lhs.cell(), rhs.cell(), out.cell()))
},
)
}
Expand All @@ -131,7 +131,7 @@ fn criterion_benchmark(c: &mut Criterion) {
region.assign_fixed(self.config.sb, 0, FF::ONE);
region.assign_fixed(self.config.sc, 0, FF::ONE);
region.assign_fixed(self.config.sm, 0, FF::ZERO);
Ok((*lhs.cell(), *rhs.cell(), *out.cell()))
Ok((lhs.cell(), rhs.cell(), out.cell()))
},
)
}
Expand All @@ -144,7 +144,7 @@ fn criterion_benchmark(c: &mut Criterion) {
layouter.assign_region(
|| "copy",
|mut region| {
region.constrain_equal(&left, &right);
region.constrain_equal(left, right);
Ok(())
},
)
Expand Down
23 changes: 6 additions & 17 deletions halo2_proofs/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,9 @@ pub struct Cell {
/// Identifies the region in which this cell resides.
// region_index: RegionIndex,
/// The relative offset of this cell within its region.
row_offset: usize,
pub row_offset: usize,
/// The column of this cell.
column: Column<Any>,
}

impl Cell {
/// Returns row offset
pub fn row_offset(&self) -> usize {
self.row_offset
}
/// Returns reference to column
pub fn column(&self) -> &Column<Any> {
&self.column
}
pub column: Column<Any>,
}

/// An assigned cell.
Expand All @@ -120,8 +109,8 @@ impl<V, F: Field> AssignedCell<V, F> {
}

/// Returns the cell.
pub fn cell(&self) -> &Cell {
&self.cell
pub fn cell(&self) -> Cell {
self.cell
}

pub fn row_offset(&self) -> usize {
Expand Down Expand Up @@ -169,7 +158,7 @@ impl<'v, F: Field> AssignedCell<&'v Assigned<F>, F> {
offset: usize,
) -> AssignedCell<&'_ Assigned<F>, F> {
let assigned_cell = region.assign_advice(column, offset, self.value.map(|v| *v));
region.constrain_equal(&assigned_cell.cell, &self.cell);
region.constrain_equal(assigned_cell.cell, self.cell);
assigned_cell
}
}
Expand Down Expand Up @@ -352,7 +341,7 @@ impl<'r, F: Field> Region<'r, F> {
///
/// Returns an error if either of the cells are in columns where equality
/// has not been enabled.
pub fn constrain_equal(&mut self, left: &Cell, right: &Cell) {
pub fn constrain_equal(&mut self, left: Cell, right: Cell) {
self.region.constrain_equal(left, right);
}

Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/floor_planner/single_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl<'r, 'a, F: Field, CS: Assignment<F> + 'a + SyncDeps> RegionLayouter<F>
Ok(())
}

fn constrain_equal(&mut self, left: &Cell, right: &Cell) {
fn constrain_equal(&mut self, left: Cell, right: Cell) {
self.layouter.cs.copy(
left.column,
left.row_offset, // *self.layouter.regions[*left.region_index] + left.row_offset,
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/circuit/layouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub trait RegionLayouter<F: Field>: fmt::Debug + SyncDeps {
/// Constraint two cells to have the same value.
///
/// Returns an error if either of the cells is not within the given permutation.
fn constrain_equal(&mut self, left: &Cell, right: &Cell);
fn constrain_equal(&mut self, left: Cell, right: Cell);

/// Queries the value of the given challenge.
///
Expand Down
10 changes: 5 additions & 5 deletions halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn plonk_api() {
region.assign_fixed(self.config.sb, 0, FF::ZERO);
region.assign_fixed(self.config.sc, 0, FF::ONE);
region.assign_fixed(self.config.sm, 0, FF::ONE);
Ok((*lhs.cell(), *rhs.cell(), *out.cell()))
Ok((lhs.cell(), rhs.cell(), out.cell()))
},
)
}
Expand Down Expand Up @@ -167,7 +167,7 @@ fn plonk_api() {
region.assign_fixed(self.config.sb, 0, FF::ONE);
region.assign_fixed(self.config.sc, 0, FF::ONE);
region.assign_fixed(self.config.sm, 0, FF::ZERO);
Ok((*lhs.cell(), *rhs.cell(), *out.cell()))
Ok((lhs.cell(), rhs.cell(), out.cell()))
},
)
}
Expand All @@ -180,8 +180,8 @@ fn plonk_api() {
layouter.assign_region(
|| "copy",
|mut region| {
region.constrain_equal(&left, &right);
region.constrain_equal(&left, &right);
region.constrain_equal(left, right);
region.constrain_equal(left, right);
Ok(())
},
)
Expand All @@ -196,7 +196,7 @@ fn plonk_api() {
let value = region.assign_advice(self.config.a, 0, f());
region.assign_fixed(self.config.sp, 0, FF::ONE);

Ok(*value.cell())
Ok(value.cell())
},
)
}
Expand Down

0 comments on commit 5946707

Please sign in to comment.