Skip to content

Commit

Permalink
refac(zk): move Open() func from PermutationEvaluated to its `Run…
Browse files Browse the repository at this point in the history
…ner`

This commit gathers the transition functions of the permutation
into the `PermutationArgumentRunner` to enhance the readability of the protocol.
  • Loading branch information
dongchangYoo committed Dec 1, 2023
1 parent d06df37 commit 774c318
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
9 changes: 3 additions & 6 deletions tachyon/zk/plonk/permutation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ tachyon_cc_library(
":permutation_table_store",
"//tachyon/base:logging",
"//tachyon/base:parallelize",
"//tachyon/zk/base:prover_query",
"//tachyon/zk/base:ref",
"//tachyon/zk/plonk/circuit:rotation",
],
)

Expand All @@ -76,12 +78,7 @@ tachyon_cc_library(
tachyon_cc_library(
name = "permutation_evaluated",
hdrs = ["permutation_evaluated.h"],
deps = [
"//tachyon/zk/base:blinded_polynomial",
"//tachyon/zk/base:prover",
"//tachyon/zk/base:prover_query",
"//tachyon/zk/plonk/circuit:rotation",
],
deps = ["//tachyon/zk/base:blinded_polynomial"],
)

tachyon_cc_library(
Expand Down
6 changes: 6 additions & 0 deletions tachyon/zk/plonk/permutation/permutation_argument_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "tachyon/base/parallelize.h"
#include "tachyon/zk/base/prover.h"
#include "tachyon/zk/base/prover_query.h"
#include "tachyon/zk/base/ref.h"
#include "tachyon/zk/plonk/circuit/table.h"
#include "tachyon/zk/plonk/permutation/permutation_argument.h"
Expand Down Expand Up @@ -43,6 +44,11 @@ class PermutationArgumentRunner {
Prover<PCSTy, ExtendedDomain>* prover,
PermutationCommitted<Poly>&& committed, const F& x);

template <typename PCSTy, typename ExtendedDomain, typename F>
static std::vector<ProverQuery<PCSTy>> OpenEvaluated(
const Prover<PCSTy, ExtendedDomain>* prover,
const PermutationEvaluated<Poly>& evaluated, const F& x);

private:
template <typename F>
static std::function<base::ParallelizeCallback3<F>(size_t)>
Expand Down
28 changes: 28 additions & 0 deletions tachyon/zk/plonk/permutation/permutation_argument_runner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "tachyon/base/logging.h"
#include "tachyon/zk/base/blinded_polynomial.h"
#include "tachyon/zk/plonk/circuit/rotation.h"
#include "tachyon/zk/plonk/permutation/grand_product_argument.h"
#include "tachyon/zk/plonk/permutation/permutation_argument_runner.h"
#include "tachyon/zk/plonk/permutation/permutation_table_store.h"
Expand Down Expand Up @@ -107,6 +108,33 @@ PermutationArgumentRunner<Poly, Evals>::EvaluateCommitted(
return PermutationEvaluated<Poly>(std::move(product_polys));
}

template <typename Poly, typename Evals>
template <typename PCSTy, typename ExtendedDomain, typename F>
std::vector<ProverQuery<PCSTy>>
PermutationArgumentRunner<Poly, Evals>::OpenEvaluated(
const Prover<PCSTy, ExtendedDomain>* prover,
const PermutationEvaluated<Poly>& evaluated, const F& x) {
const std::vector<BlindedPolynomial<Poly>>& product_polys =
evaluated.product_polys();

std::vector<ProverQuery<PCSTy>> ret;
ret.reserve(product_polys.size() * 3 - 1);

F x_next = Rotation::Next().RotateOmega(prover->domain(), x);
for (const BlindedPolynomial<Poly>& blinded_poly : product_polys) {
ret.emplace_back(x, blinded_poly.ToRef());
ret.emplace_back(x_next, blinded_poly.ToRef());
}

int32_t blinding_factors =
static_cast<int32_t>(prover->blinder().blinding_factors());
F x_last = Rotation(-(blinding_factors + 1)).RotateOmega(prover->domain(), x);
for (auto it = product_polys.rbegin() + 1; it != product_polys.rend(); ++it) {
ret.emplace_back(x_last, it->ToRef());
}
return std::move(ret);
}

template <typename Poly, typename Evals>
template <typename F>
std::function<base::ParallelizeCallback3<F>(size_t)>
Expand Down
26 changes: 0 additions & 26 deletions tachyon/zk/plonk/permutation/permutation_evaluated.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <vector>

#include "tachyon/zk/base/blinded_polynomial.h"
#include "tachyon/zk/base/prover.h"
#include "tachyon/zk/base/prover_query.h"
#include "tachyon/zk/plonk/circuit/rotation.h"

namespace tachyon::zk {

Expand All @@ -29,29 +26,6 @@ class PermutationEvaluated {
return product_polys_;
}

template <typename PCSTy, typename ExtendedDomain, typename F>
std::vector<ProverQuery<PCSTy>> Open(
const Prover<PCSTy, ExtendedDomain>* prover, const F& x) const {
std::vector<ProverQuery<PCSTy>> ret;
ret.reserve(product_polys_.size() * 3 - 1);

F x_next = Rotation::Next().RotateOmega(prover->domain(), x);
for (const BlindedPolynomial<Poly>& blinded_poly : product_polys_) {
ret.emplace_back(x, blinded_poly.ToRef());
ret.emplace_back(x_next, blinded_poly.ToRef());
}

int32_t blinding_factors =
static_cast<int32_t>(prover->blinder().blinding_factors());
F x_last =
Rotation(-(blinding_factors + 1)).RotateOmega(prover->domain(), x);
for (auto it = product_polys_.rbegin() + 1; it != product_polys_.rend();
++it) {
ret.emplace_back(x_last, it->ToRef());
}
return ret;
}

private:
std::vector<BlindedPolynomial<Poly>> product_polys_;
};
Expand Down

0 comments on commit 774c318

Please sign in to comment.