Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

halo2-ecc: update is_on_curve helper to support p256 #28

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions halo2-ecc/src/ecc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,25 @@ where
FC: FieldChip<F>,
C: CurveAffine<Base = FC::FieldType>,
{
// calculate y^2
let lhs = chip.mul_no_carry(ctx, &P.y, &P.y);
// calculate x^2
let mut rhs = chip.mul(ctx, &P.x, &P.x);
// calculate x^3
rhs = chip.mul_no_carry(ctx, &rhs, &P.x);

let a_const = FC::fe_to_constant(C::a());
let a = chip.load_constant(ctx, a_const);
let b = FC::fe_to_constant(C::b());
// calculate x^3 + b
rhs = chip.add_constant_no_carry(ctx, &rhs, b);
// calculate `a*x` part of the whole equation: `y^2= x^3 + a*x + b`, if a = 0 (for secp256k1),
// `a*x` is zero.
// add chip.mul_constant helper ?
let ax = chip.mul(ctx, &P.x, &a);
// calculate x^3 + a*x + b
rhs = chip.add_no_carry(ctx, &rhs, &ax);

let diff = chip.sub_no_carry(ctx, &lhs, &rhs);
chip.check_carry_mod_to_zero(ctx, &diff)
}
Expand Down Expand Up @@ -615,8 +628,17 @@ impl<F: PrimeField, FC: FieldChip<F>> EccChip<F, FC> {
let mut rhs = self.field_chip.mul(ctx, &P.x, &P.x);
rhs = self.field_chip.mul_no_carry(ctx, &rhs, &P.x);

let a_const = FC::fe_to_constant(C::a());
let a = self.field_chip.load_constant(ctx, a_const);

let b = FC::fe_to_constant(C::b());
rhs = self.field_chip.add_constant_no_carry(ctx, &rhs, b);
// calculate `a*x` part of the whole equation: `y^2= x^3 + a*x + b`, if a = 0 (for secp256k1),
// `a*x` is zero.
// add chip.mul_constant helper ?
let ax = self.field_chip.mul(ctx, &P.x, &a);
// calculate x^3 + a*x + b
rhs = self.field_chip.add_no_carry(ctx, &rhs, &ax);
let mut diff = self.field_chip.sub_no_carry(ctx, &lhs, &rhs);
diff = self.field_chip.carry_mod(ctx, &diff);

Expand Down