|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Generic implementation of a log-derivative based lookup relation. More...
#include <generic_lookup_relation.hpp>
Public Types | |
| using | FF = FF_ |
| using | PolynomialStructure = LookupPolynomialStructure< Settings > |
Static Public Member Functions | |
| static constexpr size_t | compute_lookup_term_product_degree () |
| Compute the degree of the product of lookup terms. | |
| static constexpr size_t | compute_table_term_product_degree () |
| Compute the degree of the product of table terms. | |
| static constexpr size_t | compute_second_subrelation_degree () |
| Compute the degree of the second subrelation. | |
| template<typename AllValues > | |
| static bool | operation_exists_at_row (const AllValues &row) |
| Check if we need to compute the inverse polynomial element value for this row. | |
| template<typename AllEntities > | |
| static auto & | get_inverse_polynomial (AllEntities &in) |
| Get the inverse permutation polynomial. | |
| template<typename Accumulator , typename AllEntities > | |
| static Accumulator | compute_inverse_exists (const AllEntities &in) |
| Get selector/wire switching on (1) or off (0) inverse computation. | |
| template<typename Accumulator , size_t index, typename AllEntities > | |
| static Accumulator | lookup_read_counts (const AllEntities &in) |
| Get the number of times a particular table value has been looked up. | |
| template<typename Accumulator , size_t lookup_index, typename AllEntities > | |
| static Accumulator | get_lookup_term_predicate (const AllEntities &in) |
| Extract predicate enabling looking up a given lookup term at this row. | |
| template<typename Accumulator , size_t table_index, typename AllEntities > | |
| static Accumulator | get_table_term_predicate (const AllEntities &in) |
| Extract predicate enabling looking up a given table term at this row. | |
| template<typename Accumulator , size_t lookup_index, typename AllEntities , typename Parameters > | |
| static Accumulator | compute_lookup_term (const AllEntities &in, const Parameters ¶ms) |
| Compute the value of the lookup term at a given index. | |
| template<typename Accumulator , size_t table_index, typename AllEntities , typename Parameters > | |
| static Accumulator | compute_table_term (const AllEntities &in, const Parameters ¶ms) |
| Compute the value of a table term at a given index. | |
| template<typename ContainerOverSubrelations , typename AllEntities , typename Parameters > | |
| static void | accumulate (ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters ¶ms, const FF &scaling_factor) |
| Compute generic log-derivative lookup subrelation accumulation. | |
Static Public Attributes | |
| static constexpr size_t | NUM_LOOKUP_TERMS = Settings::NUM_LOOKUP_TERMS |
| static constexpr size_t | NUM_TABLE_TERMS = Settings::NUM_TABLE_TERMS |
| static constexpr size_t | LOOKUP_TUPLE_SIZE = Settings::LOOKUP_TUPLE_SIZE |
| static constexpr size_t | LOOKUP_TERM_ACCUMULATED_DEGREE = compute_lookup_term_product_degree() |
| static constexpr size_t | TABLE_TERM_ACCUMULATED_DEGREE = compute_table_term_product_degree() |
| static constexpr size_t | FIRST_RELATION_PARTIAL_LENGTH |
| static constexpr size_t | SECOND_RELATION_PARTIAL_LENGTH |
| static constexpr size_t | LENGTH = std::max(FIRST_RELATION_PARTIAL_LENGTH, SECOND_RELATION_PARTIAL_LENGTH) |
| static constexpr std::array< size_t, 2 > | SUBRELATION_PARTIAL_LENGTHS { LENGTH, LENGTH } |
| static constexpr std::array< bool, 2 > | SUBRELATION_LINEARLY_INDEPENDENT = { true, false } |
Generic implementation of a log-derivative based lookup relation.
The following is a generic implementation of a log-derivative based lookup relation that allows the implementor to highly customize the lookup operations performed. For ease of use, the struct implements a default lookup argument with column batching, see below for more details.
The implementor is expected to provide two template parameters:
Write \(f_1, \ldots, f_n\) for the columns to be looked up, and \(t_1, \ldots, t_m\) for the table columns. The relation implements the log-derivative lookup argument for two cases:
\[ \sum_{x \in H_N} \frac{1}{\gamma - f(x, \beta)} = \sum_{x \in H_N} \frac{\text{counts}(x)}{\gamma - t(x, \beta)} \]
In both cases, we rephrase the equation check in terms of two relations:
\[ I(x) \cdot \prod_{i=1}^{\text{NUM_LOOKUP_TERMS}} \text{lookup_entry}_i(x) \cdot \prod_{i=0}^{\text{NUM_TABLE_TERMS}} \text{table_entry}_i(x) - \text{inverse_exists}(x) = 0 \]
\[ \sum_{i=0}^{\text{NUM_LOOKUP_TERMS}} \text{lookup_entry_predicate}_i(x) \cdot \frac{1}{\text{lookup_entry}_i(x)} - \sum_{i=0}^{\text{NUM_TABLE_TERMS}} \text{table_entry_predicate}_i(x) \cdot \text{lookup_read_count}_i(x) \cdot \frac{1}{\text{table_entry}_i(x)} \]
The first relation ensures that the polynomial \(I\) represents the inverse of the product of the entries to be looked up and the table entries. As this polynomial doesn't need to be defined everywhere, we set the result of the multiplication to be equal to the value of another polynomial: inverse_exist, which is set to 1 only if the inverse must be computed. Note that relation 1) is independent: it must be satisfied at every row in the trace.
The second relation is a dependent relation, it is satisfied only when its values are summed over the entire trace. The result of the sum is the log-derivative expression that bears witness to the validity of the lookup. Note that the lookup and table entries are multiplied by predicates that enable specifying which table lookup/table entries the prover is allowed to use at any given row.
The degrees of the above relations are:
\[ \frac{1}{\text{table_entry}_i(x)} = I(x) \cdot \prod_{j \neq i} \text{table_entry}_j(x) \cdot \prod_{j} \text{lookup_entry}_j(x) \]
Definition at line 242 of file generic_lookup_relation.hpp.
| using bb::GenericLookupRelationImpl< Settings, FF_ >::FF = FF_ |
Definition at line 244 of file generic_lookup_relation.hpp.
| using bb::GenericLookupRelationImpl< Settings, FF_ >::PolynomialStructure = LookupPolynomialStructure<Settings> |
Definition at line 245 of file generic_lookup_relation.hpp.
|
inlinestatic |
Compute generic log-derivative lookup subrelation accumulation.
The generic log-derivative lookup relation consists of two subrelations. The first demonstrates that the inverse polynomial I has been computed correctly. The second establishes the correctness of the lookups themselves based on the log-derivative lookup argument. Note that the latter subrelation is "linearly dependent" in the sense that it establishes that a sum across all rows of the exectution trace is zero, rather than that some expression holds independently at each row. Accordingly, this subrelation is not multiplied by a scaling factor at each accumulation step. See the documentation for GenericLookupRelationImpl for the definition of the subrelations.
| ContainerOverSubrelations | Container type for accumulating subrelation contributions |
| AllEntities | Type containing all polynomial entities |
| Parameters | Type containing relation parameters |
| accumulator | Transformed to evals + C(in(X)...)*scaling_factor |
| in | An std::array containing the fully extended Accumulator edges |
| params | Contains beta, gamma relation parameters |
| scaling_factor | Optional term to scale the evaluation before adding to evals |
Definition at line 585 of file generic_lookup_relation.hpp.
|
inlinestatic |
Get selector/wire switching on (1) or off (0) inverse computation.
| Accumulator | Accumulator type for polynomial evaluations |
| AllEntities | Type containing all polynomial entities |
| in | All entities |
Definition at line 417 of file generic_lookup_relation.hpp.
|
inlinestatic |
Compute the value of the lookup term at a given index.
| Accumulator | Accumulator type for polynomial evaluations |
| lookup_index | Index of the lookup term to compute |
| AllEntities | Type containing all polynomial entities |
| Parameters | Type containing relation parameters (beta, gamma) |
| in | All entities |
| params | Relation parameters |
Definition at line 499 of file generic_lookup_relation.hpp.
|
inlinestaticconstexpr |
Compute the degree of the product of lookup terms.
Definition at line 263 of file generic_lookup_relation.hpp.
|
inlinestaticconstexpr |
Compute the degree of the second subrelation.
Iterate over all terms and compute the maximum of the sum of the degree of all terms minus the degree of the term we are currently looking at. The degree of the subrelation is the maximum plus 3 to account for the inverse polynomial, the read count, and the table term predicate.
Definition at line 317 of file generic_lookup_relation.hpp.
|
inlinestatic |
Compute the value of a table term at a given index.
| Accumulator | Accumulator type for polynomial evaluations |
| table_index | Index of the table term to compute |
| AllEntities | Type containing all polynomial entities |
| Parameters | Type containing relation parameters (beta, gamma) |
| in | All entities |
| params | Relation parameters |
Definition at line 538 of file generic_lookup_relation.hpp.
|
inlinestaticconstexpr |
Compute the degree of the product of table terms.
Definition at line 288 of file generic_lookup_relation.hpp.
|
inlinestatic |
Get the inverse permutation polynomial.
This method needs to return a non-const reference because it's used to compute the value of the inverse polynomial
| AllEntities | Type containing all polynomial entities |
| in | All entities |
Definition at line 403 of file generic_lookup_relation.hpp.
|
inlinestatic |
Extract predicate enabling looking up a given lookup term at this row.
| Accumulator | Accumulator type for polynomial evaluations |
| lookup_index | Index of the lookup term (must be less than NUM_LOOKUP_TERMS) |
| AllEntities | Type containing all polynomial entities |
| in | All entities |
Definition at line 457 of file generic_lookup_relation.hpp.
|
inlinestatic |
Extract predicate enabling looking up a given table term at this row.
| Accumulator | Accumulator type for polynomial evaluations |
| table_index | Index of the table term (must be less than NUM_TABLE_TERMS) |
| AllEntities | Type containing all polynomial entities |
| in | All entities |
Definition at line 477 of file generic_lookup_relation.hpp.
|
inlinestatic |
Get the number of times a particular table value has been looked up.
We assume lookup read counts are independent columns and therefore do not allow customization of this method to the implementor.
| Accumulator | Accumulator type for polynomial evaluations |
| index | Index of the table term (must be less than NUM_TABLE_TERMS) |
| AllEntities | Type containing all polynomial entities |
| in | All entities |
Definition at line 437 of file generic_lookup_relation.hpp.
|
inlinestatic |
Check if we need to compute the inverse polynomial element value for this row.
| AllValues | Type containing all polynomial values at a given row |
| row | All values at row |
Definition at line 388 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 365 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 371 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 360 of file generic_lookup_relation.hpp.
|
staticconstexpr |
When performing a basic lookup, we batch columns for efficiency. This constant represents the number of columns to be batched together. For example, it would be 1 for a range constraint lookup, 3 for a XOR lookup.
Definition at line 256 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 247 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 248 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 369 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 379 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 375 of file generic_lookup_relation.hpp.
|
staticconstexpr |
Definition at line 361 of file generic_lookup_relation.hpp.