Skip to content

Commit 46f29e6

Browse files
authored
fix(sol-verifier): templating error (#16801)
Optimized verifier has a templating error - denominator inverses should not have started at the scratch space pointer used in the other bary centric values loop before, rather continued on from pointer
2 parents b02e0b5 + ed81ff5 commit 46f29e6

File tree

3 files changed

+313
-313
lines changed

3 files changed

+313
-313
lines changed

barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_optimized_contract.hpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ inline std::string generate_memory_offsets(int log_n)
248248
}
249249
for (int i = 0; i < log_n; ++i) {
250250
for (int j = 0; j < BARYCENTRIC_DOMAIN_SIZE; ++j) {
251-
print_fr(bary_pointer,
251+
print_fr(pointer,
252252
"BARYCENTRIC_DENOMINATOR_INVERSES_" + std::to_string(i) + "_" + std::to_string(j) + "_LOC");
253-
bary_pointer += 32;
253+
pointer += 32;
254254
}
255255
}
256256
print_header_centered("SUMCHECK - RUNTIME MEMORY - BARYCENTRIC COMPLETE");
@@ -299,55 +299,54 @@ inline std::string generate_memory_offsets(int log_n)
299299
print_header_centered("SHPLEMINI - RUNTIME MEMORY - INVERSIONS");
300300

301301
// Inverted gemini denominators
302-
int inv_pointer = SCRATCH_SPACE_POINTER;
303302
for (int i = 0; i < log_n + 1; ++i) {
304-
print_fr(inv_pointer, "INVERTED_GEMINI_DENOMINATOR_" + std::to_string(i) + "_LOC");
305-
inv_pointer += 32;
303+
print_fr(pointer, "INVERTED_GEMINI_DENOMINATOR_" + std::to_string(i) + "_LOC");
304+
pointer += 32;
306305
}
307306

308307
// Batched evaluation accumulator inversions
309308
for (int i = 0; i < log_n; ++i) {
310-
print_fr(inv_pointer, "BATCH_EVALUATION_ACCUMULATOR_INVERSION_" + std::to_string(i) + "_LOC");
311-
inv_pointer += 32;
309+
print_fr(pointer, "BATCH_EVALUATION_ACCUMULATOR_INVERSION_" + std::to_string(i) + "_LOC");
310+
pointer += 32;
312311
}
313312

314313
out << "\n";
315-
print_fr(inv_pointer, "BATCHED_EVALUATION_LOC");
316-
inv_pointer += 32;
317-
print_fr(inv_pointer, "CONSTANT_TERM_ACCUMULATOR_LOC");
318-
inv_pointer += 32;
314+
print_fr(pointer, "BATCHED_EVALUATION_LOC");
315+
pointer += 32;
316+
print_fr(pointer, "CONSTANT_TERM_ACCUMULATOR_LOC");
317+
pointer += 32;
319318

320319
out << "\n";
321-
print_fr(inv_pointer, "POS_INVERTED_DENOMINATOR");
322-
inv_pointer += 32;
323-
print_fr(inv_pointer, "NEG_INVERTED_DENOMINATOR");
324-
inv_pointer += 32;
320+
print_fr(pointer, "POS_INVERTED_DENOMINATOR");
321+
pointer += 32;
322+
print_fr(pointer, "NEG_INVERTED_DENOMINATOR");
323+
pointer += 32;
325324

326325
out << "\n";
327326
out << "// LOG_N challenge pow minus u\n";
328327
for (int i = 0; i < log_n; ++i) {
329-
print_fr(inv_pointer, "INVERTED_CHALLENEGE_POW_MINUS_U_" + std::to_string(i) + "_LOC");
330-
inv_pointer += 32;
328+
print_fr(pointer, "INVERTED_CHALLENEGE_POW_MINUS_U_" + std::to_string(i) + "_LOC");
329+
pointer += 32;
331330
}
332331

333332
out << "\n";
334333
out << "// LOG_N pos_inverted_off\n";
335334
for (int i = 0; i < log_n; ++i) {
336-
print_fr(inv_pointer, "POS_INVERTED_DENOM_" + std::to_string(i) + "_LOC");
337-
inv_pointer += 32;
335+
print_fr(pointer, "POS_INVERTED_DENOM_" + std::to_string(i) + "_LOC");
336+
pointer += 32;
338337
}
339338

340339
out << "\n";
341340
out << "// LOG_N neg_inverted_off\n";
342341
for (int i = 0; i < log_n; ++i) {
343-
print_fr(inv_pointer, "NEG_INVERTED_DENOM_" + std::to_string(i) + "_LOC");
344-
inv_pointer += 32;
342+
print_fr(pointer, "NEG_INVERTED_DENOM_" + std::to_string(i) + "_LOC");
343+
pointer += 32;
345344
}
346345

347346
out << "\n";
348347
for (int i = 0; i < log_n; ++i) {
349-
print_fr(inv_pointer, "FOLD_POS_EVALUATIONS_" + std::to_string(i) + "_LOC");
350-
inv_pointer += 32;
348+
print_fr(pointer, "FOLD_POS_EVALUATIONS_" + std::to_string(i) + "_LOC");
349+
pointer += 32;
351350
}
352351

353352
print_header_centered("SHPLEMINI RUNTIME MEMORY - INVERSIONS - COMPLETE");
@@ -368,7 +367,6 @@ inline std::string generate_memory_offsets(int log_n)
368367
// Scratch space aliases
369368
out << "\n";
370369
out << "// Aliases for scratch space\n";
371-
out << "// TODO: work out the stack scheduling for these\n";
372370
print_fr(0x00, "CHALL_POW_LOC");
373371
print_fr(0x20, "SUMCHECK_U_LOC");
374372
print_fr(0x40, "GEMINI_A_LOC");
@@ -840,7 +838,6 @@ contract HonkVerifier is IVerifier {
840838
841839
mcopy(0x20, LOOKUP_INVERSES_X_LOC, 0x80)
842840
843-
// Generate single alpha challenge and compute its powers
844841
prev_challenge := mod(keccak256(0x00, 0xa0), p)
845842
mstore(0x00, prev_challenge)
846843
let alpha := and(prev_challenge, LOWER_127_MASK)
@@ -1315,7 +1312,7 @@ contract HonkVerifier is IVerifier {
13151312
13161313
// Normalise as last loop will have incremented the offset
13171314
bary_centric_inverses_off := sub(bary_centric_inverses_off, 0x20)
1318-
for {} gt(bary_centric_inverses_off, BARYCENTRIC_LAGRANGE_DENOMINATOR_7_LOC) {
1315+
for {} gt(bary_centric_inverses_off, SUM_U_CHALLENGE_{{ LOG_N_MINUS_ONE }}) {
13191316
bary_centric_inverses_off := sub(bary_centric_inverses_off, 0x20)
13201317
} {
13211318
let tmp := mulmod(accumulator, mload(temp), p)

barretenberg/sol/scripts/copy_optimized_to_cpp.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ sed -i -E 's/(uint256 constant NUMBER_PUBLIC_INPUTS = )[0-9]+;/\1{{ NUM_PUBLIC_I
6868
sed -i -E 's/(uint256 constant REAL_NUMBER_PUBLIC_INPUTS = )[0-9]+ - [0-9]+;/\1{{ REAL_NUM_PUBLIC_INPUTS }};/' "$TEMP_SOL"
6969
sed -i -E 's/(uint256 constant NUMBER_OF_BARYCENTRIC_INVERSES = )[0-9]+;/\1{{ NUMBER_OF_BARYCENTRIC_INVERSES }};/' "$TEMP_SOL"
7070

71+
# Replace the for-loop comparison to use a template placeholder for CIRCUIT_SIZE
72+
sed -i -E 's/for \{\} gt\(bary_centric_inverses_off, SUM_U_CHALLENGE_14\) \{/for {} gt(bary_centric_inverses_off, SUM_U_CHALLENGE_{{ LOG_N_MINUS_ONE }}) \{/' "$TEMP_SOL"
73+
7174
# Replace the contract name
7275
sed -i 's/contract BlakeOptHonkVerifier/contract HonkVerifier/' "$TEMP_SOL"
7376

0 commit comments

Comments
 (0)