Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
composer_lib.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Raju], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
11
12namespace bb {
13
23template <typename Flavor>
25 const typename Flavor::CircuitBuilder& circuit)
26{
27 size_t offset = circuit.blocks.lookup.trace_offset();
28 for (const auto& table : circuit.get_lookup_tables()) {
29 for (size_t i = 0; i < table.size(); ++i) {
30 table_polynomials[0].at(offset) = table.column_1[i];
31 table_polynomials[1].at(offset) = table.column_2[i];
32 table_polynomials[2].at(offset) = table.column_3[i];
33 table_polynomials[3].at(offset) = table.table_index;
34 offset++;
35 }
36 }
37 BB_ASSERT(offset <= table_polynomials[0].end_index(),
38 "construct_lookup_table_polynomials: total lookup table entries exceed polynomial size");
39}
40
48template <typename Flavor>
50 typename Flavor::Polynomial& read_tags,
51 typename Flavor::CircuitBuilder& circuit)
52{
53 // loop over all tables used in the circuit; each table contains data about the lookups made on it
54 size_t table_offset = circuit.blocks.lookup.trace_offset();
55 for (auto& table : circuit.get_lookup_tables()) {
56 table.initialize_index_map();
57
58 for (auto& gate_data : table.lookup_gates) {
59 // convert lookup gate data to an array of three field elements, one for each of the 3 columns
60 auto table_entry = gate_data.to_table_components(table.use_twin_keys);
61
62 // find the index of the entry in the table
63 auto index_in_table = table.index_map[table_entry];
64
65 // increment the read count at the corresponding index in the full polynomial
66 size_t index_in_poly = table_offset + index_in_table;
67 read_counts.at(index_in_poly)++;
68 read_tags.at(index_in_poly) = 1; // tag is 1 if entry has been read 1 or more times
69 }
70 table_offset += table.size(); // set the offset of the next table within the polynomials
71 }
72}
73
74} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
ssize_t offset
Definition engine.cpp:62
Base class templates shared across Honk flavors.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
void construct_lookup_table_polynomials(const RefArray< typename Flavor::Polynomial, 4 > &table_polynomials, const typename Flavor::CircuitBuilder &circuit)
Construct polynomials containing the concatenation of all lookup tables used in the circuit.
void construct_lookup_read_counts(typename Flavor::Polynomial &read_counts, typename Flavor::Polynomial &read_tags, typename Flavor::CircuitBuilder &circuit)
Construct polynomial whose value at index i is the number of times the table entry at that index has ...