Skip to content

Commit

Permalink
Add comments on default comparisons.
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkinwho committed Nov 29, 2023
1 parent ad21d26 commit 6818a31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/bls12-381/fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ class fp
bool isLexicographicallyLargest() const;
template<size_t N> static fp modPrime(const std::array<uint64_t, N>& k);

std::strong_ordering operator<=>(const fp& e) const { return cmp(e); }
// Those operators are defined to support set and map.
// They are mathematically correctly in certain cases.
// However, there are still ambiguity there as the fp can be in Montgomery form or not.
// Please avoid using those operators.
constexpr std::strong_ordering operator<=>(const fp& e) const { return cmp(e); }

static const fp MODULUS; // base field modulus: p = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 or 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAB
static const uint64_t INP; // INP = -(p^{-1} mod 2^64) mod 2^64
Expand Down Expand Up @@ -124,6 +128,9 @@ class fp2
bool isQuadraticNonResidue() const;
bool isLexicographicallyLargest() const;

// Those operators are defined to support set and map.
// They are not mathematically correct.
// DO NOT use them to compare fp2.
auto operator<=>(const fp2&) const = default;

static const fp2 negativeOne2;
Expand Down
6 changes: 6 additions & 0 deletions include/bls12-381/g.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class g1
g1 clearCofactor() const;
g1 glvEndomorphism() const;

// Those operators are defined to support set and map.
// They are not mathematically correct.
// DO NOT use them to compare g1.
auto operator<=>(const g1&) const = default;

static g1 weightedSum(std::span<const g1> points, std::span<const std::array<uint64_t, 4>> scalars, const std::function<void()>& yield = std::function<void()>());
Expand Down Expand Up @@ -121,6 +124,9 @@ class g2
g2 clearCofactor() const;
g2 frobeniusMap(int64_t power) const;

// Those operators are defined to support set and map.
// They are not mathematically correct.
// DO NOT use them to compare g2.
auto operator<=>(const g2&) const = default;

static g2 weightedSum(std::span<const g2> points, std::span<const std::array<uint64_t, 4>> scalars, const std::function<void()>& yield = std::function<void()>());
Expand Down

0 comments on commit 6818a31

Please sign in to comment.