Skip to content

Commit

Permalink
[fix] FieldChip::range_check should take FieldPoint instead of `U…
Browse files Browse the repository at this point in the history
…nsafeFieldPoint` (#209)

* fix: `FieldChip::range_check` should take `FieldPoint`

instead of `UnsafeFieldPoint`

* chore: fix audit-check CI

* chore: toggle CI on release branches
  • Loading branch information
jonathanpwang authored Nov 2, 2023
1 parent 4ba2efc commit d4bf2fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["main"]
pull_request:
branches: ["main", "develop", "community-edition"]
branches: ["main", "develop", "community-edition", "release-*"]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -64,5 +64,10 @@ jobs:
- name: Run clippy
run: cargo clippy --all -- -D warnings

- name: Generate Cargo.lock
run: cargo generate-lockfile

- name: Run cargo audit
uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
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 d4bf2fa

Please sign in to comment.