@@ -30,6 +30,142 @@ template <IsUltraFlavor Flavor> size_t DeciderProvingKey_<Flavor>::compute_dyadi
30
30
return circuit.get_circuit_subgroup_size (total_num_gates);
31
31
}
32
32
33
+ template <IsUltraFlavor Flavor> void DeciderProvingKey_<Flavor>::allocate_wires()
34
+ {
35
+ PROFILE_THIS_NAME (" allocate_wires" );
36
+
37
+ for (auto & wire : proving_key.polynomials .get_wires ()) {
38
+ wire = Polynomial::shiftable (proving_key.circuit_size );
39
+ }
40
+ }
41
+
42
+ template <IsUltraFlavor Flavor> void DeciderProvingKey_<Flavor>::allocate_permutation_argument_polynomials()
43
+ {
44
+ PROFILE_THIS_NAME (" allocate_permutation_argument_polynomials" );
45
+
46
+ for (auto & sigma : proving_key.polynomials .get_sigmas ()) {
47
+ sigma = Polynomial (proving_key.circuit_size );
48
+ }
49
+ for (auto & id : proving_key.polynomials .get_ids ()) {
50
+ id = Polynomial (proving_key.circuit_size );
51
+ }
52
+ proving_key.polynomials .z_perm = Polynomial::shiftable (proving_key.circuit_size );
53
+ }
54
+
55
+ template <IsUltraFlavor Flavor> void DeciderProvingKey_<Flavor>::allocate_lagrange_polynomials()
56
+ {
57
+ PROFILE_THIS_NAME (" allocate_lagrange_polynomials" );
58
+
59
+ // First and last lagrange polynomials (in the full circuit size)
60
+ proving_key.polynomials .lagrange_first = Polynomial (
61
+ /* size=*/ 1 , /* virtual size=*/ dyadic_circuit_size, /* start_index=*/ 0 );
62
+
63
+ // Even though lagrange_last has a single non-zero element, we cannot set its size to 0 as different
64
+ // keys being folded might have lagrange_last set at different indexes and folding does not work
65
+ // correctly unless the polynomial is allocated in the correct range to accomodate this
66
+ proving_key.polynomials .lagrange_last = Polynomial (
67
+ /* size=*/ dyadic_circuit_size, /* virtual size=*/ dyadic_circuit_size, /* start_index=*/ 0 );
68
+ }
69
+
70
+ template <IsUltraFlavor Flavor> void DeciderProvingKey_<Flavor>::allocate_selectors(const Circuit& circuit)
71
+ {
72
+ PROFILE_THIS_NAME (" allocate_selectors" );
73
+
74
+ // Define gate selectors over the block they are isolated to
75
+ for (auto [selector, block] :
76
+ zip_view (proving_key.polynomials .get_gate_selectors (), circuit.blocks .get_gate_blocks ())) {
77
+
78
+ // TODO(https://github.com/AztecProtocol/barretenberg/issues/914): q_arith is currently used
79
+ // in aux block.
80
+ if (&block == &circuit.blocks .arithmetic ) {
81
+ size_t arith_size = circuit.blocks .aux .trace_offset - circuit.blocks .arithmetic .trace_offset +
82
+ circuit.blocks .aux .get_fixed_size (is_structured);
83
+ selector = Polynomial (arith_size, proving_key.circuit_size , circuit.blocks .arithmetic .trace_offset );
84
+ } else {
85
+ selector = Polynomial (block.get_fixed_size (is_structured), proving_key.circuit_size , block.trace_offset );
86
+ }
87
+ }
88
+
89
+ // Set the other non-gate selector polynomials (e.g. q_l, q_r, q_m etc.) to full size
90
+ for (auto & selector : proving_key.polynomials .get_non_gate_selectors ()) {
91
+ selector = Polynomial (proving_key.circuit_size );
92
+ }
93
+ }
94
+
95
+ template <IsUltraFlavor Flavor>
96
+ void DeciderProvingKey_<Flavor>::allocate_table_lookup_polynomials(const Circuit& circuit)
97
+ {
98
+ PROFILE_THIS_NAME (" allocate_table_lookup_polynomials" );
99
+
100
+ const size_t max_tables_size = std::min (static_cast <size_t >(MAX_LOOKUP_TABLES_SIZE), dyadic_circuit_size - 1 );
101
+ size_t table_offset = dyadic_circuit_size - max_tables_size;
102
+ ASSERT (dyadic_circuit_size > max_tables_size);
103
+
104
+ // Allocate the polynomials containing the actual table data
105
+ if constexpr (IsUltraFlavor<Flavor>) {
106
+ for (auto & poly : proving_key.polynomials .get_tables ()) {
107
+ poly = Polynomial (max_tables_size, dyadic_circuit_size, table_offset);
108
+ }
109
+ }
110
+
111
+ // Allocate the read counts and tags polynomials
112
+ proving_key.polynomials .lookup_read_counts = Polynomial (max_tables_size, dyadic_circuit_size, table_offset);
113
+ proving_key.polynomials .lookup_read_tags = Polynomial (max_tables_size, dyadic_circuit_size, table_offset);
114
+ ZoneScopedN (" allocating lookup and databus inverses" );
115
+
116
+ // Allocate the log derivative lookup argument inverse polynomial
117
+ const size_t lookup_offset = static_cast <size_t >(circuit.blocks .lookup .trace_offset );
118
+ const size_t lookup_inverses_start = std::min (lookup_offset, table_offset);
119
+ const size_t lookup_inverses_end =
120
+ std::min (dyadic_circuit_size,
121
+ std::max (lookup_offset + circuit.blocks .lookup .get_fixed_size (is_structured),
122
+ table_offset + MAX_LOOKUP_TABLES_SIZE));
123
+ proving_key.polynomials .lookup_inverses =
124
+ Polynomial (lookup_inverses_end - lookup_inverses_start, dyadic_circuit_size, lookup_inverses_start);
125
+ }
126
+
127
+ template <IsUltraFlavor Flavor>
128
+ void DeciderProvingKey_<Flavor>::allocate_ecc_op_polynomials(const Circuit& circuit)
129
+ requires IsMegaFlavor<Flavor>
130
+ {
131
+ PROFILE_THIS_NAME (" allocate_ecc_op_polynomials" );
132
+
133
+ // Allocate the ecc op wires and selector
134
+ const size_t ecc_op_block_size = circuit.blocks .ecc_op .get_fixed_size (is_structured);
135
+ const size_t op_wire_offset = circuit.blocks .ecc_op .trace_offset ;
136
+ for (auto & wire : proving_key.polynomials .get_ecc_op_wires ()) {
137
+ wire = Polynomial (ecc_op_block_size, proving_key.circuit_size , op_wire_offset);
138
+ }
139
+ proving_key.polynomials .lagrange_ecc_op = Polynomial (ecc_op_block_size, proving_key.circuit_size , op_wire_offset);
140
+ }
141
+
142
+ template <IsUltraFlavor Flavor>
143
+ void DeciderProvingKey_<Flavor>::allocate_databus_polynomials(const Circuit& circuit)
144
+ requires HasDataBus<Flavor>
145
+ {
146
+ proving_key.polynomials .calldata = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
147
+ proving_key.polynomials .calldata_read_counts = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
148
+ proving_key.polynomials .calldata_read_tags = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
149
+ proving_key.polynomials .secondary_calldata = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
150
+ proving_key.polynomials .secondary_calldata_read_counts = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
151
+ proving_key.polynomials .secondary_calldata_read_tags = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
152
+ proving_key.polynomials .return_data = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
153
+ proving_key.polynomials .return_data_read_counts = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
154
+ proving_key.polynomials .return_data_read_tags = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
155
+
156
+ proving_key.polynomials .databus_id = Polynomial (MAX_DATABUS_SIZE, proving_key.circuit_size );
157
+
158
+ // Allocate log derivative lookup argument inverse polynomials
159
+ const size_t q_busread_end =
160
+ circuit.blocks .busread .trace_offset + circuit.blocks .busread .get_fixed_size (is_structured);
161
+ proving_key.polynomials .calldata_inverses =
162
+ Polynomial (std::max (circuit.get_calldata ().size (), q_busread_end), dyadic_circuit_size);
163
+ proving_key.polynomials .secondary_calldata_inverses =
164
+ Polynomial (std::max (circuit.get_secondary_calldata ().size (), q_busread_end), dyadic_circuit_size);
165
+ proving_key.polynomials .return_data_inverses =
166
+ Polynomial (std::max (circuit.get_return_data ().size (), q_busread_end), dyadic_circuit_size);
167
+ }
168
+
33
169
/* *
34
170
* @brief
35
171
* @details
@@ -39,7 +175,7 @@ template <IsUltraFlavor Flavor> size_t DeciderProvingKey_<Flavor>::compute_dyadi
39
175
*/
40
176
template <IsUltraFlavor Flavor>
41
177
void DeciderProvingKey_<Flavor>::construct_databus_polynomials(Circuit& circuit)
42
- requires IsMegaFlavor <Flavor>
178
+ requires HasDataBus <Flavor>
43
179
{
44
180
auto & calldata_poly = proving_key.polynomials .calldata ;
45
181
auto & calldata_read_counts = proving_key.polynomials .calldata_read_counts ;
@@ -51,9 +187,9 @@ void DeciderProvingKey_<Flavor>::construct_databus_polynomials(Circuit& circuit)
51
187
auto & return_data_read_counts = proving_key.polynomials .return_data_read_counts ;
52
188
auto & return_data_read_tags = proving_key.polynomials .return_data_read_tags ;
53
189
54
- auto calldata = circuit.get_calldata ();
55
- auto secondary_calldata = circuit.get_secondary_calldata ();
56
- auto return_data = circuit.get_return_data ();
190
+ const auto & calldata = circuit.get_calldata ();
191
+ const auto & secondary_calldata = circuit.get_secondary_calldata ();
192
+ const auto & return_data = circuit.get_return_data ();
57
193
58
194
// Note: We do not utilize a zero row for databus columns
59
195
for (size_t idx = 0 ; idx < calldata.size (); ++idx) {
0 commit comments