Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
ashjeong committed May 10, 2024
1 parent 2c1974e commit a0729be
Show file tree
Hide file tree
Showing 16 changed files with 1,726 additions and 2,740 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ jobs:
run: bazel build -c fastbuild --config ${{ matrix.bazel_config }} //...

- name: Test Tachyon (fastbuild)
run: bazel test -c fastbuild --config ${{ matrix.bazel_config }} --test_output=errors --test_tag_filters -benchmark,-manual,-cuda //...
run: bazel test -c fastbuild --config ${{ matrix.bazel_config }} --test_output=errors --test_tag_filters -benchmark,-manual,-cuda,-halo2 //...

- name: Test Tachyon (optimized)
run: bazel test -c opt --config ${{ matrix.bazel_config }} --test_output=errors --test_tag_filters -benchmark,-manual,-cuda //...

- name: Test Tachyon (halo2)
run: bazel test -c opt --config ${{ matrix.bazel_config }} halo2 --test_output=errors --test_tag_filters -benchmark,-manual,-cuda //tachyon/zk/plonk/examples/fibonacci/...

- name: Test OpenMP
if: matrix.os == 'ubuntu-latest'
# NOTE(TomTaehoonKim): Test timeouts are overridden 1.5x of the default timeout due to timeout failure on GitHub Actions by change in
Expand Down
45 changes: 23 additions & 22 deletions tachyon/zk/plonk/base/column_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ namespace tachyon::zk::plonk {

class TACHYON_EXPORT ColumnKeyBase {
public:
ColumnKeyBase() = default;
ColumnKeyBase(ColumnType type, size_t index) : type_(type), index_(index) {}
constexpr ColumnKeyBase() = default;
constexpr ColumnKeyBase(ColumnType type, size_t index)
: type_(type), index_(index) {}

ColumnType type() const { return type_; }
size_t index() const { return index_; }
constexpr ColumnType type() const { return type_; }
constexpr size_t index() const { return index_; }

bool operator==(const ColumnKeyBase& other) const {
constexpr bool operator==(const ColumnKeyBase& other) const {
return type_ == other.type_ && index_ == other.index_;
}
bool operator!=(const ColumnKeyBase& other) const {
constexpr bool operator!=(const ColumnKeyBase& other) const {
return !operator==(other);
}

Expand Down Expand Up @@ -62,16 +63,16 @@ class ColumnKey : public ColumnKeyBase {
public:
constexpr static ColumnType kDefaultType = C;

ColumnKey() : ColumnKeyBase(C, 0) {}
explicit ColumnKey(size_t index) : ColumnKeyBase(C, index) {}
constexpr ColumnKey() : ColumnKeyBase(C, 0) {}
constexpr explicit ColumnKey(size_t index) : ColumnKeyBase(C, index) {}

// NOTE(chokobole): AdviceColumnKey can be constructed with an additional
// argument |phase|.
//
// AdviceColumnKey column(1, kSecondPhase);
template <ColumnType C2 = C,
std::enable_if_t<C2 == ColumnType::kAdvice>* = nullptr>
ColumnKey(size_t index, Phase phase)
constexpr ColumnKey(size_t index, Phase phase)
: ColumnKeyBase(C, index), phase_(phase) {}

// NOTE(chokobole): in this case, |type_| is changed!
Expand All @@ -84,7 +85,7 @@ class ColumnKey : public ColumnKeyBase {
// CHECK_EQ(c.phase(), kSecondPhase);
template <ColumnType C2,
std::enable_if_t<C == ColumnType::kAny && C != C2>* = nullptr>
ColumnKey(const ColumnKey<C2>& other)
constexpr ColumnKey(const ColumnKey<C2>& other)
: ColumnKeyBase(other.type_, other.index_), phase_(other.phase_) {}

// NOTE(chokobole): in this case, |type_| is not changed!
Expand All @@ -98,11 +99,11 @@ class ColumnKey : public ColumnKeyBase {
// CHECK_EQ(c2.phase(), kSecondPhase);
template <ColumnType C2, std::enable_if_t<C != ColumnType::kAny &&
C2 == ColumnType::kAny>* = nullptr>
ColumnKey(const ColumnKey<C2>& other)
constexpr ColumnKey(const ColumnKey<C2>& other)
: ColumnKeyBase(C, other.index_), phase_(other.phase_) {}

// FixedColumnKey c(FixedColumnKey(1));
ColumnKey(const ColumnKey& other) = default;
constexpr ColumnKey(const ColumnKey& other) = default;

// NOTE(chokobole): in this case, |type_| is changed!
//
Expand All @@ -116,7 +117,7 @@ class ColumnKey : public ColumnKeyBase {
// CHECK_EQ(c.phase(), kSecondPhase);
template <ColumnType C2,
std::enable_if_t<C == ColumnType::kAny && C != C2>* = nullptr>
ColumnKey& operator=(const ColumnKey<C2>& other) {
constexpr ColumnKey& operator=(const ColumnKey<C2>& other) {
ColumnKeyBase::operator=(other);
phase_ = other.phase_;
return *this;
Expand All @@ -134,37 +135,37 @@ class ColumnKey : public ColumnKeyBase {
// CHECK_EQ(c.phase(), kSecondPhase);
template <ColumnType C2, std::enable_if_t<C != ColumnType::kAny &&
C2 == ColumnType::kAny>* = nullptr>
ColumnKey& operator=(const ColumnKey<C2>& other) {
constexpr ColumnKey& operator=(const ColumnKey<C2>& other) {
index_ = other.index_;
phase_ = other.phase_;
return *this;
}

// FixedColumnKey c;
// c = FixedColumnKey(1);
ColumnKey& operator=(const ColumnKey& other) = default;
constexpr ColumnKey& operator=(const ColumnKey& other) = default;

ColumnType type() const { return type_; }
size_t index() const { return index_; }
Phase phase() const { return phase_; }
constexpr ColumnType type() const { return type_; }
constexpr size_t index() const { return index_; }
constexpr Phase phase() const { return phase_; }

template <ColumnType C2>
bool operator==(const ColumnKey<C2>& other) const {
constexpr bool operator==(const ColumnKey<C2>& other) const {
if (!ColumnKeyBase::operator==(other)) return false;
if (type_ == ColumnType::kAdvice) {
return phase_ == other.phase_;
}
return true;
}
template <ColumnType C2>
bool operator!=(const ColumnKey<C2>& other) const {
constexpr bool operator!=(const ColumnKey<C2>& other) const {
return !operator==(other);
}

// This ordering is consensus-critical! The layouters rely on deterministic
// column orderings.
template <ColumnType C2>
bool operator<(const ColumnKey<C2>& other) const {
constexpr bool operator<(const ColumnKey<C2>& other) const {
CHECK_NE(type_, ColumnType::kAny);
CHECK_NE(other.type_, ColumnType::kAny);

Expand All @@ -180,7 +181,7 @@ class ColumnKey : public ColumnKeyBase {
}
}

std::string ToString() const {
constexpr std::string ToString() const {
if (type_ == ColumnType::kAdvice) {
return absl::Substitute("{type: $0, index: $1, phase: $2}",
ColumnTypeToString(type_), index_,
Expand Down
6 changes: 6 additions & 0 deletions tachyon/zk/plonk/examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ tachyon_cc_library(
name = "shuffle_circuit_test_data",
testonly = True,
hdrs = ["shuffle_circuit_test_data.h"],
deps = COMMON_TEST_DATA_DEPS + [
"//tachyon/math/elliptic_curves/bn/bn254",
"//tachyon/zk/base/commitments:gwc_extension",
"//tachyon/zk/base/commitments:shplonk_extension",
],
)

tachyon_cc_library(
Expand Down Expand Up @@ -75,6 +80,7 @@ tachyon_cc_library(
name = "simple_lookup_circuit_test_data",
testonly = True,
hdrs = ["simple_lookup_circuit_test_data.h"],
deps = COMMON_TEST_DATA_DEPS,
)

tachyon_cc_unittest(
Expand Down
11 changes: 6 additions & 5 deletions tachyon/zk/plonk/examples/circuit_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ namespace tachyon::zk::plonk::halo2 {

template <typename PCS>
class CircuitTest : public ProverTest<PCS> {
public:
struct Point {
std::string_view x;
std::string_view y;
};

protected:
using F = typename PCS::Field;
using Commitment = typename PCS::Commitment;
using Poly = typename PCS::Poly;
using Evals = typename PCS::Evals;
using RationalEvals = typename PCS::RationalEvals;

struct Point {
std::string_view x;
std::string_view y;
};

static Commitment CreateCommitment(const Point& point) {
using BaseField = typename Commitment::BaseField;
return Commitment(*BaseField::FromHexString(point.x),
Expand Down
124 changes: 124 additions & 0 deletions tachyon/zk/plonk/examples/circuit_test_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#ifndef TACHYON_ZK_PLONK_EXAMPLES_CIRCUIT_TEST_DATA_H_
#define TACHYON_ZK_PLONK_EXAMPLES_CIRCUIT_TEST_DATA_H_

#include <stdint.h>

#include <vector>

#include "tachyon/base/range.h"
#include "tachyon/math/elliptic_curves/bn/bn254/bn254.h"
#include "tachyon/zk/base/commitments/shplonk_extension.h"
#include "tachyon/zk/plonk/examples/circuit_test.h"

namespace tachyon::zk::plonk::halo2 {

// TODO: move somewhere else
template <typename T, size_t N>
const std::vector<T> ArrayToVector(const T (&arr)[N]) {
return std::vector<T>(std::begin(arr), std::end(arr));
}

template <typename T>
const std::vector<T> ArrayToVector(const T (&arr)[0]) {
return {};
}

template <typename T, size_t A, size_t B>
std::vector<std::vector<T>> Array2DToVector2D(const T (&arr)[A][B]) {
std::vector<std::vector<T>> vec = {};
for (const auto& inner_array : arr) {
vec.emplace_back(std::begin(inner_array), std::end(inner_array));
}
return vec;
}

template <typename T>
std::vector<std::vector<T>> Array2DToVector2D(const T (&arr)[0][0]) {
return {};
}

template <typename CircuitType, typename _ProverType>
class CircuitTestData {
public:
using ProverType = _ProverType;

constexpr static size_t kN = 1;
constexpr static std::string_view kPinnedConstraintSystem = "";
constexpr static std::string_view kFixedColumnsOther[0][0] = {};
constexpr static AnyColumnKey kColumns[0] = {};
constexpr static Label kMapping[0][0] = {};
constexpr static Label kAux[0][0] = {};
constexpr static size_t kSizes[0][0] = {};
constexpr static bool kSelectors[0][0] = {};
constexpr static base::Range<RowIndex> kUsableRows =
base::Range<RowIndex>::Until(10);
constexpr static std::string_view kPinnedVerifyingKey = "";
constexpr static std::string_view kTranscriptRepr = "";
constexpr static std::string_view kLFirst[0] = {};
constexpr static std::string_view kLLast[0] = {};
constexpr static std::string_view kLActiveRow[0] = {};
constexpr static std::string_view kFixedColumns[0][0] = {};
constexpr static std::string_view kFixedPolys[0][0] = {};
constexpr static std::string_view kPermutationsColumns[0][0] = {};
constexpr static std::string_view kPermutationsPolys[0][0] = {};
constexpr static uint8_t kProof[0] = {};
constexpr static
typename CircuitTest<ProverType>::Point kAdviceCommitments[0][0] = {};
constexpr static std::string_view kChallenges[0] = {};
constexpr static std::string_view kTheta = "";
constexpr static typename CircuitTest<ProverType>::Point
kPermutationProductCommitmentsInputPoints[0][0] = {};
constexpr static typename CircuitTest<ProverType>::Point
kPermutationProductCommitmentsTablePoints[0][0] = {};
constexpr static std::string_view kBeta = "";
constexpr static std::string_view kGamma = "";
constexpr static typename CircuitTest<ProverType>::Point
kPermutationProductCommitments[0][0] = {};
constexpr static
typename CircuitTest<ProverType>::Point kLookupProductCommitments[0][0] =
{};
constexpr static std::string_view kY = "";
constexpr static
typename CircuitTest<ProverType>::Point kVanishingHPolyCommitments[0] =
{};
constexpr static std::string_view kX = "";
constexpr static std::string_view kAdviceEvals[0][0] = {};
constexpr static std::string_view kFixedEvals[0] = {};
constexpr static std::string_view kCommonPermutationEvals[0] = {};
constexpr static std::string_view kPermutationProductEvals[0][0] = {};
constexpr static std::string_view kPermutationProductNextEvals[0][0] = {};
constexpr static std::string_view kPermutationProductLastEvals[0][0] = {};
constexpr static std::string_view kLookupProductEvals[0][0] = {};
constexpr static std::string_view kLookupProductNextEvals[0][0] = {};
constexpr static std::string_view kLookupPermutedInputEvals[0][0] = {};
constexpr static std::string_view kLookupPermutedInputPrevEvals[0][0] = {};
constexpr static std::string_view kLookupPermutedTableEvals[0][0] = {};
constexpr static std::string_view kHEval = "";

constexpr static
typename CircuitTest<ProverType>::Point kVanishingRandomPolyCommitment{
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002"};

constexpr static std::string_view kVanishingRandomEval =
"0x0000000000000000000000000000000000000000000000000000000000000001";

static CircuitType GetCircuit() { return CircuitType(); }

static std::vector<CircuitType> GetCircuits() {
CircuitType circuit = GetCircuit();
return {circuit, std::move(circuit)};
}

static std::vector<typename ProverType::RationalEvals> GetFixedColumns() {
return {};
}

static std::vector<typename ProverType::Evals> GetInstanceColumns() {
return {};
}
};

} // namespace tachyon::zk::plonk::halo2

#endif // TACHYON_ZK_PLONK_EXAMPLES_CIRCUIT_TEST_DATA_H_
55 changes: 0 additions & 55 deletions tachyon/zk/plonk/examples/fibonacci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -75,58 +75,3 @@ tachyon_cc_library(
"//tachyon/zk/plonk/layout:region",
],
)

COMMON_DEPS = [
"//tachyon/zk/plonk/examples:circuit_test",
"//tachyon/zk/plonk/halo2:pinned_constraint_system",
"//tachyon/zk/plonk/halo2:pinned_verifying_key",
"//tachyon/zk/plonk/keys:proving_key",
"//tachyon/zk/plonk/layout/floor_planner:simple_floor_planner",
"//tachyon/zk/plonk/layout/floor_planner/v1:v1_floor_planner",
]

tachyon_cc_unittest(
name = "fibonacci1_circuit_test",
srcs = ["fibonacci1_circuit_test.cc"],
deps = COMMON_DEPS + [
":fibonacci1_circuit",
":fibonacci1_circuit_test_data",
],
)

tachyon_cc_unittest(
name = "fibonacci1_v1_circuit_test",
srcs = ["fibonacci1_v1_circuit_test.cc"],
deps = COMMON_DEPS + [
":fibonacci1_circuit",
":fibonacci1_circuit_test_data",
],
)

tachyon_cc_unittest(
name = "fibonacci2_circuit_test",
srcs = ["fibonacci2_circuit_test.cc"],
deps = COMMON_DEPS + [
":fibonacci2_circuit",
":fibonacci2_circuit_test_data",
],
)

tachyon_cc_unittest(
name = "fibonacci3_circuit_test",
srcs = ["fibonacci3_circuit_test.cc"],
deps = COMMON_DEPS + [
":fibonacci3_circuit",
":fibonacci3_circuit_test_data",
],
)

tachyon_cc_unittest(
name = "fibonacci4_circuit_test",
size = "medium",
srcs = ["fibonacci4_circuit_test.cc"],
deps = COMMON_DEPS + [
":fibonacci4_circuit",
":fibonacci4_circuit_test_data",
],
)
Loading

0 comments on commit a0729be

Please sign in to comment.