Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
decider_proving_key.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
24#include <chrono>
25
26namespace bb {
36template <IsUltraOrMegaHonk Flavor> class DeciderProvingKey_ {
39 using FF = typename Flavor::FF;
43
44 // Flag indicating whether the polynomials will be constructed with fixed block sizes for each gate type
46
47 MetaData metadata; // circuit size and public inputs metadata
48 size_t overflow_size{ 0 }; // size of the structured execution trace overflow
49 size_t final_active_wire_idx{ 0 }; // idx of last non-trivial wire value in the trace
50
51 public:
53
54 std::vector<FF> public_inputs;
55 ProverPolynomials polynomials; // the multilinear polynomials used by the prover
56 SubrelationSeparators alphas; // a challenge for each subrelation
58 std::vector<FF> gate_challenges;
59 FF target_sum{ 0 }; // Sumcheck target sum; typically nonzero for a ProtogalaxyProver's accumulator
60
61 HonkProof ipa_proof; // utilized only for UltraRollupFlavor
62
63 bool from_first_instance = false; // whether this instance is the first one
64 bool is_complete = false; // whether this instance has been completely populated
65 std::vector<uint32_t> memory_read_records;
66 std::vector<uint32_t> memory_write_records;
67
69
70 ActiveRegionData active_region_data; // specifies active regions of execution trace
71
72 void set_dyadic_size(size_t size) { metadata.dyadic_size = size; }
73 void set_overflow_size(size_t size) { overflow_size = size; }
75 size_t dyadic_size() const { return metadata.dyadic_size; }
76 size_t log_dyadic_size() const { return numeric::get_msb(dyadic_size()); }
77 size_t pub_inputs_offset() const { return metadata.pub_inputs_offset; }
83 MetaData get_metadata() const { return metadata; }
84 size_t get_overflow_size() const { return overflow_size; }
86
88 {
89 return typename Flavor::PrecomputedData{ polynomials.get_precomputed(), metadata };
90 }
91
93 TraceSettings trace_settings = {},
95 : is_structured(trace_settings.structure.has_value())
97 {
98 PROFILE_THIS_NAME("DeciderProvingKey(Circuit&)");
99 vinfo("Constructing DeciderProvingKey");
100 auto start = std::chrono::steady_clock::now();
101 // Decider proving keys can be constructed multiple times, hence, we check whether the circuit has been
102 // finalized
103 if (!circuit.circuit_finalized) {
104 circuit.finalize_circuit(/* ensure_nonzero = */ true);
105 }
106
107 // If using a structured trace, set fixed block sizes, check their validity, and set the dyadic circuit size
109 metadata.dyadic_size = compute_dyadic_size(circuit); // set dyadic size directly from circuit block sizes
111 if (is_structured) {
112 circuit.blocks.set_fixed_block_sizes(trace_settings); // The structuring is set
113 if (verbose_logging) {
114 circuit.blocks.summarize();
115 }
117 overflow_size = circuit.blocks.overflow.size();
118 metadata.dyadic_size = compute_structured_dyadic_size(circuit); // set the dyadic size accordingly
119 } else {
120 metadata.dyadic_size = compute_dyadic_size(circuit); // set dyadic based on circuit block sizes
121 }
122 }
123
124 circuit.blocks.compute_offsets(is_structured); // compute offset of each block within the trace
125
126 // Find index of last non-trivial wire value in the trace
127 for (auto& block : circuit.blocks.get()) {
128 if (block.size() > 0) {
129 final_active_wire_idx = block.trace_offset() + block.size() - 1;
130 }
131 }
132
133 vinfo("allocating polynomials object in proving key...");
134 {
135 PROFILE_THIS_NAME("allocating proving key");
136
138
139 // If not using structured trace OR if using structured trace but overflow has occurred (overflow block in
140 // use), allocate full size polys
141 // is_structured = false;
142 if ((IsMegaFlavor<Flavor> && !is_structured) || (is_structured && circuit.blocks.has_overflow)) {
143 // Allocate full size polynomials
145 } else { // Allocate only a correct amount of memory for each polynomial
147
149
150 allocate_selectors(circuit);
151
153
155
156 if constexpr (IsMegaFlavor<Flavor>) {
158 }
159 if constexpr (HasDataBus<Flavor>) {
161 }
162 }
163 // We can finally set the shifted polynomials now that all of the to_be_shifted polynomials are
164 // defined.
165 polynomials.set_shifted(); // Ensure shifted wires are set correctly
166 }
167
168 // Construct and add to proving key the wire, selector and copy constraint polynomials
169 vinfo("populating trace...");
171
172 {
173 PROFILE_THIS_NAME("constructing prover instance after trace populate");
174
175 // If Goblin, construct the databus polynomials
176 if constexpr (IsMegaFlavor<Flavor>) {
177 PROFILE_THIS_NAME("constructing databus polynomials");
178
180 }
181 }
182 // Set the lagrange polynomials
183 polynomials.lagrange_first.at(0) = 1;
184 polynomials.lagrange_last.at(final_active_wire_idx) = 1;
185
186 {
187 PROFILE_THIS_NAME("constructing lookup table polynomials");
188
189 construct_lookup_table_polynomials<Flavor>(
190 polynomials.get_tables(), circuit, dyadic_size(), NUM_DISABLED_ROWS_IN_SUMCHECK);
191 }
192
193 {
194 PROFILE_THIS_NAME("constructing lookup read counts");
195
196 construct_lookup_read_counts<Flavor>(
197 polynomials.lookup_read_counts, polynomials.lookup_read_tags, circuit, dyadic_size());
198 }
199 { // Public inputs handling
200 metadata.num_public_inputs = circuit.blocks.pub_inputs.size();
201 metadata.pub_inputs_offset = circuit.blocks.pub_inputs.trace_offset();
202 for (size_t i = 0; i < metadata.num_public_inputs; ++i) {
203 size_t idx = i + metadata.pub_inputs_offset;
204 public_inputs.emplace_back(polynomials.w_r[idx]);
205 }
206
207 if constexpr (HasIPAAccumulator<Flavor>) { // Set the IPA claim indices
208 ipa_proof = circuit.ipa_proof;
209 }
210 }
211 auto end = std::chrono::steady_clock::now();
212 auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
213 vinfo("time to construct proving key: ", diff.count(), " ms.");
214 }
215
218
220
221 private:
222 static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0;
223 static constexpr size_t NUM_WIRES = Circuit::NUM_WIRES;
224
226
227 void allocate_wires();
228
230
232
233 void allocate_selectors(const Circuit&);
234
236
238 requires IsMegaFlavor<Flavor>;
239
241 requires HasDataBus<Flavor>;
242
247 size_t compute_structured_dyadic_size(Circuit& circuit) { return circuit.blocks.get_structured_dyadic_size(); }
248
250 requires HasDataBus<Flavor>;
251
253 requires IsMegaFlavor<Flavor>;
254
255 void populate_memory_records(const Circuit& circuit);
256};
257
258} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
CommitmentKey object over a pairing group 𝔾₁.
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
void populate_memory_records(const Circuit &circuit)
Copy RAM/ROM record of reads and writes from the circuit to the proving key.
SubrelationSeparators alphas
size_t compute_dyadic_size(Circuit &)
Helper method to compute quantities like total number of gates and dyadic circuit size.
void set_overflow_size(size_t size)
DeciderProvingKey_()=default
void set_final_active_wire_idx(size_t idx)
typename Flavor::Polynomial Polynomial
void allocate_ecc_op_polynomials(const Circuit &)
~DeciderProvingKey_()=default
std::vector< FF > gate_challenges
void allocate_databus_polynomials(const Circuit &)
std::vector< FF > public_inputs
static constexpr size_t num_zero_rows
DeciderProvingKey_(Circuit &circuit, TraceSettings trace_settings={}, const CommitmentKey &commitment_key=CommitmentKey())
typename Flavor::CircuitBuilder Circuit
size_t compute_structured_dyadic_size(Circuit &circuit)
Compute dyadic size based on a structured trace with fixed block size.
void allocate_table_lookup_polynomials(const Circuit &)
static constexpr size_t NUM_WIRES
void allocate_selectors(const Circuit &)
static void move_structured_trace_overflow_to_overflow_block(Circuit &circuit)
Check that the number of gates in each block does not exceed its fixed capacity. Move any overflow to...
size_t get_final_active_wire_idx() const
std::vector< uint32_t > memory_write_records
ActiveRegionData active_region_data
void set_dyadic_size(size_t size)
typename Flavor::ProverPolynomials ProverPolynomials
std::vector< uint32_t > memory_read_records
bb::RelationParameters< FF > relation_parameters
typename Flavor::CommitmentKey CommitmentKey
void construct_databus_polynomials(Circuit &)
Flavor::PrecomputedData get_precomputed()
typename Flavor::SubrelationSeparators SubrelationSeparators
A container for the prover polynomials handles.
Curve::ScalarField FF
bb::CommitmentKey< Curve > CommitmentKey
std::array< FF, NUM_SUBRELATIONS - 1 > SubrelationSeparators
MegaCircuitBuilder CircuitBuilder
bb::Polynomial< FF > Polynomial
static constexpr bool has_zero_row
static void populate(Builder &builder, ProverPolynomials &, ActiveRegionData &)
Given a circuit, populate a proving key with wire polys, selector polys, and sigma/id polys.
void vinfo(Args... args)
Definition log.hpp:76
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
bool verbose_logging
Definition log.cpp:6
constexpr T get_msb(const T in)
Definition get_msb.hpp:47
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
Definition proof.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
#define PROFILE_THIS_NAME(name)
Definition op_count.hpp:16
Contains various functions that help construct Honk Sigma and Id polynomials.
Dyadic trace size and public inputs metadata; Common between prover and verifier keys.
Definition flavor.hpp:129
size_t pub_inputs_offset
Definition flavor.hpp:132
size_t num_public_inputs
Definition flavor.hpp:131
size_t dyadic_size
Definition flavor.hpp:130
The precomputed data needed to compute a Honk VK.
Definition flavor.hpp:138
Container for parameters used by the grand product (permutation, lookup) Honk relations.