Skip to content

chore: translator circuit builder and flavor audit#19798

Merged
suyash67 merged 12 commits into
merge-train/barretenbergfrom
sb/translator-ckt-bldr
Jan 26, 2026
Merged

chore: translator circuit builder and flavor audit#19798
suyash67 merged 12 commits into
merge-train/barretenbergfrom
sb/translator-ckt-bldr

Conversation

@suyash67

@suyash67 suyash67 commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

🧾 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

  • Audited all methods of the relevant module/class
  • Audited the interface of the module/class with other (relevant) components
  • Documented existing functionality and any changes made (as per Doxygen requirements)
  • Resolved and/or closed all issues/TODOs pertaining to the audited files
  • Confirmed and documented any security or other issues found (if applicable)
  • 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

--

suyash67 and others added 11 commits January 21, 2026 14:23
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>
* 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) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@suyash67 suyash67 Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor fix: we want to assert $z_1, z_2 &lt; 2^{128}$ (not $z_1, z_2 &lt; 2^{68 \times 2}$

}

// Test with minimal operations (only required no-ops and random ops)
TEST(TranslatorCircuitBuilder, MinimalOperations)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@suyash67 suyash67 Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes polynomial sizes (actual range of polynomials)

@suyash67 suyash67 requested a review from iakovenkos January 21, 2026 14:55
};
// 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can re-use faster slicing method here -- AztecProtocol/barretenberg#1610

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though maybe it requires non-Montgomery form. I'll check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems as per this thread, the function get_bit_slice_raw works for specifically for the Pippenger use cases.

Comment thread barretenberg/cpp/src/barretenberg/translator_vm/translator_circuit_builder.cpp Outdated
// 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a new issue AztecProtocol/barretenberg#1612

@iakovenkos iakovenkos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@suyash67 suyash67 merged commit 91fc66e into merge-train/barretenberg Jan 26, 2026
8 checks passed
@suyash67 suyash67 deleted the sb/translator-ckt-bldr branch January 26, 2026 12:43
github-merge-queue Bot pushed a commit that referenced this pull request Jan 27, 2026
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
danielntmd pushed a commit that referenced this pull request Jan 27, 2026
### 🧾 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants