Skip to content

Commit 12d59ca

Browse files
author
maramihali
committed
I fixed the size of the op queue
1 parent 4fb977e commit 12d59ca

File tree

10 files changed

+126
-10
lines changed

10 files changed

+126
-10
lines changed

barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ ClientIVC::perform_recursive_verification_and_databus_consistency_checks(
269269
pairing_points.aggregate(nested_pairing_points);
270270
if (is_hiding_kernel) {
271271
pairing_points.aggregate(decider_pairing_points);
272+
// Placeholder for randomness (will be removed)
273+
circuit.queue_ecc_no_op();
274+
circuit.queue_ecc_no_op();
275+
info("num ops in hiding kernel ", circuit.op_queue->get_unmerged_subtable_size());
272276
}
273277

274278
return { output_verifier_accumulator, pairing_points, merged_table_commitments };
@@ -312,6 +316,8 @@ void ClientIVC::complete_kernel_circuit_logic(ClientCircuit& circuit)
312316
// subtable is at the top of the final aggregate table since it is the last to be prepended).
313317
if (is_tail_kernel) {
314318
circuit.queue_ecc_no_op();
319+
circuit.queue_ecc_no_op();
320+
circuit.queue_ecc_no_op();
315321
}
316322
circuit.queue_ecc_eq();
317323

barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ TEST_F(ClientIVCTests, BasicStructured)
8888

8989
EXPECT_TRUE(ClientIVC::verify(proof, vk));
9090
};
91-
9291
/**
9392
* @brief Check that the IVC fails if an intermediate fold proof is invalid
9493
* @details When accumulating 4 circuits, there are 3 fold proofs to verify (the first two are recursively verfied and

barretenberg/cpp/src/barretenberg/goblin/goblin.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,31 @@ void Goblin::prove_translator()
4545
auto translator_key = std::make_shared<TranslatorProvingKey>(translator_builder, commitment_key);
4646
TranslatorProver translator_prover(translator_key, transcript);
4747
goblin_proof.translator_proof = translator_prover.construct_proof();
48+
// auto op = op_queue->construct_ultra_ops_table_columns()[0];
49+
// auto op_translator = op_queue->get_ultra_ops();
50+
// info(op.size(), " ", op_translator.size());
51+
// for (size_t i = 0; i < op_translator.size(); i++) {}
52+
53+
// if
54+
// info(op.size(), " ", translator_key->proving_key->polynomials.op.size());
55+
// for (size_t i = 0; i < op.size(); i++) {
56+
// if (op.at(i) != translator_key->proving_key->polynomials.op[i]) {
57+
// info("mismatch at ",
58+
// i,
59+
// " op_queue: ",
60+
// op.at(i),
61+
// " translator_key: ",
62+
// translator_key->proving_key->polynomials.op[i]);
63+
// }
64+
// }
4865
}
4966

5067
GoblinProof Goblin::prove(const MergeSettings merge_settings)
5168
{
5269
PROFILE_THIS_NAME("Goblin::prove");
5370

5471
prove_merge(transcript, merge_settings); // Use shared transcript for merge proving
55-
info("Constructing a Goblin proof with num ultra ops = ", op_queue->get_ultra_ops_table_num_rows());
72+
info("Constructing a Goblin proof with num ultra ops = ", op_queue->get_ultra_ops().size());
5673

5774
BB_ASSERT_EQ(merge_verification_queue.size(),
5875
1U,

barretenberg/cpp/src/barretenberg/op_queue/ecc_op_queue.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ECCOpQueue {
4848
EccvmRowTracker eccvm_row_tracker;
4949

5050
public:
51+
static const size_t OP_QUEUE_SIZE = 1 << 13;
5152
/**
5253
* @brief Instantiate an initial ECC op subtable.
5354
*/

barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.hpp

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct UltraOp {
7474
Fr z_2;
7575
bool return_is_infinity;
7676

77+
bool operator==(const UltraOp& other) const = default;
78+
7779
/**
7880
* @brief Get the point in standard form i.e. as two coordinates x and y in the base field or as a point at
7981
* infinity whose coordinates are set to (0,0).
@@ -237,7 +239,6 @@ class UltraEccOpsTable {
237239

238240
public:
239241
size_t size() const { return table.size(); }
240-
// size_t get_unmerged_subtable_size() const { return table.get_unmerged_subtable_size(); }
241242

242243
size_t ultra_table_size() const
243244
{
@@ -249,7 +250,8 @@ class UltraEccOpsTable {
249250
// The last subtable in deque is the fixed-location one
250251
last_subtable_size = table.get().back().size() * NUM_ROWS_PER_OP;
251252
}
252-
return std::max(base_size, fixed_append_offset.value() + last_subtable_size);
253+
info("here");
254+
return std::max(base_size, (fixed_append_offset.value() * NUM_ROWS_PER_OP) + last_subtable_size);
253255
}
254256
return base_size;
255257
}
@@ -275,14 +277,62 @@ class UltraEccOpsTable {
275277

276278
size_t get_unmerged_subtable_size() const { return table.get_unmerged_subtable_size(); }
277279

278-
std::vector<UltraOp> get_reconstructed() const { return table.get_reconstructed(); }
280+
std::vector<UltraOp> get_reconstructed() const
281+
{
282+
if (has_fixed_append) {
283+
return get_reconstructed_with_fixed_append();
284+
}
285+
return table.get_reconstructed();
286+
}
287+
std::vector<UltraOp> get_reconstructed_with_fixed_append() const
288+
{
289+
290+
ASSERT(get_unmerged_subtable_size() == 0,
291+
"current subtable should be merged before reconstructing the full table of operations.");
292+
info("Reconstructing with fixed append");
293+
294+
std::vector<UltraOp> reconstructed_table;
295+
// reconstructed_table.reserve(reconstructed_table_size);
296+
297+
for (size_t subtable_idx = 0; subtable_idx < table.num_subtables() - 1; subtable_idx++) {
298+
const auto& subtable = table.get()[subtable_idx];
299+
for (const auto& op : subtable) {
300+
reconstructed_table.push_back(op);
301+
}
302+
}
303+
info("Size before shift: ", reconstructed_table.size());
304+
305+
// Add zeros if fixed offset is larger than current size
306+
if (has_fixed_append && fixed_append_offset.has_value()) {
307+
size_t current_size = reconstructed_table.size();
308+
size_t target_offset = fixed_append_offset.value();
309+
310+
// Fill gap with no-ops if needed
311+
while (current_size < target_offset) {
312+
UltraOp no_op = {};
313+
// no_op.op_code is already initialized with all false values (no operation)
314+
reconstructed_table.push_back(no_op);
315+
current_size++;
316+
}
317+
}
318+
319+
// Add the final subtable (appended at fixed location)
320+
info("Size before appending final subtable: ", reconstructed_table.size());
321+
const auto& final_subtable = table.get()[table.num_subtables() - 1];
322+
for (const auto& op : final_subtable) {
323+
reconstructed_table.push_back(op);
324+
}
325+
info("Reconstructed table size: ", reconstructed_table.size());
326+
return reconstructed_table;
327+
}
279328

280329
// Construct the columns of the full ultra ecc ops table
281330
ColumnPolynomials construct_table_columns() const
282331
{
283332
const size_t poly_size = ultra_table_size();
284333

285334
if (has_fixed_append) {
335+
info("we should construct with fixed append ", poly_size);
286336
// Handle fixed-location append: prepended tables first, then appended table at fixed offset
287337
return construct_column_polynomials_with_fixed_append(poly_size);
288338
}
@@ -347,7 +397,7 @@ class UltraEccOpsTable {
347397

348398
// Process all prepended subtables (all except last)
349399
size_t i = 0;
350-
for (size_t subtable_idx = 0; subtable_idx < table.num_subtables() - 1; ++subtable_idx) {
400+
for (size_t subtable_idx = 0; subtable_idx < table.num_subtables() - 1; subtable_idx++) {
351401
const auto& subtable = table.get()[subtable_idx];
352402
for (const auto& op : subtable) {
353403
write_op_to_polynomials(column_polynomials, op, i);
@@ -356,7 +406,8 @@ class UltraEccOpsTable {
356406
}
357407

358408
// Place the appended subtable at the fixed offset
359-
size_t append_position = fixed_append_offset.value_or(i);
409+
size_t append_position = fixed_append_offset.value_or(i) * NUM_ROWS_PER_OP;
410+
info("append position: ", append_position);
360411
const auto& appended_subtable = table.get()[table.num_subtables() - 1];
361412

362413
size_t j = append_position;

barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.test.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,39 @@ TEST(EccOpsTableTest, UltraOpsFixedLocationAppendWithGap)
329329
EXPECT_EQ(ultra_op_poly.at(fixed_offset + row), expected_poly[row]);
330330
}
331331
}
332+
333+
// Mimic get_reconstructed by unifying all the ops from subtables into a single vector with the appropiate gap of
334+
// no-ops
335+
{
336+
// Compute how many no-op operations are needed to span the gap (fixed_offset and prepended_size are in rows)
337+
338+
std::vector<UltraOp> expected_reconstructed;
339+
expected_reconstructed.reserve(expected_num_ops + fixed_offset);
340+
341+
// Order: subtable[1], subtable[0], gap (no-ops), subtable[2]
342+
for (const auto& op : subtables[1]) {
343+
expected_reconstructed.push_back(op);
344+
}
345+
for (const auto& op : subtables[0]) {
346+
expected_reconstructed.push_back(op);
347+
}
348+
349+
// Construct a canonical "no-op" UltraOp (fields zeroed)
350+
UltraOp no_op = {};
351+
size_t size_before = expected_reconstructed.size();
352+
for (size_t i = size_before; i < fixed_offset; i++) {
353+
expected_reconstructed.push_back(no_op);
354+
}
355+
356+
for (const auto& op : subtables[2]) {
357+
expected_reconstructed.push_back(op);
358+
}
359+
360+
EXPECT_EQ(expected_reconstructed.size(), ultra_ops_table.get_reconstructed().size());
361+
362+
// Compare to the op-queue's reconstruction (should include the gap as no-ops)
363+
EXPECT_EQ(expected_reconstructed, ultra_ops_table.get_reconstructed());
364+
}
332365
}
333366

334367
// Ensure EccvmOpsTable correctly constructs a concatenated table from successively prepended subtables

barretenberg/cpp/src/barretenberg/translator_vm/translator_circuit_builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void TranslatorCircuitBuilder::feed_ecc_op_queue_into_circuit(const std::shared_
540540

541541
const auto& ultra_op = ultra_ops[ultra_ops.size() - i];
542542
if (ultra_op.op_code.value() == 0) {
543-
// Skip no-ops as
543+
// Skip no-ops as they should not affect the computation of the accumulator (or)
544544
continue;
545545
}
546546
current_accumulator *= evaluation_input_x;

barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TranslatorProvingKey {
4949
PROFILE_THIS_NAME("TranslatorProvingKey(TranslatorCircuit&)");
5050
// Check that the Translator Circuit does not exceed the fixed upper bound, the current value amounts to
5151
// a number of EccOps sufficient for 10 rounds of folding (so 20 circuits)
52-
if (circuit.num_gates > Flavor::MINI_CIRCUIT_SIZE - NUM_DISABLED_ROWS_IN_SUMCHECK) {
52+
if (circuit.num_gates > Flavor::MINI_CIRCUIT_SIZE) {
5353
throw_or_abort("The Translator circuit size has exceeded the fixed upper bound");
5454
}
5555

barretenberg/cpp/src/barretenberg/translator_vm/translator_verifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ bool TranslatorVerifier::verify_translation(const TranslationEvaluations& transl
204204
*/
205205
bool TranslatorVerifier::verify_consistency_with_final_merge(const std::array<Commitment, 4>& merge_commitments)
206206
{
207+
207208
if (op_queue_commitments[0] != merge_commitments[0]) {
208209
info("Consistency check failed: op commitment mismatch");
209210
return false;

barretenberg/cpp/src/barretenberg/ultra_honk/merge_prover.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ MergeProver::MergeProver(const std::shared_ptr<ECCOpQueue>& op_queue,
2525
{
2626
// Merge the current subtable (for which a merge proof is being constructed) prior to
2727
// procedeing with proving.
28-
op_queue->merge(settings);
28+
if (settings == MergeSettings::APPEND) {
29+
30+
op_queue->merge(settings, ECCOpQueue::OP_QUEUE_SIZE - 293);
31+
info("hiding kernel subtable size? ", op_queue->get_current_ultra_ops_subtable_num_rows() / 2);
32+
33+
} else {
34+
op_queue->merge(settings);
35+
}
36+
2937
pcs_commitment_key =
3038
commitment_key.initialized() ? commitment_key : CommitmentKey(op_queue->get_ultra_ops_table_num_rows());
3139
};

0 commit comments

Comments
 (0)