-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk): implement lookup verification evaluations
See [Evaluated<C>::expressions()](https://github.com/kroma-network/halo2/blob/7d0a36990452c8e7ebd600de258420781a9b7917/halo2_proofs/src/plonk/lookup/verifier.rs#L92-L168).
- Loading branch information
Showing
8 changed files
with
182 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2020-2022 The Electric Coin Company | ||
// Copyright 2022 The Halo2 developers | ||
// Use of this source code is governed by a MIT/Apache-2.0 style license that | ||
// can be found in the LICENSE-MIT.halo2 and the LICENCE-APACHE.halo2 | ||
// file. | ||
|
||
#ifndef TACHYON_ZK_LOOKUP_LOOKUP_VERIFICATION_H_ | ||
#define TACHYON_ZK_LOOKUP_LOOKUP_VERIFICATION_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "tachyon/zk/lookup/lookup_argument.h" | ||
#include "tachyon/zk/lookup/lookup_verification_data.h" | ||
#include "tachyon/zk/plonk/vanishing/vanishing_verification_evaluator.h" | ||
|
||
namespace tachyon::zk { | ||
|
||
template <typename F> | ||
F CompressExpressions( | ||
const std::vector<std::unique_ptr<Expression<F>>>& expressions, | ||
const F& theta, VanishingVerificationEvaluator<F>& evaluator) { | ||
F compressed_value = F::Zero(); | ||
for (size_t expr_idx = 0; expr_idx < expressions.size(); ++expr_idx) { | ||
compressed_value *= theta; | ||
compressed_value += evaluator.Evaluate(expressions[expr_idx].get()); | ||
} | ||
return compressed_value; | ||
} | ||
|
||
template <typename F> | ||
F CreateProductExpression(const LookupVerificationData<F>& data, | ||
const LookupArgument<F>& argument) { | ||
VanishingVerificationEvaluator<F> evaluator(data); | ||
// z(ω * X) * (a'(X) + β) * (s'(X) + γ) | ||
// - z(X) * (θᵐ⁻¹a₀(X) + ... + aₘ₋₁(X) + β) * (θᵐ⁻¹s₀(X) + ... + sₘ₋₁(X) + γ) | ||
F left = data.product_next_eval * (data.permuted_input_eval + data.beta) * | ||
(data.permuted_table_eval + data.gamma); | ||
F compressed_input_expression = | ||
CompressExpressions(argument.input_expressions(), data.theta, evaluator); | ||
F compressed_table_expression = | ||
CompressExpressions(argument.table_expressions(), data.theta, evaluator); | ||
F right = data.product_eval * (compressed_input_expression + data.beta) * | ||
(compressed_table_expression + data.gamma); | ||
return left - right; | ||
} | ||
|
||
constexpr size_t GetSizeOfLookupVerificationExpressions() { return 5; } | ||
|
||
template <typename F> | ||
std::vector<F> CreateLookupVerificationExpressions( | ||
const LookupVerificationData<F>& data, const LookupArgument<F>& argument) { | ||
F active_rows = F::One() - (data.l_last + data.l_blind); | ||
std::vector<F> ret; | ||
ret.reserve(GetSizeOfLookupVerificationExpressions()); | ||
// l_first(X) * (1 - z'(X)) = 0 | ||
ret.push_back(data.l_first * (F::One() - data.product_eval)); | ||
// l_last(X) * (z(X)² - z(X)) = 0 | ||
ret.push_back(data.l_last * (data.product_eval.Square() - data.product_eval)); | ||
// (1 - (l_last(X) + l_blind(X))) * ( | ||
// z(ω * X) * (a'(X) + β) * (s'(X) + γ) | ||
// - z(X) (θᵐ⁻¹a₀(X) + ... + aₘ₋₁(X) + β) (θᵐ⁻¹s₀(X) + ... + sₘ₋₁(X) + γ) | ||
// ) = 0 | ||
ret.push_back(active_rows * CreateProductExpression(data, argument)); | ||
// l_first(X) * (a'(X) - s'(X)) = 0 | ||
ret.push_back(data.l_first * | ||
(data.permuted_input_eval - data.permuted_table_eval)); | ||
// (1 - (l_last(X) + l_blind(X))) * | ||
// (a′(X) − s′(X)) * (a′(X) − a′(ω⁻¹ * X)) = 0 | ||
ret.push_back(active_rows * | ||
(data.permuted_input_eval - data.permuted_table_eval) * | ||
(data.permuted_input_eval - data.permuted_input_inv_eval)); | ||
return ret; | ||
} | ||
|
||
} // namespace tachyon::zk | ||
|
||
#endif // TACHYON_ZK_LOOKUP_LOOKUP_VERIFICATION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef TACHYON_ZK_LOOKUP_LOOKUP_VERIFICATION_DATA_H_ | ||
#define TACHYON_ZK_LOOKUP_LOOKUP_VERIFICATION_DATA_H_ | ||
|
||
#include "tachyon/zk/plonk/vanishing/vanishing_verification_data.h" | ||
|
||
namespace tachyon::zk { | ||
|
||
template <typename F> | ||
struct LookupVerificationData : public VanishingVerificationData<F> { | ||
F product_eval; | ||
F product_next_eval; | ||
F permuted_input_eval; | ||
F permuted_input_inv_eval; | ||
F permuted_table_eval; | ||
F theta; | ||
F beta; | ||
F gamma; | ||
F x; | ||
F l_first; | ||
F l_blind; | ||
F l_last; | ||
}; | ||
|
||
} // namespace tachyon::zk | ||
|
||
#endif // TACHYON_ZK_LOOKUP_LOOKUP_VERIFICATION_DATA_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters