Skip to content

Commit

Permalink
refac(zk): move Evaluate() func from PermutationComitted to its `…
Browse files Browse the repository at this point in the history
…Runner`

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 1186050 commit d06df37
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
5 changes: 2 additions & 3 deletions tachyon/zk/plonk/permutation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ tachyon_cc_library(
":grand_product_argument",
":permutation_argument",
":permutation_committed",
":permutation_evaluated",
":permutation_proving_key",
":permutation_table_store",
"//tachyon/base:logging",
"//tachyon/base:parallelize",
"//tachyon/zk/base:blinded_polynomial",
"//tachyon/zk/base:prover",
"//tachyon/zk/base:ref",
],
)
Expand All @@ -71,7 +70,7 @@ tachyon_cc_library(
tachyon_cc_library(
name = "permutation_committed",
hdrs = ["permutation_committed.h"],
deps = [":permutation_evaluated"],
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 @@ -16,6 +16,7 @@
#include "tachyon/zk/plonk/circuit/table.h"
#include "tachyon/zk/plonk/permutation/permutation_argument.h"
#include "tachyon/zk/plonk/permutation/permutation_committed.h"
#include "tachyon/zk/plonk/permutation/permutation_evaluated.h"
#include "tachyon/zk/plonk/permutation/permutation_proving_key.h"

namespace tachyon::zk {
Expand All @@ -37,6 +38,11 @@ class PermutationArgumentRunner {
const PermutationProvingKey<PCSTy>& permutation_proving_key,
const F& beta, const F& gamma);

template <typename PCSTy, typename ExtendedDomain, typename F>
static PermutationEvaluated<Poly> EvaluateCommitted(
Prover<PCSTy, ExtendedDomain>* prover,
PermutationCommitted<Poly>&& committed, const F& x);

private:
template <typename F>
static std::function<base::ParallelizeCallback3<F>(size_t)>
Expand Down
33 changes: 33 additions & 0 deletions tachyon/zk/plonk/permutation/permutation_argument_runner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ PermutationArgumentRunner<Poly, Evals>::CommitArgument(
return PermutationCommitted<Poly>(std::move(grand_product_polys));
}

template <typename Poly, typename Evals>
template <typename PCSTy, typename ExtendedDomain, typename F>
PermutationEvaluated<Poly>
PermutationArgumentRunner<Poly, Evals>::EvaluateCommitted(
Prover<PCSTy, ExtendedDomain>* prover,
PermutationCommitted<Poly>&& committed, const F& x) {
int32_t blinding_factors =
static_cast<int32_t>(prover->blinder().blinding_factors());

std::vector<BlindedPolynomial<Poly>> product_polys =
std::move(committed).product_polys();

for (size_t i = 0; i < product_polys.size(); ++i) {
const Poly& poly = product_polys[i].poly();

prover->Evaluate(poly, x);

F x_next = Rotation::Next().RotateOmega(prover->domain(), x);
prover->Evaluate(poly, x_next);

// If we have any remaining sets to process, evaluate this set at ωᵘ
// so we can constrain the last value of its running product to equal the
// first value of the next set's running product, chaining them together.
if (i != product_polys.size() - 1) {
F x_last =
Rotation(-(blinding_factors + 1)).RotateOmega(prover->domain(), x);
prover->Evaluate(poly, x_last);
}
}

return PermutationEvaluated<Poly>(std::move(product_polys));
}

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

#include "tachyon/zk/base/blinded_polynomial.h"
#include "tachyon/zk/base/prover.h"
#include "tachyon/zk/plonk/permutation/permutation_evaluated.h"

namespace tachyon::zk {

Expand All @@ -24,35 +22,8 @@ class PermutationCommitted {
std::vector<BlindedPolynomial<Poly>> product_polys)
: product_polys_(std::move(product_polys)) {}

const std::vector<BlindedPolynomial<Poly>>& product_polys() const {
return product_polys_;
}

template <typename PCSTy, typename ExtendedDomain, typename F>
PermutationEvaluated<Poly> Evaluate(Prover<PCSTy, ExtendedDomain>* prover,
const F& x) && {
int32_t blinding_factors =
static_cast<int32_t>(prover->blinder().blinding_factors());

for (size_t i = 0; i < product_polys_.size(); ++i) {
const Poly& poly = product_polys_[i].poly();

prover->Evaluate(poly, x);

F x_next = Rotation::Next().RotateOmega(prover->domain(), x);
prover->Evaluate(poly, x_next);

// If we have any remaining sets to process, evaluate this set at ωᵘ
// so we can constrain the last value of its running product to equal the
// first value of the next set's running product, chaining them together.
if (i != product_polys_.size() - 1) {
F x_last =
Rotation(-(blinding_factors + 1)).RotateOmega(prover->domain(), x);
prover->Evaluate(poly, x_last);
}
}

return PermutationEvaluated<Poly>(std::move(product_polys_));
std::vector<BlindedPolynomial<Poly>>&& product_polys() && {
return std::move(product_polys_);
}

private:
Expand Down

0 comments on commit d06df37

Please sign in to comment.