Skip to content

Commit 75811ae

Browse files
committed
Migrate to group::CurveAffine
1 parent 7e3fc6a commit 75811ae

File tree

4 files changed

+18
-42
lines changed

4 files changed

+18
-42
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ sqrt-table = ["alloc", "lazy_static"]
7373
repr-c = []
7474
uninline-portable = []
7575
serde = ["hex", "serde_crate"]
76+
77+
[patch.crates-io]
78+
group = { git = "https://github.com/zkcrypto/group.git", rev = "85c484fff517135cedfe265ef893bd4b8d745300" }

src/arithmetic/curves.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub trait CurveExt:
2424
+ Default
2525
+ ConditionallySelectable
2626
+ ConstantTimeEq
27-
+ From<<Self as PrimeCurve>::Affine>
27+
+ From<Self::Affine>
2828
{
2929
/// The scalar field of this elliptic curve.
3030
type ScalarExt: ff::WithSmallOrderMulGroup<3>;
@@ -88,15 +88,13 @@ pub trait CurveExt:
8888
#[cfg(feature = "alloc")]
8989
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
9090
pub trait CurveAffine:
91-
PrimeCurveAffine<
92-
Scalar = <Self as CurveAffine>::ScalarExt,
93-
Curve = <Self as CurveAffine>::CurveExt,
94-
> + Default
95-
+ Add<Output = <Self as PrimeCurveAffine>::Curve>
96-
+ Sub<Output = <Self as PrimeCurveAffine>::Curve>
91+
PrimeCurveAffine<Curve = Self::CurveExt>
92+
+ Default
93+
+ Add<Output = Self::Curve>
94+
+ Sub<Output = Self::Curve>
9795
+ ConditionallySelectable
9896
+ ConstantTimeEq
99-
+ From<<Self as PrimeCurveAffine>::Curve>
97+
+ From<Self::Curve>
10098
{
10199
/// The scalar field of this elliptic curve.
102100
type ScalarExt: ff::WithSmallOrderMulGroup<3> + Ord;

src/curves.rs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use alloc::boxed::Box;
1212
use ff::{Field, PrimeField};
1313
use group::{
1414
cofactor::{CofactorCurve, CofactorGroup},
15-
prime::{PrimeCurve, PrimeCurveAffine, PrimeGroup},
16-
Curve as _, Group as _, GroupEncoding,
15+
prime::{PrimeCurve, PrimeGroup},
16+
Curve as _, CurveAffine as _, Group as _, GroupEncoding,
1717
};
1818
use rand::RngCore;
1919
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
@@ -168,9 +168,9 @@ macro_rules! new_curve_impl {
168168
}
169169

170170
impl group::Curve for $name {
171-
type AffineRepr = $name_affine;
171+
type Affine = $name_affine;
172172

173-
fn batch_normalize(p: &[Self], q: &mut [Self::AffineRepr]) {
173+
fn batch_normalize(p: &[Self], q: &mut [Self::Affine]) {
174174
assert_eq!(p.len(), q.len());
175175

176176
let mut acc = $base::one();
@@ -207,7 +207,7 @@ macro_rules! new_curve_impl {
207207
}
208208
}
209209

210-
fn to_affine(&self) -> Self::AffineRepr {
210+
fn to_affine(&self) -> Self::Affine {
211211
let zinv = self.z.invert().unwrap_or($base::zero());
212212
let zinv2 = zinv.square();
213213
let x = self.x * zinv2;
@@ -244,13 +244,9 @@ macro_rules! new_curve_impl {
244244
}
245245
}
246246

247-
impl PrimeCurve for $name {
248-
type Affine = $name_affine;
249-
}
247+
impl PrimeCurve for $name {}
250248

251-
impl CofactorCurve for $name {
252-
type Affine = $name_affine;
253-
}
249+
impl CofactorCurve for $name {}
254250

255251
impl GroupEncoding for $name {
256252
type Repr = [u8; 32];
@@ -610,7 +606,7 @@ macro_rules! new_curve_impl {
610606
}
611607
}
612608

613-
impl PrimeCurveAffine for $name_affine {
609+
impl group::CurveAffine for $name_affine {
614610
type Curve = $name;
615611
type Scalar = $scalar;
616612

@@ -636,27 +632,6 @@ macro_rules! new_curve_impl {
636632
}
637633
}
638634

639-
impl group::cofactor::CofactorCurveAffine for $name_affine {
640-
type Curve = $name;
641-
type Scalar = $scalar;
642-
643-
fn identity() -> Self {
644-
<Self as PrimeCurveAffine>::identity()
645-
}
646-
647-
fn generator() -> Self {
648-
<Self as PrimeCurveAffine>::generator()
649-
}
650-
651-
fn is_identity(&self) -> Choice {
652-
<Self as PrimeCurveAffine>::is_identity(self)
653-
}
654-
655-
fn to_curve(&self) -> Self::Curve {
656-
<Self as PrimeCurveAffine>::to_curve(self)
657-
}
658-
}
659-
660635
impl GroupEncoding for $name_affine {
661636
type Repr = [u8; 32];
662637

src/serde_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ mod tests {
137137
use core::fmt::Debug;
138138

139139
use ff::Field;
140-
use group::{prime::PrimeCurveAffine, Curve, Group};
140+
use group::{Curve, CurveAffine, Group};
141141
use rand::SeedableRng;
142142
use rand_xorshift::XorShiftRng;
143143

0 commit comments

Comments
 (0)