Skip to content

Commit

Permalink
don't use y = 0 as error condition. instead use (x = 0, y = 0) as fai…
Browse files Browse the repository at this point in the history
…lure return.
  • Loading branch information
suyash67 committed Apr 25, 2023
1 parent 2a13702 commit aacba60
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,18 @@ constexpr std::array<affine_element<Fq, Fr, T>, 2> affine_element<Fq, Fr, T>::fr
if constexpr (T::has_a) {
y2 += (x * T::a);
}
auto [is_quadratic_remainder, y] = y2.sqrt();
if (!is_quadratic_remainder) {
return Fq::zero();
}
return Fq(y);
return y2.sqrt();
};

uint256_t x_1 = compressed;
uint256_t x_2 = compressed + Fr::modulus;
auto y_1 = get_y_coordinate(x_1);
auto y_2 = get_y_coordinate(x_2);
auto output_1 = affine_element<Fq, Fr, T>(y_1 == Fq::zero() ? Fq::zero() : Fq(x_1), y_1);
auto output_2 = affine_element<Fq, Fr, T>(y_1 == Fq::zero() ? Fq::zero() : Fq(x_2), y_2);
auto [is_quadratic_remainder_1, y_1] = get_y_coordinate(x_1);
auto [is_quadratic_remainder_2, y_2] = get_y_coordinate(x_2);

auto output_1 = is_quadratic_remainder_1 ? affine_element<Fq, Fr, T>(Fq(x_1), y_1)
: affine_element<Fq, Fr, T>(Fq::zero(), Fq::zero());
auto output_2 = is_quadratic_remainder_2 ? affine_element<Fq, Fr, T>(Fq(x_2), y_2)
: affine_element<Fq, Fr, T>(Fq::zero(), Fq::zero());

return { output_1, output_2 };
}
Expand Down

0 comments on commit aacba60

Please sign in to comment.