-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(zk): implement LogUp scheme #420
base: main
Are you sure you want to change the base?
Conversation
feb2a27
to
e0f3423
Compare
35d5ddf
to
8a314d3
Compare
d144562
to
6f6be38
Compare
71cf1d6
to
ca0d474
Compare
tachyon/zk/lookup/lookup_argument.h
Outdated
// clang-format off | ||
// (1 - (l_last + l_blind)) * Z(X) * (A_compressed(X) + β) * (S_compressed(X) + γ) | ||
// clang-format on | ||
size_t{2} + max_input_degree + max_table_degree); | ||
} | ||
|
||
private: | ||
static size_t GetExprDegree( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about renaming it to GetExprMaxDegree()
tachyon/zk/lookup/lookup_argument.h
Outdated
std::vector<std::vector<std::unique_ptr<Expression<F>>>> inputs_expressions_ = | ||
{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<std::vector<std::unique_ptr<Expression<F>>>> inputs_expressions_ = | |
{}; | |
std::vector<std::vector<std::unique_ptr<Expression<F>>>> inputs_expressions_; |
return lookup_pairs; | ||
}); | ||
|
||
EXPECT_EQ(constraint_system.lookups().size() - 1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_EQ(constraint_system.lookups().size() - 1, 0); | |
EXPECT_EQ(constraint_system.lookups().size() , 1); |
return lookup_pairs; | ||
}); | ||
|
||
EXPECT_EQ(constraint_system.lookups().size() - 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_EQ(constraint_system.lookups().size() - 1, 1); | |
EXPECT_EQ(constraint_system.lookups().size(), 2); |
return lookup_pairs; | ||
}); | ||
|
||
EXPECT_EQ(constraint_system.lookups().size() - 1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_EQ(constraint_system.lookups().size() - 1, 0); | |
EXPECT_EQ(constraint_system.lookups().size(), 1); |
#include <memory> | ||
#include <ostream> | ||
#include <string> | ||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <memory> | |
#include <ostream> | |
#include <string> | |
#include <vector> | |
#include <ostream> | |
#include <string> |
template <typename LookupTracker> | ||
class RustDebugStringifier<absl::btree_map<std::string, LookupTracker>> { | ||
public: | ||
static std::ostream& AppendToStream( | ||
std::ostream& os, RustFormatter& fmt, | ||
const absl::btree_map<std::string, LookupTracker>& lookups_map) { | ||
DebugMap debug_map = fmt.DebugMap(); | ||
for (const auto& [key, value] : lookups_map) { | ||
debug_map.Pair(key, value); | ||
} | ||
return os << debug_map.Finish(); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be defined as RustDebugStringifier<absl::btree_map<K, V>>
and moved to somewhere else.
#include "absl/container/btree_map.h" | ||
|
||
#include "tachyon/base/strings/rust_stringifier.h" | ||
#include "tachyon/zk/plonk/constraint_system/lookup_tracker.h" | ||
#include "tachyon/zk/plonk/halo2/stringifiers/expression_stringifier.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please match deps with header and apply these changes to all.
@@ -0,0 +1,53 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this blank
tachyon/zk/lookup/logup/scheme.h
Outdated
|
||
using Prover = lookup::logup::Prover<Poly, Evals>; | ||
|
||
static constexpr Type type = Type::kLogUp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minor , but please use constexpr
first!
static constexpr Type type = Type::kLogUp; | |
constexpr static Type type = Type::kLogUp; |
Please remove this statement from the commit body of feat(zk): add constraint_system lookup logic for LookupsMap
|
Please add links to the rust reference code to every single commit! |
You need to add license of Geometry Research. Does Scroll take this code from here, right? |
Please change the type of fix(zk): fix wrong iterator access, feat(zk): add circuit test flags for LogUp and feat(zk): implement MultiLookupCircuit to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update all the comments in RequiredDegree()
.
// τ(X) = t(X) + β | ||
// LHS = τ(X) * Π(φᵢ(X)) * (ϕ(ω * X) - ϕ(X)) | ||
// = max_table_degree + max_input_degree + 1 | ||
// RHS = τ(X) * Π(φᵢ(X)) * ((Σ 1/φᵢ(X)) - m(X) / τ(X)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// RHS = τ(X) * Π(φᵢ(X)) * ((Σ 1/φᵢ(X)) - m(X) / τ(X)) | |
// RHS = τ(X) * Π(φᵢ(X)) * ((Σ 1/φᵢ(X)) - m(X) / τ(X)) | |
// = max_input_degree + 1 |
tachyon/zk/lookup/lookup_argument.h
Outdated
@@ -108,16 +137,13 @@ class Argument { | |||
// (1 - (l_last(X) + l_blind(X))) * (A′(X) − S′(X)) * (A′(X) − A′(ω⁻¹ * X)) = 0 | |||
// clang-format on | |||
size_t max_input_degree = std::accumulate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size_t max_input_degree = std::accumulate( | |
size_t max_input_degree_sum = std::accumulate( |
}); | ||
lookup::Pairs<std::unique_ptr<Expression<F>>, LookupTableColumn> pairs = | ||
std::move(callback).Run(cells); | ||
if (lookup_type_ == lookup::Type::kHalo2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use switch statement.
@@ -565,6 +713,39 @@ class ConstraintSystem { | |||
FRIEND_TEST(ConstraintSystemTest, Lookup); | |||
FRIEND_TEST(ConstraintSystemTest, LookupAny); | |||
|
|||
template <typename VirtualCells> | |||
std::unique_ptr<Expression<F>> MakeTable( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this to VirtualCells
and changing the function name to QueryLookupTable
?
"lhs", config_.a(), 0, [&values]() { return values[0]; }); | ||
ret.push_back(lhs); | ||
|
||
region.AssignAdvice("lhs^4", config_.d(), 0, [&values]() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
region.AssignAdvice("lhs^4", config_.d(), 0, [&values]() { | |
region.AssignAdvice("lhs⁴", config_.d(), 0, [&values]() { |
"rhs", config_.b(), 0, [&values]() { return values[1]; }); | ||
ret.push_back(rhs); | ||
|
||
region.AssignAdvice("rhs^4", config_.e(), 0, [&values]() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
region.AssignAdvice("rhs^4", config_.e(), 0, [&values]() { | |
region.AssignAdvice("rhs⁴", config_.e(), 0, [&values]() { |
|
||
AssignedCell<F> rhs = region.AssignAdvice( | ||
"rhs", config_.b(), 0, [&values]() { return values[1]; }); | ||
ret.push_back(rhs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret.push_back(rhs); | |
ret.push_back(std::move(rhs)); |
ret.push_back(rhs); | ||
|
||
region.AssignAdvice("rhs^4", config_.e(), 0, [&values]() { | ||
return values[1].SquareImpl().SquareImpl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return values[1].SquareImpl().SquareImpl(); | |
return values[1].Pow(4); |
|
||
AssignedCell<F> out = region.AssignAdvice( | ||
"out", config_.c(), 0, [&values]() { return values[2]; }); | ||
ret.push_back(out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret.push_back(out); | |
ret.push_back(std::move(out)); |
Change input expression interface in lookup argument to support Logup scheme.
Change return type of `Lookup()` and `LookupAny()` from size_t (size of lookups) to void, because it is redundant.
CloneExpressions function clones a vector of `std::unique_ptr<Expression>`. It is needed to handle both lookups and lookups_map in LogUp.
62bf7f2
to
56a3412
Compare
Add `Lookup()`, `LookupAny()`, and `ChunkLookup()` for LogUp scheme. Constraint system select a logic dynamically using lookup type. - LookupTracker: holds table and input expressions with its name - LookupsMap: btree_map with table_expressions_identifier as a key and LookupTracker as values.
Add btree_map_stringifier and lookup_tracker_stringifier.
MultiLookupCircuit to be introduced in the following commit requires 2^8 kMaxExtendedDomainSize.
Introduce MultiLookupCircuit for testing LogUp scheme. See https://github.com/scroll-tech/halo2/blob/1070391642dd64b2d68b47ec246cba9e35bd3c15/halo2_proofs/tests/plonk_api.rs
56a3412
to
aae25a7
Compare
Implement logarithmic derivative lookup scheme.
Logarithmic derivatives translate products of linear factors into sums of their reciprocals, turning zeroes into simple poles of same multiplicity. It reduces computation cost using grand sum argument instead of grand product argument.
See Paper 2022/1530
Referenced Scroll Halo2 implementation.
We named Logup not MVLookup because this implementation uses univariate polynomial commitment scheme.