Skip to content

Commit

Permalink
Merge pull request #64 from kroma-network/refac/refactor-math
Browse files Browse the repository at this point in the history
refac: refactor math
  • Loading branch information
chokobole authored Sep 26, 2023
2 parents 4569add + 829209e commit 0e26c04
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 414 deletions.
5 changes: 0 additions & 5 deletions tachyon/math/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ tachyon_cc_library(
deps = [":semigroups"],
)

tachyon_cc_library(
name = "identities",
hdrs = ["identities.h"],
)

tachyon_cc_library(
name = "rings",
hdrs = ["rings.h"],
Expand Down
12 changes: 0 additions & 12 deletions tachyon/math/base/gmp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ tachyon_cc_library(
],
)

tachyon_cc_library(
name = "gmp_identities",
hdrs = ["gmp_identities.h"],
deps = [
"//tachyon/base:no_destructor",
"//tachyon/math/base:identities",
"@local_config_gmp//:gmp",
],
)

tachyon_cc_library(
name = "gmp_util",
srcs = ["gmp_util.cc"],
Expand All @@ -56,11 +46,9 @@ tachyon_cc_test(
name = "gmp_unittests",
size = "small",
srcs = [
"gmp_identities_unittest.cc",
"gmp_util_unittest.cc",
],
deps = [
":gmp_identities",
":gmp_util",
"//tachyon/build:build_config",
],
Expand Down
35 changes: 0 additions & 35 deletions tachyon/math/base/gmp/gmp_identities.h

This file was deleted.

19 changes: 0 additions & 19 deletions tachyon/math/base/gmp/gmp_identities_unittest.cc

This file was deleted.

34 changes: 0 additions & 34 deletions tachyon/math/base/identities.h

This file was deleted.

5 changes: 1 addition & 4 deletions tachyon/math/elliptic_curves/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ tachyon_cc_library(
"projective_point.h",
"semigroups.h",
],
deps = [
"//tachyon/base:no_destructor",
"//tachyon/math/base:identities",
],
deps = ["//tachyon/base:no_destructor"],
)
26 changes: 0 additions & 26 deletions tachyon/math/elliptic_curves/affine_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,6 @@ JacobianPoint<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<AffinePoint<Curve>> {
public:
using P = AffinePoint<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<AffinePoint<Curve>> {
public:
using P = AffinePoint<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<AffinePoint<Curve>, AffinePoint<Curve>> {
constexpr static const AffinePoint<Curve>& Convert(
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/elliptic_curves/jacobian_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ostream>

#include "tachyon/base/no_destructor.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/elliptic_curves/point_conversions_forward.h"

namespace tachyon::math {
Expand All @@ -23,32 +22,6 @@ JacobianPoint<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<JacobianPoint<Curve>> {
public:
using P = JacobianPoint<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<JacobianPoint<Curve>> {
public:
using P = JacobianPoint<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<JacobianPoint<Curve>, JacobianPoint<Curve>> {
constexpr static const JacobianPoint<Curve>& Convert(
Expand Down
1 change: 0 additions & 1 deletion tachyon/math/elliptic_curves/msm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ tachyon_cc_library(
"//tachyon/base:static_storage",
"//tachyon/math/base:bit_iterator",
"//tachyon/math/base/gmp:bit_traits",
"//tachyon/math/base/gmp:gmp_identities",
"//tachyon/math/base/gmp:signed_value",
"//tachyon/math/elliptic_curves:points",
"//tachyon/math/matrix:gmp_num_traits",
Expand Down
1 change: 0 additions & 1 deletion tachyon/math/elliptic_curves/msm/glv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "tachyon/base/static_storage.h"
#include "tachyon/math/base/bit_iterator.h"
#include "tachyon/math/base/gmp/bit_traits.h"
#include "tachyon/math/base/gmp/gmp_identities.h"
#include "tachyon/math/base/gmp/signed_value.h"
#include "tachyon/math/elliptic_curves/affine_point.h"
#include "tachyon/math/elliptic_curves/jacobian_point.h"
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/elliptic_curves/point_xyzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ostream>

#include "tachyon/base/no_destructor.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/elliptic_curves/point_conversions_forward.h"

namespace tachyon::math {
Expand All @@ -23,32 +22,6 @@ PointXYZZ<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<PointXYZZ<Curve>> {
public:
using P = PointXYZZ<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<PointXYZZ<Curve>> {
public:
using P = PointXYZZ<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<PointXYZZ<Curve>, PointXYZZ<Curve>> {
constexpr static const PointXYZZ<Curve>& Convert(
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/elliptic_curves/projective_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <ostream>

#include "tachyon/base/no_destructor.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/elliptic_curves/point_conversions_forward.h"

namespace tachyon::math {
Expand All @@ -24,32 +23,6 @@ ProjectivePoint<Curve> operator*(const ScalarField& v,
return point * v;
}

template <typename Curve>
class MultiplicativeIdentity<ProjectivePoint<Curve>> {
public:
using P = ProjectivePoint<Curve>;

static const P& One() {
static base::NoDestructor<P> one(P::One());
return *one;
}

constexpr static bool IsOne(const P& value) { return value.IsOne(); }
};

template <typename Curve>
class AdditiveIdentity<ProjectivePoint<Curve>> {
public:
using P = ProjectivePoint<Curve>;

static const P& Zero() {
static base::NoDestructor<P> zero(P::Zero());
return *zero;
}

constexpr static bool IsZero(const P& value) { return value.IsZero(); }
};

template <typename Curve>
struct PointConversions<ProjectivePoint<Curve>, ProjectivePoint<Curve>> {
constexpr static const ProjectivePoint<Curve>& Convert(
Expand Down
2 changes: 0 additions & 2 deletions tachyon/math/finite_fields/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ tachyon_cc_library(
"//tachyon/base:no_destructor",
"//tachyon/base/strings:string_util",
"//tachyon/math/base:field",
"//tachyon/math/base:identities",
"//tachyon/math/base/gmp:gmp_util",
],
)
Expand All @@ -83,7 +82,6 @@ tachyon_cc_library(
"//tachyon/base/containers:adapters",
"//tachyon/base/strings:string_util",
"//tachyon/math/base:arithmetics",
"//tachyon/math/base:identities",
"//tachyon/math/base/gmp:gmp_util",
"@com_google_googletest//:gtest_prod",
],
Expand Down
27 changes: 0 additions & 27 deletions tachyon/math/finite_fields/prime_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "tachyon/math/base/arithmetics.h"
#include "tachyon/math/base/big_int.h"
#include "tachyon/math/base/gmp/gmp_util.h"
#include "tachyon/math/base/identities.h"
#include "tachyon/math/finite_fields/modulus.h"
#include "tachyon/math/finite_fields/prime_field_base.h"
#include "tachyon/math/finite_fields/prime_field_forward.h"
Expand Down Expand Up @@ -297,32 +296,6 @@ std::ostream& operator<<(std::ostream& os, const PrimeField<Config>& f) {
return os << f.ToString();
}

template <typename Config>
class MultiplicativeIdentity<PrimeField<Config>> {
public:
using F = PrimeField<Config>;

static const F& One() {
static F one(F::One());
return one;
}

constexpr static bool IsOne(const F& value) { return value.IsOne(); }
};

template <typename Config>
class AdditiveIdentity<PrimeField<Config>> {
public:
using F = PrimeField<Config>;

static const F& Zero() {
static F zero(F::Zero());
return zero;
}

constexpr static bool IsZero(const F& value) { return value.IsZero(); }
};

} // namespace tachyon::math

#endif // TACHYON_MATH_FINITE_FIELDS_PRIME_FIELD_H_
Loading

0 comments on commit 0e26c04

Please sign in to comment.