Skip to content

Commit 87116f9

Browse files
author
Ryan Kim
authored
Merge pull request #553 from kroma-network/refac/refac-two-adic-fri
refac: refactor `TwoAdicFri` verify
2 parents dad8fb5 + bb6d337 commit 87116f9

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

tachyon/crypto/commitments/fri/fri_config.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ struct FRIConfig {
2626
size_t Blowup() const { return size_t{1} << log_blowup; }
2727
};
2828

29+
// NOTE(ashjeong): |kLogArity| is subject to change in the future
2930
template <typename ExtF, typename Derived>
3031
std::vector<ExtF> FoldMatrix(const ExtF& beta,
3132
const Eigen::MatrixBase<Derived>& mat) {
3233
using F = typename math::ExtensionFieldTraits<ExtF>::BaseField;
34+
const size_t kLogArity = 1;
3335
// We use the fact that
3436
// pₑ(x²) = (p(x) + p(-x)) / 2
3537
// pₒ(x²) = (p(x) - p(-x)) / (2x)
@@ -42,8 +44,8 @@ std::vector<ExtF> FoldMatrix(const ExtF& beta,
4244
// + (1/2 - β/2gᵢₙᵥⁱ)p(gⁿᐟ²⁺ⁱ)
4345
size_t rows = static_cast<size_t>(mat.rows());
4446
F w;
45-
CHECK(
46-
F::GetRootOfUnity(size_t{1} << (base::bits::CheckedLog2(rows) + 1), &w));
47+
CHECK(F::GetRootOfUnity(
48+
size_t{1} << (base::bits::CheckedLog2(rows) + kLogArity), &w));
4749
ExtF w_inv = ExtF(unwrap(w.Inverse()));
4850
ExtF half_beta = beta * ExtF::TwoInv();
4951

@@ -61,26 +63,25 @@ std::vector<ExtF> FoldMatrix(const ExtF& beta,
6163
return ret;
6264
}
6365

64-
// NOTE(ashjeong): |arity| is subject to change in the future
66+
// NOTE(ashjeong): |kLogArity| is subject to change in the future
6567
template <typename ExtF>
6668
ExtF FoldRow(size_t index, uint32_t log_num_rows, const ExtF& beta,
6769
const std::vector<ExtF>& evals) {
6870
using F = typename math::ExtensionFieldTraits<ExtF>::BaseField;
69-
const size_t kArity = 2;
7071
const size_t kLogArity = 1;
71-
const ExtF& e0 = evals[0];
72-
const ExtF& e1 = evals[1];
7372

7473
F w;
7574
CHECK(F::GetRootOfUnity(size_t{1} << (log_num_rows + kLogArity), &w));
76-
ExtF subgroup_start =
77-
ExtF(w.Pow(base::bits::ReverseBitsLen(index, log_num_rows)));
75+
ExtF w_inv = ExtF(unwrap(w.Inverse()));
76+
ExtF half_beta = beta * ExtF::TwoInv();
77+
ExtF power =
78+
ExtF(w_inv.Pow(base::bits::ReverseBitsLen(index, log_num_rows))) *
79+
half_beta;
7880

79-
CHECK(F::GetRootOfUnity(size_t{1} << kLogArity, &w));
80-
std::vector<ExtF> xs = ExtF::GetBitRevIndexSuccessivePowersSerial(
81-
kArity, ExtF(w), subgroup_start);
82-
// interpolate and evaluate at beta
83-
return e0 + unwrap((beta - xs[0]) * (e1 - e0) / (xs[1] - xs[0]));
81+
// result(g²ⁱ) = (1/2 + β/2gᵢₙᵥⁱ)p(gⁱ) + (1/2 - β/2gᵢₙᵥⁱ)p(gⁿᐟ²⁺ⁱ)
82+
const ExtF& lo = evals[0];
83+
const ExtF& hi = evals[1];
84+
return (ExtF::TwoInv() + power) * lo + (ExtF::TwoInv() - power) * hi;
8485
}
8586

8687
} // namespace tachyon::crypto

tachyon/crypto/commitments/fri/simple_fri.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,13 @@ class SimpleFRI final
153153
// Pᵢ₊₁(X) = Pᵢ_even(X) + β * Pᵢ_odd(X)
154154
//
155155
// If the domain of Pᵢ(X) is Dᵢ = {ω⁰, ω¹, ..., ωⁿ⁻¹},
156-
// then the domain of Pᵢ₊₁(X) is Dᵢ₊₁ = {ω⁰, ω¹, ..., ωᵏ⁻¹},
157-
// where k = n / 2.
156+
// then the domain of Pᵢ₊₁(X) is Dᵢ₊₁ = {ω⁰, ω², ..., ωⁿ⁻²}.
158157
//
159158
// As per the definition:
160-
// Pᵢ₊₁(ωʲ) = Pᵢ_even(ωʲ) + β * Pᵢ_odd(ωʲ)
159+
// Pᵢ₊₁(ω²ʲ) = Pᵢ_even(ω²ʲ) + β * Pᵢ_odd(ω²ʲ)
161160
//
162161
// Substituting Pᵢ_even and Pᵢ_odd:
163-
// Pᵢ₊₁(ωʲ) = (Pᵢ(ωʲ) + Pᵢ(-ωʲ)) / 2 + β * (Pᵢ(ωʲ) - Pᵢ(-ωʲ)) / (2 * ωʲ)
162+
// Pᵢ₊₁(ω²ʲ) = (Pᵢ(ωʲ) + Pᵢ(-ωʲ)) / 2 + β * (Pᵢ(ωʲ) - Pᵢ(-ωʲ)) / (2 * ωʲ)
164163
// = ((1 + β * ω⁻ʲ) * Pᵢ(ωʲ) + (1 - β * ω⁻ʲ) * Pᵢ(-ωʲ)) / 2
165164
size_t leaf_index = index % domain_size;
166165
if (i == 0) {

tachyon/math/base/semigroups.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class MultiplicativeSemigroup {
250250
size_t size, const G& generator, const G& c = G::One()) {
251251
std::vector<MulResult> ret(size);
252252
uint32_t log_size = base::bits::CheckedLog2(size);
253-
MulResult pow = c.IsOne() ? G::One() : c;
253+
MulResult pow = c;
254254
for (size_t idx = 0; idx < size - 1; ++idx) {
255255
ret[base::bits::ReverseBitsLen(idx, log_size)] = pow;
256256
pow *= generator;

tachyon/math/finite_fields/extension_field_base.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class ExtensionFieldBase {
6969
using PackedField = typename PackedFieldTraits<BaseField>::PackedField;
7070
constexpr uint32_t kDegree = T::ExtensionDegree();
7171

72-
// if |PackedField::N| = 8:
73-
// |first_n_powers[i]| = {1, aᵢ, ..., a⁷ᵢ}
72+
// if |PackedField::N| = 8,
73+
// |first_n_powers| = [ 1, b, b², b³,..., b⁶, b⁷ ], where b is an extension
74+
// field of |base|.
7475
ExtendedPackedField first_n_powers;
7576
T pow = T::One();
7677
for (size_t i = 0; i < PackedField::N; ++i) {
@@ -80,15 +81,17 @@ class ExtensionFieldBase {
8081
pow *= base;
8182
}
8283

83-
// |multiplier[j]| = {a⁸ⱼ, a⁸ⱼ, ..., a⁸ⱼ, a⁸ⱼ}
84+
// |multiplier| = [ b⁸, b⁸, ..., b⁸, b⁸ ], where b is an extension field of
85+
// |base|. #|multiplier| = 8
8486
ExtendedPackedField multiplier;
8587
for (size_t i = 0; i < PackedField::N; ++i) {
8688
for (uint32_t j = 0; j < kDegree; ++j) {
8789
multiplier[j][i] = pow[j];
8890
}
8991
}
9092

91-
// |ret[i]| = {(a⁸ᵢ)ⁱ, aᵢ * (a⁸ᵢ)ⁱ, ..., a⁷ᵢ * (a⁸ᵢ)ⁱ}
93+
// |ret[i]| = [ b⁸ⁱ, b⁸ⁱ⁺¹, ..., b⁸ⁱ⁺⁶, b⁸ⁱ⁺⁷ ], where b is an extension
94+
// field of |base|.
9295
std::vector<ExtendedPackedField> ret;
9396
ret.reserve(size);
9497
ret.emplace_back(first_n_powers);

0 commit comments

Comments
 (0)