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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
12
13#include <memory>
14
15namespace bb {
16
17template <typename Flavor>
19 const typename Flavor::CircuitBuilder& circuit,
20 const size_t dyadic_circuit_size,
21 const size_t additional_offset = 0)
22{
23 // Create lookup selector polynomials which interpolate each table column.
24 // Our selector polys always need to interpolate the full subgroup size, so here we offset so as to
25 // put the table column's values at the end. (The first gates are for non-lookup constraints).
26 // [0, ..., 0, ...table, 0, 0, 0, x]
27 // ^^^^^^^^^ ^^^^^^^^ ^^^^^^^ ^nonzero to ensure uniqueness and to avoid infinity commitments
28 // | table randomness
29 // ignored, as used for regular constraints and padding to the next power of 2.
30 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
31 const size_t tables_size = circuit.get_tables_size();
32 BB_ASSERT_GT(dyadic_circuit_size, tables_size + additional_offset);
33 size_t offset = circuit.blocks.lookup.trace_offset();
34
35 for (const auto& table : circuit.lookup_tables) {
36 const fr table_index(table.table_index);
37
38 for (size_t i = 0; i < table.size(); ++i) {
39 table_polynomials[0].at(offset) = table.column_1[i];
40 table_polynomials[1].at(offset) = table.column_2[i];
41 table_polynomials[2].at(offset) = table.column_3[i];
42 table_polynomials[3].at(offset) = table_index;
43 ++offset;
44 }
45 }
46}
47
55template <typename Flavor>
57 typename Flavor::Polynomial& read_tags,
58 typename Flavor::CircuitBuilder& circuit,
59 [[maybe_unused]] const size_t dyadic_circuit_size)
60{
61 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
62 size_t table_offset = circuit.blocks.lookup.trace_offset();
63
64 // loop over all tables used in the circuit; each table contains data about the lookups made on it
65 for (auto& table : circuit.lookup_tables) {
66 table.initialize_index_map();
67
68 for (auto& gate_data : table.lookup_gates) {
69 // convert lookup gate data to an array of three field elements, one for each of the 3 columns
70 auto table_entry = gate_data.to_table_components(table.use_twin_keys);
71
72 // find the index of the entry in the table
73 auto index_in_table = table.index_map[table_entry];
74
75 // increment the read count at the corresponding index in the full polynomial
76 size_t index_in_poly = table_offset + index_in_table;
77 read_counts.at(index_in_poly)++;
78 read_tags.at(index_in_poly) = 1; // tag is 1 if entry has been read 1 or more times
79 }
80 table_offset += table.size(); // set the offset of the next table within the polynomials
81 }
82}
83
84} // namespace bb
#define BB_ASSERT_GT(left, right,...)
Definition assert.hpp:87
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
std::vector< plookup::BasicTable > lookup_tables
size_t get_tables_size() const
Get combined size of all tables used in circuit.
ssize_t offset
Definition engine.cpp:36
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
Entry point for Barretenberg command-line interface.
void construct_lookup_table_polynomials(const RefArray< typename Flavor::Polynomial, 4 > &table_polynomials, const typename Flavor::CircuitBuilder &circuit, const size_t dyadic_circuit_size, const size_t additional_offset=0)
void construct_lookup_read_counts(typename Flavor::Polynomial &read_counts, typename Flavor::Polynomial &read_tags, typename Flavor::CircuitBuilder &circuit, const size_t dyadic_circuit_size)
Construct polynomial whose value at index i is the number of times the table entry at that index has ...