From 59467073402fc8630e0619619da98f4b75a5976e Mon Sep 17 00:00:00 2001 From: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com> Date: Sun, 27 Aug 2023 00:43:52 -0600 Subject: [PATCH] chore: revert `.cell()` and `constrain_equal` to standard API (#11) * chore: revert `.cell()` and `constrain_equal` to standard API * feat: public Cell --- halo2_proofs/benches/plonk.rs | 6 ++--- halo2_proofs/src/circuit.rs | 23 +++++-------------- .../src/circuit/floor_planner/single_pass.rs | 2 +- halo2_proofs/src/circuit/layouter.rs | 2 +- halo2_proofs/tests/plonk_api.rs | 10 ++++---- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/halo2_proofs/benches/plonk.rs b/halo2_proofs/benches/plonk.rs index 1c2b962dd0..69ac368be9 100644 --- a/halo2_proofs/benches/plonk.rs +++ b/halo2_proofs/benches/plonk.rs @@ -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())) }, ) } @@ -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())) }, ) } @@ -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(()) }, ) diff --git a/halo2_proofs/src/circuit.rs b/halo2_proofs/src/circuit.rs index 2dd94d5028..742d35168d 100644 --- a/halo2_proofs/src/circuit.rs +++ b/halo2_proofs/src/circuit.rs @@ -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, -} - -impl Cell { - /// Returns row offset - pub fn row_offset(&self) -> usize { - self.row_offset - } - /// Returns reference to column - pub fn column(&self) -> &Column { - &self.column - } + pub column: Column, } /// An assigned cell. @@ -120,8 +109,8 @@ impl AssignedCell { } /// Returns the cell. - pub fn cell(&self) -> &Cell { - &self.cell + pub fn cell(&self) -> Cell { + self.cell } pub fn row_offset(&self) -> usize { @@ -169,7 +158,7 @@ impl<'v, F: Field> AssignedCell<&'v Assigned, F> { offset: usize, ) -> AssignedCell<&'_ Assigned, 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 } } @@ -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); } diff --git a/halo2_proofs/src/circuit/floor_planner/single_pass.rs b/halo2_proofs/src/circuit/floor_planner/single_pass.rs index 8d3ee380fb..714ba923aa 100644 --- a/halo2_proofs/src/circuit/floor_planner/single_pass.rs +++ b/halo2_proofs/src/circuit/floor_planner/single_pass.rs @@ -377,7 +377,7 @@ impl<'r, 'a, F: Field, CS: Assignment + 'a + SyncDeps> RegionLayouter 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, diff --git a/halo2_proofs/src/circuit/layouter.rs b/halo2_proofs/src/circuit/layouter.rs index c2d3ad62dc..b1bf8b8111 100644 --- a/halo2_proofs/src/circuit/layouter.rs +++ b/halo2_proofs/src/circuit/layouter.rs @@ -121,7 +121,7 @@ pub trait RegionLayouter: 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. /// diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index 3e1db8231d..b6e7816b83 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -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())) }, ) } @@ -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())) }, ) } @@ -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(()) }, ) @@ -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()) }, ) }