Skip to content

chore: biggroup audit of lookup and rom tables#16895

Merged
suyash67 merged 26 commits intomerge-train/barretenbergfrom
sb/audit-biggroup-1
Sep 25, 2025
Merged

chore: biggroup audit of lookup and rom tables#16895
suyash67 merged 26 commits intomerge-train/barretenbergfrom
sb/audit-biggroup-1

Conversation

@suyash67
Copy link
Contributor

@suyash67 suyash67 commented Sep 9, 2025

🧾 Audit Context

Cleanup and audit of the lookup tables used in biggroup class. This PR does not change any logic, its mainly structural changes, cleanup and documentation.

🛠️ Changes Made

  • Added a README to explain how lookup tables are being used in biggroup, and a brief summary of how ROM tables work in barretenberg circuits.
  • Removed unused methods/structs like: lookup_table_base, batch_lookup_table_base, create_endo_pair_five_lookup_table.
  • Function comments + fix clang warnings + avoid hard-coded values.
  • No change to circuit, so no VK changes expected.

✅ 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

NA

@suyash67 suyash67 marked this pull request as ready for review September 9, 2025 12:30
@suyash67 suyash67 added the bberg-int-audit All things related to barretenberg internal audit label Sep 9, 2025
@suyash67 suyash67 requested a review from iakovenkos September 10, 2025 23:23
std::array<uint256_t, 8> limb_max; // tracks the maximum limb size represented in each element_table entry

// Each coordinate is an Fq element, which has 4 binary basis limbs and 1 prime basis limb
std::array<twin_rom_table<Builder>, Fq::NUM_LIMBS + 1> coordinates;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using Fq::NUM_LIMBS instead of hard-coded constants

bool use_endomorphism;
};

