chore: translator circuit builder and flavor audit#19798
Conversation
Replace four specialized lambda functions (split_standard_limb_into_micro_limbs, split_top_limb_into_micro_limbs, split_top_z_limb_into_micro_limbs, and split_relation_limb_into_micro_limbs) with a single generic split_limb_into_microlimbs function that handles all cases. Fix bug where partial microlimbs were not correctly storing both unshifted and shifted versions, which is required for proper range constraints and reconstruction. Remove unused constants: TOP_STANDARD_MICROLIMB_BITS, TOP_Z_MICROLIMB_BITS, TOP_QUOTIENT_MICROLIMB_BITS. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Improve readability of complex mathematical equations by: - Using clang-format off/on directives to preserve custom formatting - Aligning similar terms vertically for easier visual parsing - Grouping terms logically (accumulator, v powers, quotient, remainder) - Maintaining all original logic without any changes Equations formatted: - remainder computation (accumulator formula) - quotient_by_modulus computation - low_wide_relation_limb_part_1 (lowest limb of relation) - low_wide_relation_limb (combined low relation with SHIFT_1) - high_wide_relation_limb (high relation with multiple limb combinations) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Split high_wide_relation_limb into two parts following the same pattern as low_wide_relation_limb for better readability and consistency: - high_wide_relation_limb_part_1: combines low limb divided + limbs (0*2, 1*1, 2*0) - high_wide_relation_limb: adds limbs (0*3, 1*2, 2*1, 3*0) * SHIFT_1 Also improved formatting of low_wide_relation_limb_part_1 by placing the variable initialization on a separate line for clearer structure. This makes both relation limb computations follow a consistent pattern: part_1 = base terms full = part_1 + (cross terms) * SHIFT_1 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Improve equation readability by placing each multiplication term on its own line for the relation limb computations: - low_wide_relation_limb: 12 terms, each on separate line - high_wide_relation_limb_part_1: 17 terms, each on separate line - high_wide_relation_limb: 22 terms, each on separate line This vertical layout makes it much easier to: - Visually scan and verify all terms - Identify patterns and symmetries - Spot missing or duplicate terms - Understand the mathematical structure at a glance Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Reorder all multiplication terms in relation limb equations to consistently place x_witnesses or v*_witnesses on the right side of each multiplication: Before: v_witnesses[i] * p_x_limbs[j] After: p_x_limbs[j] * v_witnesses[i] This standardization: - Improves visual consistency across all equations - Makes it easier to identify the pattern: (limb * witness) - Groups terms by their limb indices when scanning vertically - Maintains mathematical equivalence (multiplication is commutative) Applied to all four equations: - low_wide_relation_limb_part_1 - low_wide_relation_limb - high_wide_relation_limb_part_1 - high_wide_relation_limb Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Refactor microlimb splitting to use a single loop for all standard limbs (P_x, P_y, current_accumulator, quotient) instead of four separate loops. This improves code organization and readability while maintaining the same logic. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add doc comments to split_limb_into_microlimbs and improve lay_limbs_in_row documentation for better code readability. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…neck, should be fast.
| * Always returns NUM_MICRO_LIMBS (6) elements, padding with zeros if needed. | ||
| */ | ||
| auto split_top_limb_into_micro_limbs = [](const Fr& limb, const size_t last_limb_bits) { | ||
| auto split_limb_into_microlimbs = [](const Fr& limb, const size_t num_bits) { |
There was a problem hiding this comment.
simplification: consolidated all separate lambda fns to split into microlimbs in one lambda function.
| // Check and insert x_hi and z_1 into wire 2 | ||
| BB_ASSERT_LTE(uint256_t(ultra_op.x_hi), MAX_HIGH_WIDE_LIMB_SIZE); | ||
| BB_ASSERT_LTE(uint256_t(ultra_op.z_1), MAX_LOW_WIDE_LIMB_SIZE); | ||
| BB_ASSERT_LTE(uint256_t(ultra_op.z_1), MAX_Z_LIMB_SIZE); |
There was a problem hiding this comment.
Minor fix: we want to assert
| } | ||
|
|
||
| // Test with minimal operations (only required no-ops and random ops) | ||
| TEST(TranslatorCircuitBuilder, MinimalOperations) |
There was a problem hiding this comment.
Added lot more test cases in circuit builder
| ordered_extra_range_constraints_numerator, // column 0 | ||
| lagrange_first, // column 1 | ||
| lagrange_last, // column 2 | ||
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/758): Check if one of these |
There was a problem hiding this comment.
removed old issue that's closed
| lagrange_first = Polynomial{ /*size*/ 1, /*virtual_size*/ circuit_size }; | ||
| lagrange_result_row = Polynomial{ /*size*/ 1, /*virtual_size*/ circuit_size, /*start_index*/ RESULT_ROW }; | ||
| lagrange_even_in_minicircuit = Polynomial{ /*size*/ MINI_CIRCUIT_SIZE - RESULT_ROW, | ||
| lagrange_even_in_minicircuit = Polynomial{ /*size*/ MINI_CIRCUIT_SIZE - RESULT_ROW - NUM_MASKED_ROWS_END, |
There was a problem hiding this comment.
Fixes polynomial sizes (actual range of polynomials)
| }; | ||
| // Fill in the full 14-bit microlimbs | ||
| for (size_t i = 0; i < num_full_micro_limbs; ++i) { | ||
| microlimbs[i] = uint256_t(limb).slice(i * MICRO_LIMB_BITS, (i + 1) * MICRO_LIMB_BITS); |
There was a problem hiding this comment.
I think we can re-use faster slicing method here -- AztecProtocol/barretenberg#1610
There was a problem hiding this comment.
Though maybe it requires non-Montgomery form. I'll check
There was a problem hiding this comment.
Seems as per this thread, the function get_bit_slice_raw works for specifically for the Pippenger use cases.
| // length = 3. | ||
| // The degree has to be further increased because the relation is multiplied by the Row Disabling Polynomial | ||
| // total degree = sumcheck relation degree + 1 (PowZeta) + 1 (Lagrange) | ||
| static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 2; |
There was a problem hiding this comment.
Shouldn't it be +1 and not +2 as we are not multiplying by Row Disabling Polynomial in Translator's sumcheck, and the masking Lagrange contributions are accounted by subrelations' lengths?
There was a problem hiding this comment.
Opened a new issue AztecProtocol/barretenberg#1612
BEGIN_COMMIT_OVERRIDE feat: support JSON input files for bb verify command (#19800) fix: update bootstrap.sh to use new JSON field names chore: Update `index.js` so that `HAS_ZK` and `PUBLIC_INPUTS` variables must always be set in tests (#19884) chore: pippenger int audit (#19302) chore: deduplicate batch affine addition trick (#19788) chore: transcript+codec+poseidon2 fixes (#19419) chore!: explicitly constrain inputs and intermediate witnesses (#19826) fix: exclude nlohmann/json from WASM builds in json_output.hpp chore: translator circuit builder and flavor audit (#19798) Revert "fix: exclude nlohmann/json from WASM builds in json_output.hpp" Revert "feat: support JSON input files for bb verify command (#19800)" Revert "fix: update bootstrap.sh to use new JSON field names" END_COMMIT_OVERRIDE
### 🧾 Audit Context
Audit of translator circuit builder and flavor, no logic changes.
### 🛠️ Changes Made
- Minor simplifications in circuit builder and flavor:
- use a single lambda function to split limb into microlimbs
- fix code comments (or formatting changes)
- fixed Lagrange polynomial sizes
- Added more circuit builder tests
### ✅ Checklist
- [x] Audited all methods of the relevant module/class
- [x] Audited the interface of the module/class with other (relevant)
components
- [x] Documented existing functionality and any changes made (as per
Doxygen requirements)
- [x] Resolved and/or closed all issues/TODOs pertaining to the audited
files
- [x] Confirmed and documented any security or other issues found (if
applicable)
- [x] Verified that tests cover all critical paths (and added tests if
necessary)
- [ ] Updated audit tracking for the files audited (check the start of
each file you audited)
### 📌 Notes for Reviewers
--
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
🧾 Audit Context
Audit of translator circuit builder and flavor, no logic changes.
🛠️ Changes Made
✅ Checklist
📌 Notes for Reviewers
--