Skip to content

Commit

Permalink
Fix test_sw_properties for some cofactor groups
Browse files Browse the repository at this point in the history
The sw_properties test failed for groups with cofactors, for which the
first valid point (according to incrementing x) was on the prime order
subgroup.
The test assumed that the first point should have been of low order,
such that multiplying it with the cofactor put it in the high order
group.

This patch simplifies the code, and skips over these points.

Fixes arkworks-rs#553
  • Loading branch information
rubdos committed Dec 22, 2022
1 parent 30903df commit d62122c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions test-templates/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,17 @@ macro_rules! __test_group {
assert!(generator.is_on_curve());
assert!(generator.is_in_correct_subgroup_assuming_on_curve());

let mut x = BaseField::zero();
let mut i = 0;
loop {
for i in 0.. {
let x = BaseField::from(i);
// y^2 = x^3 + a * x + b
let rhs = x * x.square() + x * <Config as SWCurveConfig>::COEFF_A + <Config as SWCurveConfig>::COEFF_B;

if let Some(y) = rhs.sqrt() {
let p = Affine::new_unchecked(x, if y < -y { y } else { -y });
if !<<$group as CurveGroup>::Config as CurveConfig>::cofactor_is_one() {
assert!(!p.is_in_correct_subgroup_assuming_on_curve());
if p.is_in_correct_subgroup_assuming_on_curve() {
continue;
}
}

let g1 = p.mul_by_cofactor_to_group();
Expand All @@ -278,9 +279,6 @@ macro_rules! __test_group {
break;
}
}

i += 1;
x += BaseField::one();
}

for _ in 0..ITERATIONS {
Expand Down

0 comments on commit d62122c

Please sign in to comment.