static std::pair<four_bit_table_plookup, four_bit_table_plookup> create_endo_pair_four_bit_table_plookup(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the implementation of this function to biggroup_tables.hpp

* The table KEY is 3 1-bit NAF entries that correspond to scalar multipliers for
* base points A, B, C
**/
template <size_t length> struct lookup_table_base {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lookup_table_base struct isn't used anywhere, its probably a remnant from the ultra-standard era.

* Creates a pair of 5-bit lookup tables, the former corresponding to 5 input points,
* the latter corresponding to the endomorphism equivalent of the 5 input points (e.g. x -> \beta * x, y -> -y)
**/
static std::pair<lookup_table_plookup<5>, lookup_table_plookup<5>> create_endo_pair_five_lookup_table(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

create_endo_pair_five_lookup_table isn't being used anywhere, so deleted it.

* Helper class to split a set of points into lookup table subsets
*
**/
struct batch_lookup_table_base {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This struct batch_lookup_table_base also isn't being used anywhere. We now have lookup_table_plookup and batch_lookup_table_plookup which help track all ROM lookup tables used in scalar multiplication in biggroup.

Copy link
Contributor

Choose a reason for hiding this comment

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

love it

Fq neg_lambda = Fq::msub_div({ x }, { (two_x + x) }, (y + y), { a });
Fq x_3 = neg_lambda.sqradd({ -(two_x) });
Fq y_3 = neg_lambda.madd(x_3 - x, { -y });
// TODO: do we handle the point at infinity case here?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This TODO will be addressed in upcoming PRs

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be good practice for us to use // TODO() for these temporary TODOs that don't quite warrant an issue, just other people know who to talk to if they run into it

element_table[29] = W5;
element_table[30] = W6;
element_table[31] = W7;
} else if constexpr (length == 7) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Case length = 7 is never used, removing it.

**/
template <typename C, class Fq, class Fr, class G>
template <size_t length>
element<C, Fq, Fr, G>::lookup_table_base<length>::lookup_table_base(const std::array<element, length>& inputs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remvoing lookup_table_base impl.

ecc_generator_table<G1>::generator_endo_xhi_table[i] = std::make_pair<bb::fr, bb::fr>(endox2, endox3);
ecc_generator_table<G1>::generator_ylo_table[i] = std::make_pair<bb::fr, bb::fr>(y0, y1);
ecc_generator_table<G1>::generator_yhi_table[i] = std::make_pair<bb::fr, bb::fr>(y2, y3);
ecc_generator_table<G1>::generator_xyprime_table[i] =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved generator_xyprime_table and generator_endo_xyprime_table at the top, just to avoid recomputing x * beta (and makes things more cleaner)

init = true;
}

// map 0 to 255 into 0 to 510 in steps of two
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused functions

Copy link
Contributor

@ledwards2225 ledwards2225 left a comment

Choose a reason for hiding this comment

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

LG! couple of small questions/suggestions

size_t remaining_points = num_points - (num_fives * 5 + num_sixes * 6);

// Allocate one quad table if required (and update remaining points)
has_quad = (remaining_points >= 4) && (num_points >= 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

is (num_points >= 4) needed here? seems like it would be caught by the 1st condition but maybe I'm misinterpreting

* Helper class to split a set of points into lookup table subsets
*
**/
struct batch_lookup_table_base {
Copy link
Contributor

Choose a reason for hiding this comment

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

love it

Fq neg_lambda = Fq::msub_div({ x }, { (two_x + x) }, (y + y), { a });
Fq x_3 = neg_lambda.sqradd({ -(two_x) });
Fq y_3 = neg_lambda.madd(x_3 - x, { -y });
// TODO: do we handle the point at infinity case here?
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be good practice for us to use // TODO() for these temporary TODOs that don't quite warrant an issue, just other people know who to talk to if they run into it

> Note:
> In the context of biggroup, we need variable-base lookup tables and fixed-base lookup tables. The variable-base lookup tables are used when the base point $P$ is not known at circuit synthesis time and is provided as a circuit witness. In this case, we need to generate the lookup tables on-the-fly based on the input base point $P$. On the other hand, fixed-base lookup tables are used when the base point $P$ is known at circuit synthesis time and can be hardcoded into the circuit (for example group generators). Fixed-base lookup tables are more efficient as they can be precomputed and do not require additional gates to enforce the correctness of the table entries. Variable-base lookup tables are realized using ROM tables (described below) while fixed-base lookup tables are realized using standard lookup tables in the circuit.

### ROM Tables in Barretenberg
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice description - what do you think about moving the non-biggroup specific stuff to a readme on ROM tables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, moved this section to rom tables' README.

@suyash67 suyash67 merged commit 57aecd9 into merge-train/barretenberg Sep 25, 2025
9 checks passed
@suyash67 suyash67 deleted the sb/audit-biggroup-1 branch September 25, 2025 13:20
github-merge-queue bot pushed a commit that referenced this pull request Sep 26, 2025
BEGIN_COMMIT_OVERRIDE
fix: secp256k1 ecdsa mul - fix handling of point at infinity (#16679)
fix: secp256k1 ecdsa mul handling of stagger point additions (#16685)
chore: biggroup audit of lookup and rom tables (#16895)
fix(bb): oversight that disabled batch commits (#17278)
docs(bb): add initial cli reference (#17244)
chore!: cycle group #6 (#17174)
fix: mac bb publish (#17276)
END_COMMIT_OVERRIDE
mralj pushed a commit that referenced this pull request Oct 13, 2025
### 🧾 Audit Context

Cleanup and audit of the lookup tables used in `biggroup` class. This PR
does not change any logic, its mainly structural changes, cleanup and
documentation.

### 🛠️ Changes Made

- Added a README to explain how lookup tables are being used in
biggroup, and a brief summary of how ROM tables work in barretenberg
circuits.
- Removed unused methods/structs like: `lookup_table_base`,
`batch_lookup_table_base`, `create_endo_pair_five_lookup_table`.
- Function comments + fix clang warnings + avoid hard-coded values.
- No change to circuit, so no VK changes expected.

### ✅ 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

NA
ludamad pushed a commit that referenced this pull request Dec 16, 2025
### 🧾 Audit Context

Cleanup and audit of the lookup tables used in `biggroup` class. This PR
does not change any logic, its mainly structural changes, cleanup and
documentation.

### 🛠️ Changes Made

- Added a README to explain how lookup tables are being used in
biggroup, and a brief summary of how ROM tables work in barretenberg
circuits.
- Removed unused methods/structs like: `lookup_table_base`,
`batch_lookup_table_base`, `create_endo_pair_five_lookup_table`.
- Function comments + fix clang warnings + avoid hard-coded values.
- No change to circuit, so no VK changes expected.

### ✅ 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

NA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bberg-int-audit All things related to barretenberg internal audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants