diff --git a/benchmark/ec/ec_double_benchmark_gpu.cc b/benchmark/ec/ec_double_benchmark_gpu.cc index c1bbe8bf2..960eea6c4 100644 --- a/benchmark/ec/ec_double_benchmark_gpu.cc +++ b/benchmark/ec/ec_double_benchmark_gpu.cc @@ -9,9 +9,9 @@ #include "tachyon/base/time/time_interval.h" #include "tachyon/device/gpu/gpu_memory.h" #include "tachyon/math/elliptic_curves/bn/bn254/g1_gpu.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" #include "tachyon/math/elliptic_curves/short_weierstrass/kernels/elliptic_curve_ops.cu.h" #include "tachyon/math/elliptic_curves/test/random.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon { diff --git a/tachyon/c/math/elliptic_curves/msm/msm_gpu.h b/tachyon/c/math/elliptic_curves/msm/msm_gpu.h index b48bc6cfd..8cd94e1e8 100644 --- a/tachyon/c/math/elliptic_curves/msm/msm_gpu.h +++ b/tachyon/c/math/elliptic_curves/msm/msm_gpu.h @@ -13,9 +13,9 @@ #include "tachyon/c/math/elliptic_curves/msm/msm_input_provider.h" #include "tachyon/device/gpu/scoped_mem_pool.h" #include "tachyon/device/gpu/scoped_stream.h" -#include "tachyon/math/elliptic_curves/affine_point.h" #include "tachyon/math/elliptic_curves/msm/variable_base_msm_gpu.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon::c::math { diff --git a/tachyon/c/zk/plonk/halo2/BUILD.bazel b/tachyon/c/zk/plonk/halo2/BUILD.bazel index 1379032f1..12d7741e9 100644 --- a/tachyon/c/zk/plonk/halo2/BUILD.bazel +++ b/tachyon/c/zk/plonk/halo2/BUILD.bazel @@ -180,10 +180,10 @@ tachyon_cc_library( "//tachyon/base/buffer:endian_auto_reset", "//tachyon/base/buffer:read_only_buffer", "//tachyon/base/containers:container_util", - "//tachyon/math/elliptic_curves:points", "//tachyon/math/finite_fields:cubic_extension_field", "//tachyon/math/finite_fields:prime_field_base", "//tachyon/math/finite_fields:quadratic_extension_field", + "//tachyon/math/geometry:affine_point", "//tachyon/math/polynomials/univariate:univariate_evaluations", "//tachyon/math/polynomials/univariate:univariate_polynomial", "//tachyon/zk/expressions:expression_factory", diff --git a/tachyon/c/zk/plonk/halo2/buffer_reader.h b/tachyon/c/zk/plonk/halo2/buffer_reader.h index b1768a12c..25ccc9eaf 100644 --- a/tachyon/c/zk/plonk/halo2/buffer_reader.h +++ b/tachyon/c/zk/plonk/halo2/buffer_reader.h @@ -15,10 +15,10 @@ #include "tachyon/base/logging.h" #include "tachyon/c/zk/plonk/halo2/bn254_gwc_pcs.h" #include "tachyon/c/zk/plonk/halo2/bn254_shplonk_pcs.h" -#include "tachyon/math/elliptic_curves/affine_point.h" #include "tachyon/math/finite_fields/cubic_extension_field.h" #include "tachyon/math/finite_fields/prime_field_base.h" #include "tachyon/math/finite_fields/quadratic_extension_field.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/math/polynomials/univariate/univariate_evaluations.h" #include "tachyon/math/polynomials/univariate/univariate_polynomial.h" #include "tachyon/zk/expressions/expression_factory.h" diff --git a/tachyon/crypto/commitments/fri/fri.h b/tachyon/crypto/commitments/fri/fri.h index 6524970ce..afd84abcd 100644 --- a/tachyon/crypto/commitments/fri/fri.h +++ b/tachyon/crypto/commitments/fri/fri.h @@ -69,7 +69,7 @@ class FRI final // Pᵢ₊₁(X) = Pᵢ_even(X²) + β * Pᵢ_odd(X²) beta = writer->SqueezeChallenge(); VLOG(2) << "FRI(beta[" << i - 1 << "]): " << beta.ToHexString(true); - folded_poly = cur_poly->template Fold(beta); + folded_poly = cur_poly->Fold(beta); BinaryMerkleTree tree(storage_->GetLayer(i), hasher_); evals = sub_domains_[i - 1]->FFT(folded_poly); @@ -82,7 +82,7 @@ class FRI final beta = writer->SqueezeChallenge(); VLOG(2) << "FRI(beta[" << num_layers - 1 << "]): " << beta.ToHexString(true); - folded_poly = cur_poly->template Fold(beta); + folded_poly = cur_poly->Fold(beta); return writer->WriteToProof(folded_poly[0]); } diff --git a/tachyon/crypto/commitments/kzg/kzg.h b/tachyon/crypto/commitments/kzg/kzg.h index 934f658f9..76abfe10a 100644 --- a/tachyon/crypto/commitments/kzg/kzg.h +++ b/tachyon/crypto/commitments/kzg/kzg.h @@ -19,7 +19,7 @@ #include "tachyon/base/logging.h" #include "tachyon/crypto/commitments/batch_commitment_state.h" #include "tachyon/math/elliptic_curves/msm/variable_base_msm.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/point_conversions.h" #include "tachyon/math/polynomials/univariate/univariate_evaluation_domain.h" #if TACHYON_CUDA diff --git a/tachyon/crypto/commitments/pedersen/pedersen.h b/tachyon/crypto/commitments/pedersen/pedersen.h index 17e41637f..ecfec9cd7 100644 --- a/tachyon/crypto/commitments/pedersen/pedersen.h +++ b/tachyon/crypto/commitments/pedersen/pedersen.h @@ -21,7 +21,7 @@ #include "tachyon/base/strings/string_util.h" #include "tachyon/crypto/commitments/vector_commitment_scheme.h" #include "tachyon/math/elliptic_curves/msm/variable_base_msm.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/point_conversions.h" #if TACHYON_CUDA #include "tachyon/device/gpu/scoped_mem_pool.h" diff --git a/tachyon/crypto/transcripts/BUILD.bazel b/tachyon/crypto/transcripts/BUILD.bazel index e117fc9e3..3f6c961f2 100644 --- a/tachyon/crypto/transcripts/BUILD.bazel +++ b/tachyon/crypto/transcripts/BUILD.bazel @@ -22,7 +22,7 @@ tachyon_cc_library( name = "transcript_traits", hdrs = ["transcript_traits.h"], deps = [ - "//tachyon/math/elliptic_curves:points", "//tachyon/math/finite_fields:prime_field_base", + "//tachyon/math/geometry:affine_point", ], ) diff --git a/tachyon/crypto/transcripts/transcript_traits.h b/tachyon/crypto/transcripts/transcript_traits.h index 5990fcb95..84eef73aa 100644 --- a/tachyon/crypto/transcripts/transcript_traits.h +++ b/tachyon/crypto/transcripts/transcript_traits.h @@ -3,8 +3,8 @@ #include -#include "tachyon/math/elliptic_curves/affine_point.h" #include "tachyon/math/finite_fields/prime_field_base.h" +#include "tachyon/math/geometry/affine_point.h" namespace tachyon::crypto { diff --git a/tachyon/math/base/semigroups.h b/tachyon/math/base/semigroups.h index 39c760267..430a90312 100644 --- a/tachyon/math/base/semigroups.h +++ b/tachyon/math/base/semigroups.h @@ -72,7 +72,7 @@ struct MultiplicativeSemigroupTraits { using ReturnTy = G; }; -template +template struct AdditiveSemigroupTraits { using ReturnTy = G; }; @@ -320,25 +320,25 @@ class AdditiveSemigroup { case 2: return Double(); case 3: - return Double() * g; + return Double() + g; case 4: return Double().Double(); case 5: { AddResult g4 = Double(); g4.DoubleInPlace(); - return g4 * g; + return g4 + g; } case 6: { AddResult g2 = Double(); AddResult g4 = g2; g4.DoubleInPlace(); - return g4 * g2; + return g4 + g2; } case 7: { AddResult g2 = Double(); AddResult g4 = g2; g4.DoubleInPlace(); - return g4 * g2 * g; + return g4 + g2 + g; } default: return DoScalarMul(BigInt<1>(scalar)); diff --git a/tachyon/math/circle/BUILD.bazel b/tachyon/math/circle/BUILD.bazel index e6f8b08db..68938d7aa 100644 --- a/tachyon/math/circle/BUILD.bazel +++ b/tachyon/math/circle/BUILD.bazel @@ -3,26 +3,25 @@ load("//bazel:tachyon_cc.bzl", "tachyon_cc_library", "tachyon_cc_unittest") package(default_visibility = ["//visibility:public"]) tachyon_cc_library( - name = "circle", - hdrs = ["circle.h"], - deps = [":circle_traits_forward"], -) - -tachyon_cc_library( - name = "circle_point", - hdrs = ["circle_point.h"], + name = "affine_point", + hdrs = ["affine_point.h"], deps = [ - ":circle_point_forward", "//tachyon/base:logging", "//tachyon/math/base:groups", + "//tachyon/math/geometry:curve_type", "//tachyon/math/geometry:point2", "@com_google_absl//absl/strings", ], ) tachyon_cc_library( - name = "circle_point_forward", - hdrs = ["circle_point_forward.h"], + name = "circle", + hdrs = ["circle.h"], + deps = [ + ":circle_traits_forward", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:curve_type", + ], ) tachyon_cc_library( @@ -32,9 +31,9 @@ tachyon_cc_library( tachyon_cc_unittest( name = "circle_unittests", - srcs = ["circle_point_unittest.cc"], + srcs = ["affine_point_unittest.cc"], deps = [ - "//tachyon/math/circle/stark:g1", - "//tachyon/math/circle/stark:g4", + "//tachyon/math/circle/m31:g1", + "//tachyon/math/circle/m31:g4", ], ) diff --git a/tachyon/math/circle/circle_point.h b/tachyon/math/circle/affine_point.h similarity index 50% rename from tachyon/math/circle/circle_point.h rename to tachyon/math/circle/affine_point.h index fb76e34d3..e6e714e41 100644 --- a/tachyon/math/circle/circle_point.h +++ b/tachyon/math/circle/affine_point.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a Apache-2.0 style license that // can be found in the LICENSE-APACHE.stwo -#ifndef TACHYON_MATH_CIRCLE_CIRCLE_POINT_H_ -#define TACHYON_MATH_CIRCLE_CIRCLE_POINT_H_ +#ifndef TACHYON_MATH_CIRCLE_AFFINE_POINT_H_ +#define TACHYON_MATH_CIRCLE_AFFINE_POINT_H_ #include #include @@ -12,61 +12,63 @@ #include "tachyon/base/logging.h" #include "tachyon/math/base/groups.h" -#include "tachyon/math/circle/circle_point_forward.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" #include "tachyon/math/geometry/point2.h" namespace tachyon::math { -// TODO(chokobole): Unify this into |AffinePoint|. -template -class CirclePoint : public AdditiveGroup> { +template +class AffinePoint<_Curve, std::enable_if_t<_Curve::kType == CurveType::kCircle>> + final : public AdditiveGroup> { public: - using Circle = _Circle; + using Curve = _Curve; + using Circle = _Curve; using BaseField = typename Circle::BaseField; using ScalarField = typename Circle::ScalarField; - constexpr CirclePoint() : CirclePoint(BaseField::One(), BaseField::Zero()) {} - explicit constexpr CirclePoint(const Point2& point) - : CirclePoint(point.x, point.y) {} - explicit constexpr CirclePoint(Point2&& point) - : CirclePoint(std::move(point.x), std::move(point.y)) {} - constexpr CirclePoint(const BaseField& x, const BaseField& y) + constexpr AffinePoint() : AffinePoint(BaseField::One(), BaseField::Zero()) {} + explicit constexpr AffinePoint(const Point2& point) + : AffinePoint(point.x, point.y) {} + explicit constexpr AffinePoint(Point2&& point) + : AffinePoint(std::move(point.x), std::move(point.y)) {} + constexpr AffinePoint(const BaseField& x, const BaseField& y) : x_(x), y_(y) {} - constexpr CirclePoint(BaseField&& x, BaseField&& y) + constexpr AffinePoint(BaseField&& x, BaseField&& y) : x_(std::move(x)), y_(std::move(y)) {} - constexpr static CirclePoint CreateChecked(const BaseField& x, + constexpr static AffinePoint CreateChecked(const BaseField& x, const BaseField& y) { - CirclePoint ret = {x, y}; + AffinePoint ret = {x, y}; CHECK(ret.IsOnCircle()); return ret; } - constexpr static CirclePoint CreateChecked(BaseField&& x, BaseField&& y) { - CirclePoint ret = {std::move(x), std::move(y)}; + constexpr static AffinePoint CreateChecked(BaseField&& x, BaseField&& y) { + AffinePoint ret = {std::move(x), std::move(y)}; CHECK(ret.IsOnCircle()); return ret; } - constexpr static CirclePoint Zero() { return CirclePoint(); } + constexpr static AffinePoint Zero() { return AffinePoint(); } - constexpr static CirclePoint One() { return Generator(); } + constexpr static AffinePoint One() { return Generator(); } - constexpr static CirclePoint Generator() { + constexpr static AffinePoint Generator() { return {Circle::Config::kGenerator.x, Circle::Config::kGenerator.y}; } - constexpr static CirclePoint Random() { + constexpr static AffinePoint Random() { return ScalarField::Random() * Generator(); } constexpr const BaseField& x() const { return x_; } constexpr const BaseField& y() const { return y_; } - constexpr bool operator==(const CirclePoint& other) const { + constexpr bool operator==(const AffinePoint& other) const { return x_ == other.x_ && y_ == other.y_; } - constexpr bool operator!=(const CirclePoint& other) const { + constexpr bool operator!=(const AffinePoint& other) const { return !operator==(other); } @@ -74,13 +76,13 @@ class CirclePoint : public AdditiveGroup> { constexpr bool IsOnCircle() { return Circle::IsOnCircle(*this); } - constexpr CirclePoint Conjugate() const { return {x_, -y_}; } + constexpr AffinePoint Conjugate() const { return {x_, -y_}; } - constexpr CirclePoint ComplexConjugate() const { + constexpr AffinePoint ComplexConjugate() const { return {x_.ComplexConjugate(), y_.ComplexConjugate()}; } - constexpr CirclePoint Antipode() const { return {-x_, -y_}; } + constexpr AffinePoint Antipode() const { return {-x_, -y_}; } std::string ToString() const { return absl::Substitute("($0, $1)", x_.ToString(), y_.ToString()); @@ -92,33 +94,43 @@ class CirclePoint : public AdditiveGroup> { } // AdditiveSemigroup methods - constexpr CirclePoint Add(const CirclePoint& other) const { + constexpr AffinePoint Add(const AffinePoint& other) const { return {x_ * other.x_ - y_ * other.y_, x_ * other.y_ + y_ * other.x_}; } - constexpr CirclePoint& AddInPlace(const CirclePoint& other) { + constexpr AffinePoint& AddInPlace(const AffinePoint& other) { return *this = {x_ * other.x_ - y_ * other.y_, x_ * other.y_ + y_ * other.x_}; } + constexpr AffinePoint DoubleImpl() const { + return {x_.Square().Double() - BaseField::One(), x_.Double() * y_}; + } + + constexpr AffinePoint& DoubleImplInPlace() { + y_ *= x_.Double(); + x_.SquareInPlace().DoubleInPlace() -= BaseField::One(); + return *this; + } + // AdditiveGroup methods - constexpr CirclePoint Sub(const CirclePoint& other) const { + constexpr AffinePoint Sub(const AffinePoint& other) const { return {x_ * other.x_ + y_ * other.y_, -x_ * other.y_ + y_ * other.x_}; } - constexpr CirclePoint& SubInPlace(const CirclePoint& other) { + constexpr AffinePoint& SubInPlace(const AffinePoint& other) { return *this = {x_ * other.x_ + y_ * other.y_, -x_ * other.y_ + y_ * other.x_}; } - constexpr CirclePoint Negate() const { return {x_, -y_}; } + constexpr AffinePoint Negate() const { return {x_, -y_}; } - constexpr CirclePoint& NegateInPlace() { + constexpr AffinePoint& NegateInPlace() { y_.NegateInPlace(); return *this; } - constexpr CirclePoint operator*(const ScalarField& idx) const { + constexpr AffinePoint operator*(const ScalarField& idx) const { return this->ScalarMul(idx.value()); } @@ -129,4 +141,4 @@ class CirclePoint : public AdditiveGroup> { } // namespace tachyon::math -#endif // TACHYON_MATH_CIRCLE_CIRCLE_POINT_H_ +#endif // TACHYON_MATH_CIRCLE_AFFINE_POINT_H_ diff --git a/tachyon/math/circle/affine_point_unittest.cc b/tachyon/math/circle/affine_point_unittest.cc new file mode 100644 index 000000000..0404a9496 --- /dev/null +++ b/tachyon/math/circle/affine_point_unittest.cc @@ -0,0 +1,100 @@ +#include "gtest/gtest.h" + +#include "tachyon/math/circle/m31/g1.h" +#include "tachyon/math/circle/m31/g4.h" + +namespace tachyon::math { + +template +class AffinePointTest : public testing::Test { + public: + static void SetUpTestSuite() { AffinePointType::Circle::Init(); } +}; + +using AffinePointTypes = testing::Types; +TYPED_TEST_SUITE(AffinePointTest, AffinePointTypes); + +TYPED_TEST(AffinePointTest, IsZero) { + using AffinePoint = TypeParam; + using BaseField = typename AffinePoint::BaseField; + + EXPECT_TRUE(AffinePoint::Zero().IsZero()); + EXPECT_FALSE(AffinePoint(BaseField::Zero(), BaseField::One()).IsZero()); +} + +TYPED_TEST(AffinePointTest, Generator) { + using AffinePoint = TypeParam; + using Circle = typename AffinePoint::Circle; + + EXPECT_EQ( + AffinePoint::Generator(), + AffinePoint(Circle::Config::kGenerator.x, Circle::Config::kGenerator.y)); +} + +TYPED_TEST(AffinePointTest, Order) { + using AffinePoint = TypeParam; + + AffinePoint r = AffinePoint::Random(); + EXPECT_TRUE(r.ScalarMul(AffinePoint::ScalarField::Config::kModulus).IsZero()); +} + +TYPED_TEST(AffinePointTest, Random) { + using AffinePoint = TypeParam; + + bool success = false; + AffinePoint r = AffinePoint::Random(); + for (size_t i = 0; i < 100; ++i) { + if (r != AffinePoint::Random()) { + success = true; + break; + } + } + EXPECT_TRUE(success); + EXPECT_TRUE(r.IsOnCircle()); +} + +TYPED_TEST(AffinePointTest, EqualityOperators) { + using AffinePoint = TypeParam; + using BaseField = typename AffinePoint::BaseField; + + AffinePoint p(BaseField::Random(), BaseField::Random()); + AffinePoint p2(BaseField::Random(), BaseField::Random()); + EXPECT_EQ(p, p); + EXPECT_NE(p, p2); +} + +TYPED_TEST(AffinePointTest, Conjugate) { + using AffinePoint = TypeParam; + + AffinePoint p = AffinePoint::Random(); + EXPECT_EQ(p.Conjugate(), AffinePoint(p.x(), -p.y())); +} + +TYPED_TEST(AffinePointTest, Antipode) { + using AffinePoint = TypeParam; + + AffinePoint p = AffinePoint::Random(); + EXPECT_EQ(p.Antipode(), AffinePoint(-p.x(), -p.y())); +} + +TYPED_TEST(AffinePointTest, AdditiveGroupOperators) { + using AffinePoint = TypeParam; + + AffinePoint a = AffinePoint::Random(); + AffinePoint b = AffinePoint::Random(); + AffinePoint c = a + b; + + EXPECT_EQ(c - a, b); + EXPECT_EQ(c - b, a); + AffinePoint doubled = a.Double(); + EXPECT_EQ(doubled, a + a); + AffinePoint a_tmp = a; + EXPECT_EQ(a_tmp.DoubleInPlace(), doubled); + + EXPECT_EQ(a + AffinePoint::Zero(), a); + a_tmp = a; + a_tmp.NegateInPlace(); + EXPECT_EQ(a_tmp, -a); +} + +} // namespace tachyon::math diff --git a/tachyon/math/circle/circle.h b/tachyon/math/circle/circle.h index 65d166595..0d0190083 100644 --- a/tachyon/math/circle/circle.h +++ b/tachyon/math/circle/circle.h @@ -1,8 +1,9 @@ #ifndef TACHYON_MATH_CIRCLE_CIRCLE_H_ #define TACHYON_MATH_CIRCLE_CIRCLE_H_ -#include "tachyon/math/circle/circle_point.h" #include "tachyon/math/circle/circle_traits_forward.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" namespace tachyon::math { @@ -15,7 +16,9 @@ class Circle { using BaseField = typename Config::BaseField; using ScalarField = typename Config::ScalarField; - using Point = typename CircleTraits::PointTy; + using AffinePoint = typename CircleTraits::AffinePointTy; + + constexpr static CurveType kType = CurveType::kCircle; static void Init() { BaseField::Init(); @@ -24,7 +27,7 @@ class Circle { Config::Init(); } - constexpr static bool IsOnCircle(const Point& point) { + constexpr static bool IsOnCircle(const AffinePoint& point) { return (point.x().Square() + point.y().Square()).IsOne(); } }; @@ -33,7 +36,7 @@ template struct CircleTraits { using BaseField = typename Config::BaseField; using ScalarField = typename Config::ScalarField; - using PointTy = CirclePoint>; + using AffinePointTy = AffinePoint>; }; } // namespace tachyon::math diff --git a/tachyon/math/circle/circle_point_forward.h b/tachyon/math/circle/circle_point_forward.h deleted file mode 100644 index 7f654da34..000000000 --- a/tachyon/math/circle/circle_point_forward.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2024 StarkWare Industries Ltd -// Use of this source code is governed by a Apache-2.0 style license that -// can be found in the LICENSE-APACHE.stwo - -#ifndef TACHYON_MATH_CIRCLE_CIRCLE_POINT_FORWARD_H_ -#define TACHYON_MATH_CIRCLE_CIRCLE_POINT_FORWARD_H_ - -namespace tachyon::math { - -template -class CirclePoint; - -template -CirclePoint operator*(const ScalarField& v, - const CirclePoint& point) { - return point * v; -} - -} // namespace tachyon::math - -#endif // TACHYON_MATH_CIRCLE_CIRCLE_POINT_FORWARD_H_ diff --git a/tachyon/math/circle/circle_point_unittest.cc b/tachyon/math/circle/circle_point_unittest.cc deleted file mode 100644 index 558689523..000000000 --- a/tachyon/math/circle/circle_point_unittest.cc +++ /dev/null @@ -1,98 +0,0 @@ -#include "gtest/gtest.h" - -#include "tachyon/math/circle/stark/g1.h" -#include "tachyon/math/circle/stark/g4.h" - -namespace tachyon::math { - -template -class CirclePointTest : public testing::Test { - public: - static void SetUpTestSuite() { CirclePointType::Circle::Init(); } -}; - -using CirclePointTypes = - testing::Types; -TYPED_TEST_SUITE(CirclePointTest, CirclePointTypes); - -TYPED_TEST(CirclePointTest, IsZero) { - using CirclePoint = TypeParam; - using BaseField = typename CirclePoint::BaseField; - - EXPECT_TRUE(CirclePoint::Zero().IsZero()); - EXPECT_FALSE(CirclePoint(BaseField::Zero(), BaseField::One()).IsZero()); -} - -TYPED_TEST(CirclePointTest, Generator) { - using CirclePoint = TypeParam; - using Circle = typename CirclePoint::Circle; - - EXPECT_EQ( - CirclePoint::Generator(), - CirclePoint(Circle::Config::kGenerator.x, Circle::Config::kGenerator.y)); -} - -TYPED_TEST(CirclePointTest, Order) { - using CirclePoint = TypeParam; - - CirclePoint r = CirclePoint::Random(); - EXPECT_TRUE(r.ScalarMul(CirclePoint::ScalarField::Config::kModulus).IsZero()); -} - -TYPED_TEST(CirclePointTest, Random) { - using CirclePoint = TypeParam; - - bool success = false; - CirclePoint r = CirclePoint::Random(); - for (size_t i = 0; i < 100; ++i) { - if (r != CirclePoint::Random()) { - success = true; - break; - } - } - EXPECT_TRUE(success); - EXPECT_TRUE(r.IsOnCircle()); -} - -TYPED_TEST(CirclePointTest, EqualityOperators) { - using CirclePoint = TypeParam; - using BaseField = typename CirclePoint::BaseField; - - CirclePoint p(BaseField::Random(), BaseField::Random()); - CirclePoint p2(BaseField::Random(), BaseField::Random()); - EXPECT_EQ(p, p); - EXPECT_NE(p, p2); -} - -TYPED_TEST(CirclePointTest, Conjugate) { - using CirclePoint = TypeParam; - - CirclePoint p = CirclePoint::Random(); - EXPECT_EQ(p.Conjugate(), CirclePoint(p.x(), -p.y())); -} - -TYPED_TEST(CirclePointTest, Antipode) { - using CirclePoint = TypeParam; - - CirclePoint p = CirclePoint::Random(); - EXPECT_EQ(p.Antipode(), CirclePoint(-p.x(), -p.y())); -} - -TYPED_TEST(CirclePointTest, AdditiveGroupOperators) { - using CirclePoint = TypeParam; - - CirclePoint a = CirclePoint::Random(); - CirclePoint b = CirclePoint::Random(); - CirclePoint c = a + b; - - EXPECT_EQ(c - a, b); - EXPECT_EQ(c - b, a); - EXPECT_EQ(a.Double(), a + a); - - EXPECT_EQ(a + CirclePoint::Zero(), a); - CirclePoint a_tmp = a; - a_tmp.NegateInPlace(); - EXPECT_EQ(a_tmp, -a); -} - -} // namespace tachyon::math diff --git a/tachyon/math/circle/generator/build_defs.bzl b/tachyon/math/circle/generator/build_defs.bzl index 15dc967a2..d7dd75af3 100644 --- a/tachyon/math/circle/generator/build_defs.bzl +++ b/tachyon/math/circle/generator/build_defs.bzl @@ -96,8 +96,8 @@ def generate_circle_points( deps = [ base_field_dep, scalar_field_dep, + "//tachyon/math/circle:affine_point", "//tachyon/math/circle:circle", - "//tachyon/math/circle:circle_point", ], **kwargs ) diff --git a/tachyon/math/circle/generator/cpu.h.tpl b/tachyon/math/circle/generator/cpu.h.tpl index 38aa66bbc..32d9f7ab8 100644 --- a/tachyon/math/circle/generator/cpu.h.tpl +++ b/tachyon/math/circle/generator/cpu.h.tpl @@ -1,7 +1,7 @@ // clang-format off #include "tachyon/base/logging.h" +#include "tachyon/math/circle/affine_point.h" #include "tachyon/math/circle/circle.h" -#include "tachyon/math/circle/circle_point.h" #include "tachyon/math/geometry/point2.h" #include "%{base_field_hdr}" #include "%{scalar_field_hdr}" @@ -29,7 +29,7 @@ template Point2 %{class}CircleConfig::kGenerator; using %{class}Circle = tachyon::math::Circle<%{class}CircleConfig<%{base_field}, %{scalar_field}>>; -using %{class}CirclePoint = tachyon::math::CirclePoint<%{class}Circle>; +using %{class}AffinePoint = tachyon::math::AffinePoint<%{class}Circle>; } // namespace %{namespace} // clang-format on diff --git a/tachyon/math/circle/stark/BUILD.bazel b/tachyon/math/circle/m31/BUILD.bazel similarity index 81% rename from tachyon/math/circle/stark/BUILD.bazel rename to tachyon/math/circle/m31/BUILD.bazel index 49bdc62e5..8c4dd009f 100644 --- a/tachyon/math/circle/stark/BUILD.bazel +++ b/tachyon/math/circle/m31/BUILD.bazel @@ -15,10 +15,10 @@ generate_circle_points( base_field_dep = "//tachyon/math/finite_fields/mersenne31", base_field_hdr = "tachyon/math/finite_fields/mersenne31/mersenne31.h", class_name = "G1", - namespace = "tachyon::math::stark", + namespace = "tachyon::math::m31", scalar_field = "Fr", scalar_field_dep = ":fr", - scalar_field_hdr = "tachyon/math/circle/stark/fr.h", + scalar_field_hdr = "tachyon/math/circle/m31/fr.h", x = ["2"], y = ["1268011823"], ) @@ -29,7 +29,7 @@ generate_prime_fields( # 2³¹ # Hex: 0x80000000 modulus = "2147483648", - namespace = "tachyon::math::stark", + namespace = "tachyon::math::m31", reduce32 = "return v & (kModulus - 1);", reduce64 = "return v & (kModulus - 1);", use_montgomery = False, @@ -41,7 +41,7 @@ generate_fp2s( base_field_hdr = "tachyon/math/finite_fields/mersenne31/mersenne31.h", class_name = "Fq2", is_packed = False, - namespace = "tachyon::math::stark", + namespace = "tachyon::math::m31", non_residue = ["-1"], deps = ["//tachyon/math/finite_fields/mersenne31"], ) @@ -50,10 +50,10 @@ generate_fp4s( name = "fq4", base_field = "Fq2", base_field_degree = 2, - base_field_hdr = "tachyon/math/circle/stark/fq2.h", + base_field_hdr = "tachyon/math/circle/m31/fq2.h", class_name = "Fq4", is_packed = False, - namespace = "tachyon::math::stark", + namespace = "tachyon::math::m31", non_residue = [ "2", "1", @@ -67,7 +67,7 @@ generate_prime_fields( # (2³¹ - 1)⁴ - 1 # Hex: 0xfffffff800000017ffffffe00000000 modulus = "21267647892944572736998860269687930880", - namespace = "tachyon::math::stark", + namespace = "tachyon::math::m31", use_asm = False, ) @@ -76,12 +76,12 @@ generate_circle_points( base_field = "Fq4", base_field_degree = 4, base_field_dep = ":fq4", - base_field_hdr = "tachyon/math/circle/stark/fq4.h", + base_field_hdr = "tachyon/math/circle/m31/fq4.h", class_name = "G4", - namespace = "tachyon::math::stark", + namespace = "tachyon::math::m31", scalar_field = "Fr4", scalar_field_dep = ":fr4", - scalar_field_hdr = "tachyon/math/circle/stark/fr4.h", + scalar_field_hdr = "tachyon/math/circle/m31/fr4.h", x = [ "1", "0", diff --git a/tachyon/math/elliptic_curves/BUILD.bazel b/tachyon/math/elliptic_curves/BUILD.bazel index 784590acd..a37960be0 100644 --- a/tachyon/math/elliptic_curves/BUILD.bazel +++ b/tachyon/math/elliptic_curves/BUILD.bazel @@ -3,22 +3,12 @@ load("//bazel:tachyon_cc.bzl", "tachyon_cc_library") package(default_visibility = ["//visibility:public"]) tachyon_cc_library( - name = "points", - hdrs = [ - "affine_point.h", - "curve_type.h", - "jacobian_point.h", - "point_conversions.h", - "point_conversions_forward.h", - "point_xyzz.h", - "projective_point.h", - "semigroups.h", - ], + name = "semigroups", + hdrs = ["semigroups.h"], deps = [ - "//tachyon/base:template_util", - "//tachyon/base/containers:container_util", - "//tachyon/math/geometry:point2", - "//tachyon/math/geometry:point3", - "//tachyon/math/geometry:point4", + "//tachyon/math/base:semigroups", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:curve_type", + "//tachyon/math/geometry:jacobian_point", ], ) diff --git a/tachyon/math/elliptic_curves/curve_type.h b/tachyon/math/elliptic_curves/curve_type.h deleted file mode 100644 index ef719e058..000000000 --- a/tachyon/math/elliptic_curves/curve_type.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_CURVE_TYPE_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_CURVE_TYPE_H_ - -namespace tachyon::math { - -enum class CurveType { - kShortWeierstrass, - kTwistedEdwards, -}; - -} // namespace tachyon::math - -#endif // TACHYON_MATH_ELLIPTIC_CURVES_CURVE_TYPE_H_ diff --git a/tachyon/math/elliptic_curves/msm/BUILD.bazel b/tachyon/math/elliptic_curves/msm/BUILD.bazel index 218779a40..05ce60208 100644 --- a/tachyon/math/elliptic_curves/msm/BUILD.bazel +++ b/tachyon/math/elliptic_curves/msm/BUILD.bazel @@ -12,7 +12,7 @@ tachyon_cc_library( "//tachyon/base/containers:container_util", "//tachyon/math/base:bit_iterator", "//tachyon/math/base:semigroups", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:point_conversions", ], ) @@ -23,7 +23,7 @@ tachyon_cc_library( "//tachyon/math/base:bit_iterator", "//tachyon/math/base/gmp:bit_traits", "//tachyon/math/base/gmp:signed_value", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/elliptic_curves:semigroups", "//tachyon/math/matrix:gmp_num_traits", ], ) diff --git a/tachyon/math/elliptic_curves/msm/algorithms/icicle/BUILD.bazel b/tachyon/math/elliptic_curves/msm/algorithms/icicle/BUILD.bazel index 0a784c362..727818232 100644 --- a/tachyon/math/elliptic_curves/msm/algorithms/icicle/BUILD.bazel +++ b/tachyon/math/elliptic_curves/msm/algorithms/icicle/BUILD.bazel @@ -31,8 +31,8 @@ tachyon_cc_library( "//tachyon/base:bit_cast", "//tachyon/device/gpu:gpu_device_functions", "//tachyon/device/gpu:gpu_enums", - "//tachyon/math/elliptic_curves:points", "//tachyon/math/elliptic_curves/bn/bn254:g1", "//tachyon/math/elliptic_curves/bn/bn254:g2", + "//tachyon/math/geometry:jacobian_point", ], ) diff --git a/tachyon/math/elliptic_curves/msm/algorithms/icicle/icicle_msm.h b/tachyon/math/elliptic_curves/msm/algorithms/icicle/icicle_msm.h index 1969d7a01..4ae6de232 100644 --- a/tachyon/math/elliptic_curves/msm/algorithms/icicle/icicle_msm.h +++ b/tachyon/math/elliptic_curves/msm/algorithms/icicle/icicle_msm.h @@ -13,7 +13,7 @@ #include "tachyon/math/elliptic_curves/bn/bn254/g2.h" #include "tachyon/math/elliptic_curves/msm/algorithms/icicle/icicle_msm_bn254_g1.h" #include "tachyon/math/elliptic_curves/msm/algorithms/icicle/icicle_msm_bn254_g2.h" -#include "tachyon/math/elliptic_curves/projective_point.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/msm/algorithms/pippenger/BUILD.bazel b/tachyon/math/elliptic_curves/msm/algorithms/pippenger/BUILD.bazel index 71bee0164..581ffe4bd 100644 --- a/tachyon/math/elliptic_curves/msm/algorithms/pippenger/BUILD.bazel +++ b/tachyon/math/elliptic_curves/msm/algorithms/pippenger/BUILD.bazel @@ -13,6 +13,7 @@ tachyon_cc_library( deps = [ ":pippenger_base", "//tachyon/base:openmp_util", + "//tachyon/math/elliptic_curves:semigroups", "//tachyon/math/elliptic_curves/msm:msm_ctx", "//tachyon/math/elliptic_curves/msm:msm_util", ], @@ -30,7 +31,8 @@ tachyon_cc_library( deps = [ "//tachyon/base/containers:adapters", "//tachyon/math/base:semigroups", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:point_xyzz", "@com_google_absl//absl/types:span", ], ) diff --git a/tachyon/math/elliptic_curves/msm/algorithms/pippenger/pippenger_base.h b/tachyon/math/elliptic_curves/msm/algorithms/pippenger/pippenger_base.h index 2c3f034a6..8d4b2d1f3 100644 --- a/tachyon/math/elliptic_curves/msm/algorithms/pippenger/pippenger_base.h +++ b/tachyon/math/elliptic_curves/msm/algorithms/pippenger/pippenger_base.h @@ -10,8 +10,8 @@ #include "tachyon/base/containers/adapters.h" #include "tachyon/math/base/semigroups.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/point_xyzz.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/msm/fixed_base_msm.h b/tachyon/math/elliptic_curves/msm/fixed_base_msm.h index ce3110759..2c09ec096 100644 --- a/tachyon/math/elliptic_curves/msm/fixed_base_msm.h +++ b/tachyon/math/elliptic_curves/msm/fixed_base_msm.h @@ -15,7 +15,7 @@ #include "tachyon/math/base/bit_iterator.h" #include "tachyon/math/base/semigroups.h" #include "tachyon/math/elliptic_curves/msm/msm_ctx.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/msm/glv.h b/tachyon/math/elliptic_curves/msm/glv.h index efa3a78e9..a9925d20d 100644 --- a/tachyon/math/elliptic_curves/msm/glv.h +++ b/tachyon/math/elliptic_curves/msm/glv.h @@ -9,10 +9,6 @@ #include "tachyon/math/base/bit_iterator.h" #include "tachyon/math/base/gmp/bit_traits.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" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" #include "tachyon/math/elliptic_curves/semigroups.h" #include "tachyon/math/matrix/gmp_num_traits.h" diff --git a/tachyon/math/elliptic_curves/msm/glv_unittest.cc b/tachyon/math/elliptic_curves/msm/glv_unittest.cc index 8800adc13..4c6a240ea 100644 --- a/tachyon/math/elliptic_curves/msm/glv_unittest.cc +++ b/tachyon/math/elliptic_curves/msm/glv_unittest.cc @@ -6,7 +6,7 @@ #include "tachyon/math/elliptic_curves/bls12/bls12_381/g2.h" #include "tachyon/math/elliptic_curves/bn/bn254/g1.h" #include "tachyon/math/elliptic_curves/bn/bn254/g2.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/msm/test/fixed_base_msm_test_set.h b/tachyon/math/elliptic_curves/msm/test/fixed_base_msm_test_set.h index f29b5675a..00d4f5195 100644 --- a/tachyon/math/elliptic_curves/msm/test/fixed_base_msm_test_set.h +++ b/tachyon/math/elliptic_curves/msm/test/fixed_base_msm_test_set.h @@ -8,8 +8,8 @@ #include "tachyon/base/logging.h" #include "tachyon/math/base/semigroups.h" #include "tachyon/math/elliptic_curves/msm/fixed_base_msm.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" #include "tachyon/math/elliptic_curves/test/random.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/msm/test/variable_base_msm_test_set.h b/tachyon/math/elliptic_curves/msm/test/variable_base_msm_test_set.h index 56a0fe6d0..1483b09f5 100644 --- a/tachyon/math/elliptic_curves/msm/test/variable_base_msm_test_set.h +++ b/tachyon/math/elliptic_curves/msm/test/variable_base_msm_test_set.h @@ -8,8 +8,8 @@ #include "tachyon/base/logging.h" #include "tachyon/math/base/semigroups.h" #include "tachyon/math/elliptic_curves/msm/variable_base_msm.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" #include "tachyon/math/elliptic_curves/test/random.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/point_conversions_forward.h b/tachyon/math/elliptic_curves/point_conversions_forward.h deleted file mode 100644 index 9b1a1c462..000000000 --- a/tachyon/math/elliptic_curves/point_conversions_forward.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_POINT_CONVERSIONS_FORWARD_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_POINT_CONVERSIONS_FORWARD_H_ - -namespace tachyon::math { - -template -struct PointConversions; - -} // namespace tachyon::math - -#endif // TACHYON_MATH_ELLIPTIC_CURVES_POINT_CONVERSIONS_FORWARD_H_ diff --git a/tachyon/math/elliptic_curves/semigroups.h b/tachyon/math/elliptic_curves/semigroups.h index ea8fe7aa4..3a3196443 100644 --- a/tachyon/math/elliptic_curves/semigroups.h +++ b/tachyon/math/elliptic_curves/semigroups.h @@ -2,13 +2,16 @@ #define TACHYON_MATH_ELLIPTIC_CURVES_SEMIGROUPS_H_ #include "tachyon/math/base/semigroups.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/jacobian_point.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" +#include "tachyon/math/geometry/jacobian_point.h" namespace tachyon::math::internal { template -struct AdditiveSemigroupTraits> { +struct AdditiveSemigroupTraits< + AffinePoint, + std::enable_if_t> { using ReturnTy = JacobianPoint; }; diff --git a/tachyon/math/elliptic_curves/short_weierstrass/BUILD.bazel b/tachyon/math/elliptic_curves/short_weierstrass/BUILD.bazel index 6da4d6cd4..7320a8931 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/BUILD.bazel +++ b/tachyon/math/elliptic_curves/short_weierstrass/BUILD.bazel @@ -26,10 +26,15 @@ tachyon_cc_library( "//tachyon/base/containers:container_util", "//tachyon/base/json", "//tachyon/math/base:groups", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/elliptic_curves:semigroups", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:curve_type", + "//tachyon/math/geometry:jacobian_point", "//tachyon/math/geometry:point2", "//tachyon/math/geometry:point3", "//tachyon/math/geometry:point4", + "//tachyon/math/geometry:point_xyzz", + "//tachyon/math/geometry:projective_point", ], ) @@ -38,7 +43,11 @@ tachyon_cc_library( srcs = ["sw_curve.h"], deps = [ ":sw_curve_traits_forward", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:curve_type", + "//tachyon/math/geometry:jacobian_point", + "//tachyon/math/geometry:point_conversions", + "//tachyon/math/geometry:projective_point", ], ) diff --git a/tachyon/math/elliptic_curves/short_weierstrass/affine_point.h b/tachyon/math/elliptic_curves/short_weierstrass/affine_point.h index be2fe803c..4a9eec0c4 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/affine_point.h +++ b/tachyon/math/elliptic_curves/short_weierstrass/affine_point.h @@ -14,13 +14,13 @@ #include "tachyon/base/logging.h" #include "tachyon/base/parallelize.h" #include "tachyon/math/base/groups.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/curve_type.h" -#include "tachyon/math/elliptic_curves/jacobian_point.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" #include "tachyon/math/elliptic_curves/semigroups.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" +#include "tachyon/math/geometry/jacobian_point.h" #include "tachyon/math/geometry/point2.h" +#include "tachyon/math/geometry/point_xyzz.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon { namespace math { diff --git a/tachyon/math/elliptic_curves/short_weierstrass/affine_point_correctness_gpu_test.cc b/tachyon/math/elliptic_curves/short_weierstrass/affine_point_correctness_gpu_test.cc index 3880f84df..3475e54d6 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/affine_point_correctness_gpu_test.cc +++ b/tachyon/math/elliptic_curves/short_weierstrass/affine_point_correctness_gpu_test.cc @@ -3,8 +3,8 @@ #include "tachyon/device/gpu/gpu_memory.h" #include "tachyon/math/elliptic_curves/bn/bn254/g1_gpu.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" #include "tachyon/math/elliptic_curves/short_weierstrass/kernels/elliptic_curve_ops.cu.h" +#include "tachyon/math/geometry/point_conversions.h" #include "tachyon/math/test/launch_op_macros.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/short_weierstrass/jacobian_point.h b/tachyon/math/elliptic_curves/short_weierstrass/jacobian_point.h index fc6894f0d..5e1099fff 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/jacobian_point.h +++ b/tachyon/math/elliptic_curves/short_weierstrass/jacobian_point.h @@ -14,12 +14,12 @@ #include "tachyon/base/json/json.h" #include "tachyon/base/logging.h" #include "tachyon/math/base/groups.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/curve_type.h" -#include "tachyon/math/elliptic_curves/jacobian_point.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" +#include "tachyon/math/geometry/jacobian_point.h" #include "tachyon/math/geometry/point3.h" +#include "tachyon/math/geometry/point_xyzz.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon { namespace math { diff --git a/tachyon/math/elliptic_curves/short_weierstrass/non_affine_point_correctness_gpu_test.cc b/tachyon/math/elliptic_curves/short_weierstrass/non_affine_point_correctness_gpu_test.cc index de374b527..53d162d98 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/non_affine_point_correctness_gpu_test.cc +++ b/tachyon/math/elliptic_curves/short_weierstrass/non_affine_point_correctness_gpu_test.cc @@ -3,8 +3,8 @@ #include "tachyon/device/gpu/gpu_memory.h" #include "tachyon/math/elliptic_curves/bn/bn254/g1_gpu.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" #include "tachyon/math/elliptic_curves/short_weierstrass/kernels/elliptic_curve_ops.cu.h" +#include "tachyon/math/geometry/point_conversions.h" #include "tachyon/math/test/launch_op_macros.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/short_weierstrass/point_xyzz.h b/tachyon/math/elliptic_curves/short_weierstrass/point_xyzz.h index 67bc583a3..0b9de58f4 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/point_xyzz.h +++ b/tachyon/math/elliptic_curves/short_weierstrass/point_xyzz.h @@ -13,11 +13,12 @@ #include "tachyon/base/json/json.h" #include "tachyon/base/logging.h" #include "tachyon/math/base/groups.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/curve_type.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" +#include "tachyon/math/geometry/jacobian_point.h" #include "tachyon/math/geometry/point4.h" +#include "tachyon/math/geometry/point_xyzz.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon { namespace math { diff --git a/tachyon/math/elliptic_curves/short_weierstrass/projective_point.h b/tachyon/math/elliptic_curves/short_weierstrass/projective_point.h index 7bf5f5acb..dba9e37ea 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/projective_point.h +++ b/tachyon/math/elliptic_curves/short_weierstrass/projective_point.h @@ -11,12 +11,12 @@ #include "tachyon/base/containers/container_util.h" #include "tachyon/base/logging.h" #include "tachyon/math/base/groups.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/curve_type.h" -#include "tachyon/math/elliptic_curves/jacobian_point.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" +#include "tachyon/math/geometry/jacobian_point.h" #include "tachyon/math/geometry/point3.h" +#include "tachyon/math/geometry/point_xyzz.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon { namespace math { diff --git a/tachyon/math/elliptic_curves/short_weierstrass/sw_curve.h b/tachyon/math/elliptic_curves/short_weierstrass/sw_curve.h index cb60d9358..f413d42a0 100644 --- a/tachyon/math/elliptic_curves/short_weierstrass/sw_curve.h +++ b/tachyon/math/elliptic_curves/short_weierstrass/sw_curve.h @@ -3,13 +3,13 @@ #include -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/curve_type.h" -#include "tachyon/math/elliptic_curves/jacobian_point.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" #include "tachyon/math/elliptic_curves/short_weierstrass/sw_curve_traits_forward.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/curve_type.h" +#include "tachyon/math/geometry/jacobian_point.h" +#include "tachyon/math/geometry/point_conversions.h" +#include "tachyon/math/geometry/point_xyzz.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon::math { diff --git a/tachyon/math/elliptic_curves/test/BUILD.bazel b/tachyon/math/elliptic_curves/test/BUILD.bazel index 424a7ddee..4f2f76faf 100644 --- a/tachyon/math/elliptic_curves/test/BUILD.bazel +++ b/tachyon/math/elliptic_curves/test/BUILD.bazel @@ -8,6 +8,6 @@ tachyon_cc_library( hdrs = ["random.h"], deps = [ "//tachyon/base:parallelize", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:point_conversions", ], ) diff --git a/tachyon/math/elliptic_curves/test/random.h b/tachyon/math/elliptic_curves/test/random.h index 057b3d65d..82c7bcf01 100644 --- a/tachyon/math/elliptic_curves/test/random.h +++ b/tachyon/math/elliptic_curves/test/random.h @@ -4,7 +4,7 @@ #include #include "tachyon/base/parallelize.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/point_conversions.h" namespace tachyon::math { diff --git a/tachyon/math/geometry/BUILD.bazel b/tachyon/math/geometry/BUILD.bazel index 923a08551..4c2342c9c 100644 --- a/tachyon/math/geometry/BUILD.bazel +++ b/tachyon/math/geometry/BUILD.bazel @@ -2,6 +2,17 @@ load("//bazel:tachyon_cc.bzl", "tachyon_cc_library", "tachyon_cc_unittest") package(default_visibility = ["//visibility:public"]) +tachyon_cc_library( + name = "affine_point", + hdrs = ["affine_point.h"], + deps = [":point_conversions_forward"], +) + +tachyon_cc_library( + name = "curve_type", + hdrs = ["curve_type.h"], +) + tachyon_cc_library( name = "dimensions", hdrs = ["dimensions.h"], @@ -13,6 +24,15 @@ tachyon_cc_library( ], ) +tachyon_cc_library( + name = "jacobian_point", + hdrs = ["jacobian_point.h"], + deps = [ + ":point3", + ":point_conversions_forward", + ], +) + tachyon_cc_library( name = "point2", hdrs = ["point2.h"], @@ -43,6 +63,42 @@ tachyon_cc_library( ], ) +tachyon_cc_library( + name = "point_conversions_forward", + hdrs = ["point_conversions_forward.h"], +) + +tachyon_cc_library( + name = "point_conversions", + hdrs = ["point_conversions.h"], + deps = [ + ":affine_point", + ":jacobian_point", + ":point_conversions_forward", + ":point_xyzz", + ":projective_point", + "//tachyon/base:template_util", + ], +) + +tachyon_cc_library( + name = "point_xyzz", + hdrs = ["point_xyzz.h"], + deps = [ + ":point4", + ":point_conversions_forward", + ], +) + +tachyon_cc_library( + name = "projective_point", + hdrs = ["projective_point.h"], + deps = [ + ":point3", + ":point_conversions_forward", + ], +) + tachyon_cc_unittest( name = "geometry_unittests", srcs = [ diff --git a/tachyon/math/elliptic_curves/affine_point.h b/tachyon/math/geometry/affine_point.h similarity index 70% rename from tachyon/math/elliptic_curves/affine_point.h rename to tachyon/math/geometry/affine_point.h index e215bf360..c65788aeb 100644 --- a/tachyon/math/elliptic_curves/affine_point.h +++ b/tachyon/math/geometry/affine_point.h @@ -1,10 +1,9 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_AFFINE_POINT_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_AFFINE_POINT_H_ +#ifndef TACHYON_MATH_GEOMETRY_AFFINE_POINT_H_ +#define TACHYON_MATH_GEOMETRY_AFFINE_POINT_H_ #include -#include "tachyon/math/elliptic_curves/jacobian_point.h" -#include "tachyon/math/elliptic_curves/point_conversions_forward.h" +#include "tachyon/math/geometry/point_conversions_forward.h" namespace tachyon::math { @@ -14,8 +13,7 @@ class AffinePoint; template >* = nullptr> -JacobianPoint operator*(const ScalarField& v, - const AffinePoint& point) { +auto operator*(const ScalarField& v, const AffinePoint& point) { return point * v; } @@ -39,4 +37,4 @@ struct PointConversions, AffinePoint, } // namespace tachyon::math -#endif // TACHYON_MATH_ELLIPTIC_CURVES_AFFINE_POINT_H_ +#endif // TACHYON_MATH_GEOMETRY_AFFINE_POINT_H_ diff --git a/tachyon/math/geometry/curve_type.h b/tachyon/math/geometry/curve_type.h new file mode 100644 index 000000000..fe07e026f --- /dev/null +++ b/tachyon/math/geometry/curve_type.h @@ -0,0 +1,14 @@ +#ifndef TACHYON_MATH_GEOMETRY_CURVE_TYPE_H_ +#define TACHYON_MATH_GEOMETRY_CURVE_TYPE_H_ + +namespace tachyon::math { + +enum class CurveType { + kCircle, + kShortWeierstrass, + kTwistedEdwards, +}; + +} // namespace tachyon::math + +#endif // TACHYON_MATH_GEOMETRY_CURVE_TYPE_H_ diff --git a/tachyon/math/elliptic_curves/jacobian_point.h b/tachyon/math/geometry/jacobian_point.h similarity index 83% rename from tachyon/math/elliptic_curves/jacobian_point.h rename to tachyon/math/geometry/jacobian_point.h index fd9dc0ff4..917fcc0b3 100644 --- a/tachyon/math/elliptic_curves/jacobian_point.h +++ b/tachyon/math/geometry/jacobian_point.h @@ -1,10 +1,10 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_JACOBIAN_POINT_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_JACOBIAN_POINT_H_ +#ifndef TACHYON_MATH_GEOMETRY_JACOBIAN_POINT_H_ +#define TACHYON_MATH_GEOMETRY_JACOBIAN_POINT_H_ #include -#include "tachyon/math/elliptic_curves/point_conversions_forward.h" #include "tachyon/math/geometry/point3.h" +#include "tachyon/math/geometry/point_conversions_forward.h" namespace tachyon::math { @@ -39,4 +39,4 @@ struct PointConversions, JacobianPoint, } // namespace tachyon::math -#endif // TACHYON_MATH_ELLIPTIC_CURVES_JACOBIAN_POINT_H_ +#endif // TACHYON_MATH_GEOMETRY_JACOBIAN_POINT_H_ diff --git a/tachyon/math/elliptic_curves/point_conversions.h b/tachyon/math/geometry/point_conversions.h similarity index 87% rename from tachyon/math/elliptic_curves/point_conversions.h rename to tachyon/math/geometry/point_conversions.h index bbad02f32..9e2edf8ed 100644 --- a/tachyon/math/elliptic_curves/point_conversions.h +++ b/tachyon/math/geometry/point_conversions.h @@ -1,13 +1,12 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_POINT_CONVERSIONS_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_POINT_CONVERSIONS_H_ +#ifndef TACHYON_MATH_GEOMETRY_POINT_CONVERSIONS_H_ +#define TACHYON_MATH_GEOMETRY_POINT_CONVERSIONS_H_ -#include "tachyon/base/containers/container_util.h" #include "tachyon/base/template_util.h" -#include "tachyon/math/elliptic_curves/affine_point.h" -#include "tachyon/math/elliptic_curves/jacobian_point.h" -#include "tachyon/math/elliptic_curves/point_conversions_forward.h" -#include "tachyon/math/elliptic_curves/point_xyzz.h" -#include "tachyon/math/elliptic_curves/projective_point.h" +#include "tachyon/math/geometry/affine_point.h" +#include "tachyon/math/geometry/jacobian_point.h" +#include "tachyon/math/geometry/point_conversions_forward.h" +#include "tachyon/math/geometry/point_xyzz.h" +#include "tachyon/math/geometry/projective_point.h" namespace tachyon::math { @@ -127,4 +126,4 @@ struct PointConversions, JacobianPoint> { } // namespace tachyon::math -#endif // TACHYON_MATH_ELLIPTIC_CURVES_POINT_CONVERSIONS_H_ +#endif // TACHYON_MATH_GEOMETRY_POINT_CONVERSIONS_H_ diff --git a/tachyon/math/geometry/point_conversions_forward.h b/tachyon/math/geometry/point_conversions_forward.h new file mode 100644 index 000000000..689602e18 --- /dev/null +++ b/tachyon/math/geometry/point_conversions_forward.h @@ -0,0 +1,11 @@ +#ifndef TACHYON_MATH_GEOMETRY_POINT_CONVERSIONS_FORWARD_H_ +#define TACHYON_MATH_GEOMETRY_POINT_CONVERSIONS_FORWARD_H_ + +namespace tachyon::math { + +template +struct PointConversions; + +} // namespace tachyon::math + +#endif // TACHYON_MATH_GEOMETRY_POINT_CONVERSIONS_FORWARD_H_ diff --git a/tachyon/math/elliptic_curves/point_xyzz.h b/tachyon/math/geometry/point_xyzz.h similarity index 83% rename from tachyon/math/elliptic_curves/point_xyzz.h rename to tachyon/math/geometry/point_xyzz.h index 11c7593c4..90c7e38e1 100644 --- a/tachyon/math/elliptic_curves/point_xyzz.h +++ b/tachyon/math/geometry/point_xyzz.h @@ -1,10 +1,10 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_POINT_XYZZ_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_POINT_XYZZ_H_ +#ifndef TACHYON_MATH_GEOMETRY_POINT_XYZZ_H_ +#define TACHYON_MATH_GEOMETRY_POINT_XYZZ_H_ #include -#include "tachyon/math/elliptic_curves/point_conversions_forward.h" #include "tachyon/math/geometry/point4.h" +#include "tachyon/math/geometry/point_conversions_forward.h" namespace tachyon::math { @@ -39,4 +39,4 @@ struct PointConversions, PointXYZZ, } // namespace tachyon::math -#endif // TACHYON_MATH_ELLIPTIC_CURVES_POINT_XYZZ_H_ +#endif // TACHYON_MATH_GEOMETRY_POINT_XYZZ_H_ diff --git a/tachyon/math/elliptic_curves/projective_point.h b/tachyon/math/geometry/projective_point.h similarity index 80% rename from tachyon/math/elliptic_curves/projective_point.h rename to tachyon/math/geometry/projective_point.h index 5a72724c5..81ffb8aa6 100644 --- a/tachyon/math/elliptic_curves/projective_point.h +++ b/tachyon/math/geometry/projective_point.h @@ -1,11 +1,10 @@ -#ifndef TACHYON_MATH_ELLIPTIC_CURVES_PROJECTIVE_POINT_H_ -#define TACHYON_MATH_ELLIPTIC_CURVES_PROJECTIVE_POINT_H_ +#ifndef TACHYON_MATH_GEOMETRY_PROJECTIVE_POINT_H_ +#define TACHYON_MATH_GEOMETRY_PROJECTIVE_POINT_H_ #include -#include "tachyon/base/buffer/copyable.h" -#include "tachyon/math/elliptic_curves/point_conversions_forward.h" #include "tachyon/math/geometry/point3.h" +#include "tachyon/math/geometry/point_conversions_forward.h" namespace tachyon::math { @@ -40,4 +39,4 @@ struct PointConversions, ProjectivePoint, } // namespace tachyon::math -#endif // TACHYON_MATH_ELLIPTIC_CURVES_PROJECTIVE_POINT_H_ +#endif // TACHYON_MATH_GEOMETRY_PROJECTIVE_POINT_H_ diff --git a/tachyon/math/polynomials/univariate/univariate_dense_coefficients.h b/tachyon/math/polynomials/univariate/univariate_dense_coefficients.h index 05e6f8298..812e4732c 100644 --- a/tachyon/math/polynomials/univariate/univariate_dense_coefficients.h +++ b/tachyon/math/polynomials/univariate/univariate_dense_coefficients.h @@ -173,27 +173,18 @@ class UnivariateDenseCoefficients { // Return coefficients where the original coefficients reduce their degree // by categorizing coefficients into even and odd degrees, - // multiplying either set of coefficients by a specified random field |r|, + // multiplying coefficients with odd degrees by a specified random field |r|, // and summing them together. - template CONSTEXPR_IF_NOT_OPENMP UnivariateDenseCoefficients Fold(const Field& r) const { size_t size = coefficients_.size(); std::vector coefficients((size + 1) >> 1); OPENMP_PARALLEL_FOR(size_t i = 0; i < size; i += 2) { - if constexpr (MulRandomWithEvens) { - coefficients[i >> 1] = coefficients_[i] * r; - coefficients[i >> 1] += coefficients_[i + 1]; - } else { - coefficients[i >> 1] = coefficients_[i + 1] * r; - coefficients[i >> 1] += coefficients_[i]; - } + coefficients[i >> 1] = coefficients_[i + 1] * r; + coefficients[i >> 1] += coefficients_[i]; } if (size % 2 != 0) { coefficients[size >> 1] = coefficients_[size - 1]; - if constexpr (MulRandomWithEvens) { - coefficients[size >> 1] *= r; - } } return UnivariateDenseCoefficients(std::move(coefficients), true); } diff --git a/tachyon/math/polynomials/univariate/univariate_dense_polynomial_unittest.cc b/tachyon/math/polynomials/univariate/univariate_dense_polynomial_unittest.cc index 178a6e77c..86778e17f 100644 --- a/tachyon/math/polynomials/univariate/univariate_dense_polynomial_unittest.cc +++ b/tachyon/math/polynomials/univariate/univariate_dense_polynomial_unittest.cc @@ -339,39 +339,21 @@ TEST_F(UnivariateDensePolynomialTest, EvaluateVanishingPolyByRoots) { poly.Evaluate(point)); } -TEST_F(UnivariateDensePolynomialTest, FoldEven) { +TEST_F(UnivariateDensePolynomialTest, Fold) { Poly poly = Poly::Random(kMaxDegree); GF7 r = GF7::Random(); - Poly folded = poly.Fold(r); - EXPECT_EQ(folded, Poly(Coeffs({r * poly[0] + poly[1], r * poly[2] + poly[3], - r * poly[4] + poly[5]}, - true))); - - GF7 r2 = GF7::Random(); - Poly folded2 = folded.Fold(r2); - EXPECT_EQ(folded2, - Poly(Coeffs({r2 * folded[0] + folded[1], r2 * folded[2]}, true))); - - GF7 r3 = GF7::Random(); - Poly folded3 = folded2.Fold(r3); - EXPECT_EQ(folded3, Poly(Coeffs({r3 * folded2[0] + folded2[1]}, true))); -} - -TEST_F(UnivariateDensePolynomialTest, FoldOdd) { - Poly poly = Poly::Random(kMaxDegree); - GF7 r = GF7::Random(); - Poly folded = poly.Fold(r); + Poly folded = poly.Fold(r); EXPECT_EQ(folded, Poly(Coeffs({poly[0] + r * poly[1], poly[2] + r * poly[3], poly[4] + r * poly[5]}, true))); GF7 r2 = GF7::Random(); - Poly folded2 = folded.Fold(r2); + Poly folded2 = folded.Fold(r2); EXPECT_EQ(folded2, Poly(Coeffs({folded[0] + r2 * folded[1], folded[2]}, true))); GF7 r3 = GF7::Random(); - Poly folded3 = folded2.Fold(r3); + Poly folded3 = folded2.Fold(r3); EXPECT_EQ(folded3, Poly(Coeffs({folded2[0] + r3 * folded2[1]}, true))); } diff --git a/tachyon/math/polynomials/univariate/univariate_polynomial.h b/tachyon/math/polynomials/univariate/univariate_polynomial.h index 60fed66d2..b5ba41f28 100644 --- a/tachyon/math/polynomials/univariate/univariate_polynomial.h +++ b/tachyon/math/polynomials/univariate/univariate_polynomial.h @@ -150,12 +150,10 @@ class UnivariatePolynomial final // Return a polynomial where the original polynomial reduces its degree // by categorizing coefficients into even and odd degrees, - // multiplying either set of coefficients by a specified random field |r|, + // multiplying coefficients with odd degrees by a specified random field |r|, // and summing them together. - template constexpr UnivariatePolynomial Fold(const Field& r) const { - return UnivariatePolynomial( - coefficients_.template Fold(r)); + return UnivariatePolynomial(coefficients_.Fold(r)); } decltype(auto) ToSparse() const { diff --git a/tachyon/math/polynomials/univariate/univariate_sparse_coefficients.h b/tachyon/math/polynomials/univariate/univariate_sparse_coefficients.h index d84b9603e..4748e1d2f 100644 --- a/tachyon/math/polynomials/univariate/univariate_sparse_coefficients.h +++ b/tachyon/math/polynomials/univariate/univariate_sparse_coefficients.h @@ -227,36 +227,25 @@ class UnivariateSparseCoefficients { // Return coefficients where the original coefficients reduce their degree // by categorizing coefficients into even and odd degrees, - // multiplying either set of coefficients by a specified random field |r|, + // multiplying coefficients with odd degrees by a specified random field |r|, // and summing them together. - template constexpr UnivariateSparseCoefficients Fold(const Field& r) const { std::vector terms; terms.reserve(terms_.size() >> 1); bool r_is_zero = r.IsZero(); for (const Term& term : terms_) { if (term.degree % 2 == 0) { - if constexpr (MulRandomWithEvens) { - if (!r_is_zero) { - terms.push_back({term.degree >> 1, term.coefficient * r}); - } - } else { - terms.push_back({term.degree >> 1, term.coefficient}); - } + terms.push_back({term.degree >> 1, term.coefficient}); } else { if (!terms.empty() && terms.back().degree == (term.degree >> 1)) { - if constexpr (MulRandomWithEvens) { - terms.back() += term.coefficient; - } else if (!r_is_zero) { + if (!r_is_zero) { terms.back() += (term.coefficient * r); } if (terms.back().coefficient.IsZero()) { terms.pop_back(); } } else { - if constexpr (MulRandomWithEvens) { - terms.push_back({term.degree >> 1, term.coefficient}); - } else if (!r_is_zero) { + if (!r_is_zero) { terms.push_back({term.degree >> 1, term.coefficient * r}); } } diff --git a/tachyon/math/polynomials/univariate/univariate_sparse_polynomial_unittest.cc b/tachyon/math/polynomials/univariate/univariate_sparse_polynomial_unittest.cc index fe37f5c13..b431327a2 100644 --- a/tachyon/math/polynomials/univariate/univariate_sparse_polynomial_unittest.cc +++ b/tachyon/math/polynomials/univariate/univariate_sparse_polynomial_unittest.cc @@ -369,39 +369,10 @@ TEST_F(UnivariateSparsePolynomialTest, EvaluateVanishingPolyByRoots) { poly.Evaluate(point)); } -TEST_F(UnivariateSparsePolynomialTest, FoldEven) { +TEST_F(UnivariateSparsePolynomialTest, Fold) { Poly poly = Poly::Random(kMaxDegree); GF7 r = GF7::Random(); - Poly folded = poly.Fold(r); - std::vector> terms{{0, r * poly[0] + poly[1]}, - {1, r * poly[2] + poly[3]}, - {2, r * poly[4] + poly[5]}}; - base::EraseIf(terms, [](const UnivariateTerm& term) { - return term.coefficient.IsZero(); - }); - EXPECT_EQ(folded, Poly(Coeffs(std::move(terms)))); - - GF7 r2 = GF7::Random(); - Poly folded2 = folded.Fold(r2); - terms = {{0, r2 * folded[0] + folded[1]}, {1, r2 * folded[2]}}; - base::EraseIf(terms, [](const UnivariateTerm& term) { - return term.coefficient.IsZero(); - }); - EXPECT_EQ(folded2, Poly(Coeffs(std::move(terms)))); - - GF7 r3 = GF7::Random(); - Poly folded3 = folded2.Fold(r3); - terms = {{0, r3 * folded2[0] + folded2[1]}}; - base::EraseIf(terms, [](const UnivariateTerm& term) { - return term.coefficient.IsZero(); - }); - EXPECT_EQ(folded3, Poly(Coeffs(std::move(terms)))); -} - -TEST_F(UnivariateSparsePolynomialTest, FoldOdd) { - Poly poly = Poly::Random(kMaxDegree); - GF7 r = GF7::Random(); - Poly folded = poly.Fold(r); + Poly folded = poly.Fold(r); std::vector> terms{{0, poly[0] + r * poly[1]}, {1, poly[2] + r * poly[3]}, {2, poly[4] + r * poly[5]}}; @@ -411,7 +382,7 @@ TEST_F(UnivariateSparsePolynomialTest, FoldOdd) { EXPECT_EQ(folded, Poly(Coeffs(std::move(terms)))); GF7 r2 = GF7::Random(); - Poly folded2 = folded.Fold(r2); + Poly folded2 = folded.Fold(r2); terms = {{0, folded[0] + r2 * folded[1]}, {1, folded[2]}}; base::EraseIf(terms, [](const UnivariateTerm& term) { return term.coefficient.IsZero(); @@ -419,7 +390,7 @@ TEST_F(UnivariateSparsePolynomialTest, FoldOdd) { EXPECT_EQ(folded2, Poly(Coeffs(std::move(terms)))); GF7 r3 = GF7::Random(); - Poly folded3 = folded2.Fold(r3); + Poly folded3 = folded2.Fold(r3); terms = {{0, folded2[0] + r3 * folded2[1]}}; base::EraseIf(terms, [](const UnivariateTerm& term) { return term.coefficient.IsZero(); diff --git a/tachyon/node/math/elliptic_curves/short_weierstrass/BUILD.bazel b/tachyon/node/math/elliptic_curves/short_weierstrass/BUILD.bazel index d0d5a37cb..5286313aa 100644 --- a/tachyon/node/math/elliptic_curves/short_weierstrass/BUILD.bazel +++ b/tachyon/node/math/elliptic_curves/short_weierstrass/BUILD.bazel @@ -11,7 +11,10 @@ tachyon_cc_library( "projective_point.h", ], deps = [ - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:jacobian_point", + "//tachyon/math/geometry:point_xyzz", + "//tachyon/math/geometry:projective_point", "//tachyon/node/base:node_base", ], ) diff --git a/tachyon/node/math/elliptic_curves/short_weierstrass/jacobian_point.h b/tachyon/node/math/elliptic_curves/short_weierstrass/jacobian_point.h index 37fe8292d..ebba65fd0 100644 --- a/tachyon/node/math/elliptic_curves/short_weierstrass/jacobian_point.h +++ b/tachyon/node/math/elliptic_curves/short_weierstrass/jacobian_point.h @@ -1,7 +1,7 @@ #ifndef TACHYON_NODE_MATH_ELLIPTIC_CURVES_SHORT_WEIERSTRASS_JACOBIAN_POINT_H_ #define TACHYON_NODE_MATH_ELLIPTIC_CURVES_SHORT_WEIERSTRASS_JACOBIAN_POINT_H_ -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/node/base/node_module.h" namespace tachyon::node::math { diff --git a/tachyon/node/math/elliptic_curves/short_weierstrass/point_xyzz.h b/tachyon/node/math/elliptic_curves/short_weierstrass/point_xyzz.h index 7067c63c1..6b2b5c574 100644 --- a/tachyon/node/math/elliptic_curves/short_weierstrass/point_xyzz.h +++ b/tachyon/node/math/elliptic_curves/short_weierstrass/point_xyzz.h @@ -1,7 +1,7 @@ #ifndef TACHYON_NODE_MATH_ELLIPTIC_CURVES_SHORT_WEIERSTRASS_POINT_XYZZ_H_ #define TACHYON_NODE_MATH_ELLIPTIC_CURVES_SHORT_WEIERSTRASS_POINT_XYZZ_H_ -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/node/base/node_module.h" namespace tachyon::node::math { diff --git a/tachyon/node/math/elliptic_curves/short_weierstrass/projective_point.h b/tachyon/node/math/elliptic_curves/short_weierstrass/projective_point.h index 1c9846979..abf788df4 100644 --- a/tachyon/node/math/elliptic_curves/short_weierstrass/projective_point.h +++ b/tachyon/node/math/elliptic_curves/short_weierstrass/projective_point.h @@ -1,7 +1,7 @@ #ifndef TACHYON_NODE_MATH_ELLIPTIC_CURVES_SHORT_WEIERSTRASS_PROJECTIVE_POINT_H_ #define TACHYON_NODE_MATH_ELLIPTIC_CURVES_SHORT_WEIERSTRASS_PROJECTIVE_POINT_H_ -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/node/base/node_module.h" namespace tachyon::node::math { diff --git a/tachyon/py/math/elliptic_curves/short_weierstrass/BUILD.bazel b/tachyon/py/math/elliptic_curves/short_weierstrass/BUILD.bazel index 5f7cd4f0f..e87c46bcf 100644 --- a/tachyon/py/math/elliptic_curves/short_weierstrass/BUILD.bazel +++ b/tachyon/py/math/elliptic_curves/short_weierstrass/BUILD.bazel @@ -11,7 +11,10 @@ tachyon_pybind_library( "projective_point.h", ], deps = [ - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:affine_point", + "//tachyon/math/geometry:jacobian_point", + "//tachyon/math/geometry:point_xyzz", + "//tachyon/math/geometry:projective_point", "//tachyon/py/base:pybind11", ], ) diff --git a/tachyon/py/math/elliptic_curves/short_weierstrass/jacobian_point.h b/tachyon/py/math/elliptic_curves/short_weierstrass/jacobian_point.h index 87ac89569..583197ee7 100644 --- a/tachyon/py/math/elliptic_curves/short_weierstrass/jacobian_point.h +++ b/tachyon/py/math/elliptic_curves/short_weierstrass/jacobian_point.h @@ -5,7 +5,7 @@ #include "pybind11/operators.h" -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/py/base/pybind11.h" namespace tachyon::py::math { diff --git a/tachyon/py/math/elliptic_curves/short_weierstrass/point_xyzz.h b/tachyon/py/math/elliptic_curves/short_weierstrass/point_xyzz.h index 92f9ba911..1c3915a4b 100644 --- a/tachyon/py/math/elliptic_curves/short_weierstrass/point_xyzz.h +++ b/tachyon/py/math/elliptic_curves/short_weierstrass/point_xyzz.h @@ -5,7 +5,7 @@ #include "pybind11/operators.h" -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/py/base/pybind11.h" namespace tachyon::py::math { diff --git a/tachyon/py/math/elliptic_curves/short_weierstrass/projective_point.h b/tachyon/py/math/elliptic_curves/short_weierstrass/projective_point.h index 9f837ce64..10de12c58 100644 --- a/tachyon/py/math/elliptic_curves/short_weierstrass/projective_point.h +++ b/tachyon/py/math/elliptic_curves/short_weierstrass/projective_point.h @@ -5,7 +5,7 @@ #include "pybind11/operators.h" -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/py/base/pybind11.h" namespace tachyon::py::math { diff --git a/tachyon/zk/plonk/halo2/BUILD.bazel b/tachyon/zk/plonk/halo2/BUILD.bazel index 2e17f21f8..4a5114df0 100644 --- a/tachyon/zk/plonk/halo2/BUILD.bazel +++ b/tachyon/zk/plonk/halo2/BUILD.bazel @@ -181,8 +181,8 @@ tachyon_cc_library( hdrs = ["proof_serializer.h"], deps = [ "//tachyon/base/buffer", - "//tachyon/math/elliptic_curves:points", "//tachyon/math/finite_fields:prime_field_base", + "//tachyon/math/geometry:affine_point", ], ) diff --git a/tachyon/zk/plonk/halo2/proof_serializer.h b/tachyon/zk/plonk/halo2/proof_serializer.h index 436dbca14..6f290b8df 100644 --- a/tachyon/zk/plonk/halo2/proof_serializer.h +++ b/tachyon/zk/plonk/halo2/proof_serializer.h @@ -11,8 +11,8 @@ #include #include "tachyon/base/buffer/buffer.h" -#include "tachyon/math/elliptic_curves/affine_point.h" #include "tachyon/math/finite_fields/prime_field_base.h" +#include "tachyon/math/geometry/affine_point.h" namespace tachyon::zk::plonk::halo2 { diff --git a/tachyon/zk/plonk/halo2/stringifiers/BUILD.bazel b/tachyon/zk/plonk/halo2/stringifiers/BUILD.bazel index 1781cca71..8b111e2e8 100644 --- a/tachyon/zk/plonk/halo2/stringifiers/BUILD.bazel +++ b/tachyon/zk/plonk/halo2/stringifiers/BUILD.bazel @@ -110,7 +110,7 @@ tachyon_cc_library( hdrs = ["point_stringifier.h"], deps = [ ":field_stringifier", - "//tachyon/math/elliptic_curves:points", + "//tachyon/math/geometry:affine_point", ], ) diff --git a/tachyon/zk/plonk/halo2/stringifiers/point_stringifier.h b/tachyon/zk/plonk/halo2/stringifiers/point_stringifier.h index 4009a67cc..e5de9d08a 100644 --- a/tachyon/zk/plonk/halo2/stringifiers/point_stringifier.h +++ b/tachyon/zk/plonk/halo2/stringifiers/point_stringifier.h @@ -10,7 +10,7 @@ #include #include "tachyon/base/strings/rust_stringifier.h" -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" #include "tachyon/zk/plonk/halo2/stringifiers/field_stringifier.h" namespace tachyon::base::internal { diff --git a/tachyon/zk/r1cs/groth16/BUILD.bazel b/tachyon/zk/r1cs/groth16/BUILD.bazel index 11a613c52..a4214af9b 100644 --- a/tachyon/zk/r1cs/groth16/BUILD.bazel +++ b/tachyon/zk/r1cs/groth16/BUILD.bazel @@ -67,8 +67,8 @@ tachyon_cc_library( deps = [ ":prepared_verifying_key", ":proof", - "//tachyon/math/elliptic_curves:points", "//tachyon/math/elliptic_curves/msm:variable_base_msm", + "//tachyon/math/geometry:point_conversions", ], ) diff --git a/tachyon/zk/r1cs/groth16/verify.h b/tachyon/zk/r1cs/groth16/verify.h index 8bfa302c3..b88493afe 100644 --- a/tachyon/zk/r1cs/groth16/verify.h +++ b/tachyon/zk/r1cs/groth16/verify.h @@ -10,7 +10,7 @@ #include "tachyon/math/elliptic_curves/msm/variable_base_msm.h" #include "tachyon/math/elliptic_curves/pairing/pairing.h" -#include "tachyon/math/elliptic_curves/point_conversions.h" +#include "tachyon/math/geometry/point_conversions.h" #include "tachyon/zk/r1cs/groth16/prepared_verifying_key.h" #include "tachyon/zk/r1cs/groth16/proof.h" diff --git a/vendors/circom/circomlib/json/BUILD.bazel b/vendors/circom/circomlib/json/BUILD.bazel index 2018c2d5e..bcca2a02c 100644 --- a/vendors/circom/circomlib/json/BUILD.bazel +++ b/vendors/circom/circomlib/json/BUILD.bazel @@ -8,6 +8,7 @@ tachyon_cc_library( deps = [ ":json_converter_forward", ":points", + "@kroma_network_tachyon//tachyon/base:logging", "@kroma_network_tachyon//tachyon/zk/r1cs/groth16:proof", ], ) @@ -33,7 +34,7 @@ tachyon_cc_library( hdrs = ["points.h"], deps = [ "@com_github_tencent_rapidjson//:rapidjson", - "@kroma_network_tachyon//tachyon/math/elliptic_curves:points", + "@kroma_network_tachyon//tachyon/math/geometry:affine_point", ], ) diff --git a/vendors/circom/circomlib/json/groth16_proof.h b/vendors/circom/circomlib/json/groth16_proof.h index f40f0691b..896fa7ca3 100644 --- a/vendors/circom/circomlib/json/groth16_proof.h +++ b/vendors/circom/circomlib/json/groth16_proof.h @@ -3,6 +3,7 @@ #include "circomlib/json/json_converter_forward.h" #include "circomlib/json/points.h" +#include "tachyon/base/logging.h" #include "tachyon/zk/r1cs/groth16/proof.h" namespace tachyon::circom { diff --git a/vendors/circom/circomlib/json/points.h b/vendors/circom/circomlib/json/points.h index 2a5d431e2..fe0cd76d0 100644 --- a/vendors/circom/circomlib/json/points.h +++ b/vendors/circom/circomlib/json/points.h @@ -5,7 +5,7 @@ #include "rapidjson/document.h" -#include "tachyon/math/elliptic_curves/affine_point.h" +#include "tachyon/math/geometry/affine_point.h" namespace tachyon::circom::internal {