Skip to content

Commit

Permalink
fix: FieldChip::range_check should take FieldPoint
Browse files Browse the repository at this point in the history
instead of `UnsafeFieldPoint`
  • Loading branch information
jonathanpwang committed Nov 2, 2023
1 parent 4ba2efc commit 41e66af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions halo2-ecc/src/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,17 @@ impl<'range, F: BigPrimeField, Fp: BigPrimeField> FieldChip<F> for FpChip<'range
fn range_check(
&self,
ctx: &mut Context<F>,
a: impl Into<CRTInteger<F>>,
a: impl Into<ProperCrtUint<F>>,
max_bits: usize, // the maximum bits that a.value could take
) {
let n = self.limb_bits;
let a = a.into();
let mut remaining_bits = max_bits;

debug_assert!(a.value.bits() as usize <= max_bits);
debug_assert!(a.0.value.bits() as usize <= max_bits);

// range check limbs of `a` are in [0, 2^n) except last limb should be in [0, 2^last_limb_bits)
for cell in a.truncation.limbs {
for cell in a.0.truncation.limbs {
let limb_bits = cmp::min(n, remaining_bits);
remaining_bits -= limb_bits;
self.range.range_check(ctx, cell, limb_bits);
Expand Down
7 changes: 1 addition & 6 deletions halo2-ecc/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ pub trait FieldChip<F: BigPrimeField>: Clone + Send + Sync {

fn carry_mod(&self, ctx: &mut Context<F>, a: Self::UnsafeFieldPoint) -> Self::FieldPoint;

fn range_check(
&self,
ctx: &mut Context<F>,
a: impl Into<Self::UnsafeFieldPoint>,
max_bits: usize,
);
fn range_check(&self, ctx: &mut Context<F>, a: impl Into<Self::FieldPoint>, max_bits: usize);

/// Constrains that `a` is a reduced representation and returns the wrapped `a`.
fn enforce_less_than(
Expand Down
4 changes: 2 additions & 2 deletions halo2-ecc/src/fields/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ where
a: impl IntoIterator<Item = A>,
max_bits: usize,
) where
A: Into<FpChip::UnsafeFieldPoint>,
A: Into<FpChip::FieldPoint>,
{
for coeff in a {
self.fp_chip.range_check(ctx, coeff, max_bits);
Expand Down Expand Up @@ -435,7 +435,7 @@ macro_rules! impl_field_ext_chip_common {
fn range_check(
&self,
ctx: &mut Context<F>,
a: impl Into<Self::UnsafeFieldPoint>,
a: impl Into<Self::FieldPoint>,
max_bits: usize,
) {
self.0.range_check(ctx, a.into(), max_bits)
Expand Down

0 comments on commit 41e66af

Please sign in to comment.