Skip to content

Commit

Permalink
fix clippy + rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyKing-1 committed Jan 8, 2024
1 parent f250f4a commit 7e2c0fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions halo2-ecc/src/bn254/tests/ec_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn g2_add_test<F: BigPrimeField>(
let points =
_points.iter().map(|pt| g2_chip.assign_point_unchecked(ctx, *pt)).collect::<Vec<_>>();

let acc = g2_chip.sum::<G2Affine>(ctx, points);
let acc = g2_chip.sum_unsafe::<G2Affine>(ctx, points);

let answer = _points.iter().fold(G2Affine::identity(), |a, b| (a + b).to_affine());
let x = fp2_chip.get_assigned_value(&acc.x.into());
Expand All @@ -60,7 +60,7 @@ fn g1_sum_safe_test<F: BigPrimeField>(
let points =
_points.iter().map(|pt| g1_chip.assign_point_unchecked(ctx, *pt)).collect::<Vec<_>>();

let acc = g1_chip.sum_safe::<G1Affine>(ctx, points);
let acc = g1_chip.sum::<G1Affine>(ctx, points);

let answer = _points.iter().fold(G1Affine::identity(), |a, b| (a + b).to_affine());
let x = fp_chip.get_assigned_value(&acc.x.into());
Expand Down
2 changes: 1 addition & 1 deletion halo2-ecc/src/ecc/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where

// compute (x1, y1) = u1 * G + u2 * pubkey and check (r mod n) == x1 as integers
// because it is possible for u1 * G == u2 * pubkey, we must use `EccChip::sum`
let sum = chip.sum::<GA>(ctx, [u1_mul, u2_mul]);
let sum = chip.sum_unsafe::<GA>(ctx, [u1_mul, u2_mul]);
// WARNING: For optimization reasons, does not reduce x1 mod n, which is
// invalid unless p is very close to n in size.
// enforce x1 < n
Expand Down
14 changes: 7 additions & 7 deletions halo2-ecc/src/ecc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,8 @@ impl<'chip, F: BigPrimeField, FC: FieldChip<F>> EccChip<'chip, F, FC> {
self.field_chip.assert_equal(ctx, P.y, Q.y);
}

/// None of elements in `points` can be point at infinity.
pub fn sum<C>(
/// None of elements in `points` can be point at infinity. Sum cannot be point at infinity either.
pub fn sum_unsafe<C>(
&self,
ctx: &mut Context<F>,
points: impl IntoIterator<Item = EcPoint<F, FC::FieldPoint>>,
Expand All @@ -1036,7 +1036,8 @@ impl<'chip, F: BigPrimeField, FC: FieldChip<F>> EccChip<'chip, F, FC>
where
FC: Selectable<F, FC::FieldPoint>,
{
pub fn sum_safe<C>(
/// Expensive version of `sum_unsafe`, but works generally
pub fn sum<C>(
&self,
ctx: &mut Context<F>,
points: impl IntoIterator<Item = EcPoint<F, FC::FieldPoint>>,
Expand All @@ -1047,15 +1048,14 @@ where
let rand_point = self.load_random_point::<C>(ctx);
let rand_point2 = self.load_random_point::<C>(ctx);
let zero = ctx.load_constant(F::ZERO);
let rand_point = into_strict_point(self.field_chip, ctx, rand_point);
let neg_rand_point = self.negate_strict(ctx, rand_point.clone());
let mut acc = StrictEcPoint::from(neg_rand_point.clone());
let neg_rand_point = self.negate(ctx, rand_point.clone());
let mut acc = ComparableEcPoint::from(neg_rand_point.clone());
for point in points {
let point_is_inf = self.is_infinity(ctx, point.clone());
let addend = self.select(ctx, rand_point2.clone(), point.clone(), point_is_inf);
let _acc = self.add_unequal(ctx, acc.clone(), addend.clone(), true);
let _acc = self.select(ctx, acc.clone().into(), _acc, point_is_inf);
acc = into_strict_point(self.field_chip, ctx, _acc);
acc = _acc.into();
let acc_is_inf = self.is_infinity(ctx, acc.clone().into());
ctx.constrain_equal(&acc_is_inf, &zero);
}
Expand Down

0 comments on commit 7e2c0fd

Please sign in to comment.