Skip to content

Commit 3c1f54c

Browse files
authored
chore: name ECCVM subrelation indices with enums (#22003)
## Summary - Replace raw `std::get<N>(accumulator)` calls with named `enum SubrelationIndex` constants across all 7 ECCVM relation files (134 total subrelations) - Zero runtime cost — enum values are compile-time `size_t` constants that resolve to identical `std::get<N>` calls - Makes the wildly non-sequential index assignments (especially in MSM relation: 0,1,2,36,37,38,10,11,12,...) self-documenting and auditable ## Test plan - [x] `eccvm_tests` — all 42 tests pass - [x] Grep for remaining raw `std::get<\d+>(accumulator)` in `.hpp` files — zero matches - [x] No changes to SUBRELATION_PARTIAL_LENGTHS, sumcheck infrastructure, flavors, or test files
2 parents fda15ca + 5c5ebcb commit 3c1f54c

20 files changed

Lines changed: 486 additions & 163 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ bb-sol: bb-cpp-native bb-crs
235235
# Barretenberg Tests
236236
#==============================================================================
237237

238-
bb-cpp-native-tests: bb-cpp-native bb-crs
238+
bb-cpp-native-tests: bb-cpp-native
239239
$(call test,$@,barretenberg/cpp,native)
240240

241241
bb-cpp-wasm-threads-tests: bb-cpp-wasm-threads

barretenberg/cpp/bootstrap.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,6 @@ case "$cmd" in
380380
build
381381
;;
382382
"ci")
383-
# Ensure CRS is downloaded before running tests
384-
../crs/bootstrap.sh
385383
build
386384
test
387385
;;

barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplemini.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,10 @@ template <typename Curve, bool HasZK = false> class ShpleminiVerifier_ {
465465

466466
// Accumulate the const term contribution given by
467467
// v^{2j} * A_j(r^{2^j}) /(z - r^{2^j}) + v^{2j+1} * A_j(-r^{2^j}) /(z+ r^{2^j})
468-
constant_term_accumulator +=
469-
scaling_factor_neg * gemini_neg_evaluations[j] + scaling_factor_pos * gemini_pos_evaluations[j];
468+
// For padding rounds (j >= log_n), padding_indicator_array[j] = 0, zeroing the contribution.
469+
// This ensures prover-sent negative evaluations for padding rounds don't affect the constant term.
470+
constant_term_accumulator += padding_indicator_array[j] * (scaling_factor_neg * gemini_neg_evaluations[j] +
471+
scaling_factor_pos * gemini_pos_evaluations[j]);
470472

471473
// Place the scaling factor to the 'scalars' vector
472474
scalars.emplace_back(-padding_indicator_array[j] * (scaling_factor_neg + scaling_factor_pos));

barretenberg/cpp/src/barretenberg/dsl/acir_format/gate_count_constants.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ constexpr std::tuple<size_t, size_t> HONK_RECURSION_CONSTANTS(
7575
} else if constexpr (std::is_same_v<RecursiveFlavor, bb::UltraZKRecursiveFlavor_<UltraCircuitBuilder>>) {
7676
switch (mode) {
7777
case PredicateTestCase::ConstantTrue:
78-
return std::make_tuple(703927, 0);
78+
return std::make_tuple(703951, 0);
7979
case PredicateTestCase::WitnessTrue:
8080
case PredicateTestCase::WitnessFalse:
81-
return std::make_tuple(705080, 0);
81+
return std::make_tuple(705104, 0);
8282
}
8383
} else if constexpr (std::is_same_v<RecursiveFlavor, bb::UltraRecursiveFlavor_<MegaCircuitBuilder>>) {
8484
switch (mode) {
@@ -91,16 +91,16 @@ constexpr std::tuple<size_t, size_t> HONK_RECURSION_CONSTANTS(
9191
} else if constexpr (std::is_same_v<RecursiveFlavor, bb::UltraZKRecursiveFlavor_<MegaCircuitBuilder>>) {
9292
switch (mode) {
9393
case PredicateTestCase::ConstantTrue:
94-
return std::make_tuple(25452, 77);
94+
return std::make_tuple(25476, 77);
9595
case PredicateTestCase::WitnessTrue:
9696
case PredicateTestCase::WitnessFalse:
97-
return std::make_tuple(26605, 77);
97+
return std::make_tuple(26629, 77);
9898
}
9999
} else if constexpr (std::is_same_v<RecursiveFlavor, bb::MegaZKRecursiveFlavor_<UltraCircuitBuilder>>) {
100100
if (mode != PredicateTestCase::ConstantTrue) {
101101
bb::assert_failure("Unhandled mode in MegaZKRecursiveFlavor.");
102102
}
103-
return std::make_tuple(781918, 0);
103+
return std::make_tuple(781933, 0);
104104
} else {
105105
bb::assert_failure("Unhandled recursive flavor.");
106106
}
@@ -113,7 +113,7 @@ constexpr std::tuple<size_t, size_t> HONK_RECURSION_CONSTANTS(
113113
// ========================================
114114

115115
// Gate count for Chonk recursive verification (Ultra with RollupIO)
116-
inline constexpr size_t CHONK_RECURSION_GATES = 1493584;
116+
inline constexpr size_t CHONK_RECURSION_GATES = 1494161;
117117

118118
// ========================================
119119
// Hypernova Recursion Constants
@@ -147,7 +147,7 @@ inline constexpr size_t HIDING_KERNEL_ULTRA_OPS = 127;
147147
// ========================================
148148

149149
// Gate count for ECCVM recursive verifier (Ultra-arithmetized)
150-
inline constexpr size_t ECCVM_RECURSIVE_VERIFIER_GATE_COUNT = 224657;
150+
inline constexpr size_t ECCVM_RECURSIVE_VERIFIER_GATE_COUNT = 225236;
151151

152152
// ========================================
153153
// Goblin AVM Recursive Verifier Constants

barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_bools_relation.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,39 @@ template <typename FF_> class ECCVMBoolsRelationImpl {
2323
public:
2424
using FF = FF_;
2525

26+
// Named subrelation indices — matches SUBRELATION_PARTIAL_LENGTHS ordering.
27+
// Each constrains a specific column to be boolean: col * (col - 1) == 0.
28+
enum SubrelationIndex : size_t {
29+
BOOL_Q_EQ = 0,
30+
BOOL_Q_ADD = 1,
31+
BOOL_Q_MUL = 2,
32+
BOOL_Q_RESET_ACCUMULATOR = 3,
33+
BOOL_MSM_TRANSITION = 4,
34+
BOOL_ACCUMULATOR_NOT_EMPTY = 5,
35+
BOOL_Z1_ZERO = 6,
36+
BOOL_Z2_ZERO = 7,
37+
BOOL_ADD_X_EQUAL = 8,
38+
BOOL_ADD_Y_EQUAL = 9,
39+
BOOL_BASE_INFINITY = 10,
40+
BOOL_MSM_INFINITY = 11,
41+
BOOL_MSM_COUNT_ZERO_AT_TRANSITION = 12,
42+
BOOL_MSM_TRANSITION_MSM = 13,
43+
BOOL_PRECOMPUTE_POINT_TRANSITION = 14,
44+
BOOL_MSM_ADD = 15,
45+
BOOL_MSM_DOUBLE = 16,
46+
BOOL_MSM_SKEW = 17,
47+
BOOL_PRECOMPUTE_SELECT = 18,
48+
BOOL_MSM_ADD1 = 19,
49+
BOOL_MSM_ADD2 = 20,
50+
BOOL_MSM_ADD3 = 21,
51+
BOOL_MSM_ADD4 = 22,
52+
NUM_SUBRELATIONS,
53+
};
54+
2655
static constexpr std::array<size_t, 23> SUBRELATION_PARTIAL_LENGTHS{
2756
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2857
};
58+
static_assert(NUM_SUBRELATIONS == SUBRELATION_PARTIAL_LENGTHS.size());
2959

3060
template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
3161
static void accumulate(ContainerOverSubrelations& accumulator,

barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_bools_relation_impl.hpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,33 @@ void ECCVMBoolsRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulat
5656
auto msm_add3 = View(in.msm_add3);
5757
auto msm_add4 = View(in.msm_add4);
5858

59-
std::get<0>(accumulator) += q_eq * (q_eq - 1) * scaling_factor;
60-
std::get<1>(accumulator) += q_add * (q_add - 1) * scaling_factor;
61-
std::get<2>(accumulator) += q_mul * (q_mul - 1) * scaling_factor;
62-
std::get<3>(accumulator) += q_reset_accumulator * (q_reset_accumulator - 1) * scaling_factor;
63-
std::get<4>(accumulator) += transcript_msm_transition * (transcript_msm_transition - 1) * scaling_factor;
64-
std::get<5>(accumulator) += is_accumulator_not_empty * (is_accumulator_not_empty - 1) * scaling_factor;
65-
std::get<6>(accumulator) += z1_zero * (z1_zero - 1) * scaling_factor;
66-
std::get<7>(accumulator) += z2_zero * (z2_zero - 1) * scaling_factor;
67-
std::get<8>(accumulator) += transcript_add_x_equal * (transcript_add_x_equal - 1) * scaling_factor;
68-
std::get<9>(accumulator) += transcript_add_y_equal * (transcript_add_y_equal - 1) * scaling_factor;
69-
std::get<10>(accumulator) += transcript_Pinfinity * (transcript_Pinfinity - 1) * scaling_factor;
70-
std::get<11>(accumulator) += transcript_msm_infinity * (transcript_msm_infinity - 1) * scaling_factor;
71-
std::get<12>(accumulator) += msm_count_zero_at_transition * (msm_count_zero_at_transition - 1) * scaling_factor;
72-
std::get<13>(accumulator) += msm_transition * (msm_transition - 1) * scaling_factor;
73-
std::get<14>(accumulator) += precompute_point_transition * (precompute_point_transition - 1) * scaling_factor;
74-
std::get<15>(accumulator) += msm_add * (msm_add - 1) * scaling_factor;
75-
std::get<16>(accumulator) += msm_double * (msm_double - 1) * scaling_factor;
76-
std::get<17>(accumulator) += msm_skew * (msm_skew - 1) * scaling_factor;
77-
std::get<18>(accumulator) += precompute_select * (precompute_select - 1) * scaling_factor;
78-
std::get<19>(accumulator) += msm_add1 * (msm_add1 - 1) * scaling_factor;
79-
std::get<20>(accumulator) += msm_add2 * (msm_add2 - 1) * scaling_factor;
80-
std::get<21>(accumulator) += msm_add3 * (msm_add3 - 1) * scaling_factor;
81-
std::get<22>(accumulator) += msm_add4 * (msm_add4 - 1) * scaling_factor;
59+
std::get<BOOL_Q_EQ>(accumulator) += q_eq * (q_eq - 1) * scaling_factor;
60+
std::get<BOOL_Q_ADD>(accumulator) += q_add * (q_add - 1) * scaling_factor;
61+
std::get<BOOL_Q_MUL>(accumulator) += q_mul * (q_mul - 1) * scaling_factor;
62+
std::get<BOOL_Q_RESET_ACCUMULATOR>(accumulator) += q_reset_accumulator * (q_reset_accumulator - 1) * scaling_factor;
63+
std::get<BOOL_MSM_TRANSITION>(accumulator) +=
64+
transcript_msm_transition * (transcript_msm_transition - 1) * scaling_factor;
65+
std::get<BOOL_ACCUMULATOR_NOT_EMPTY>(accumulator) +=
66+
is_accumulator_not_empty * (is_accumulator_not_empty - 1) * scaling_factor;
67+
std::get<BOOL_Z1_ZERO>(accumulator) += z1_zero * (z1_zero - 1) * scaling_factor;
68+
std::get<BOOL_Z2_ZERO>(accumulator) += z2_zero * (z2_zero - 1) * scaling_factor;
69+
std::get<BOOL_ADD_X_EQUAL>(accumulator) += transcript_add_x_equal * (transcript_add_x_equal - 1) * scaling_factor;
70+
std::get<BOOL_ADD_Y_EQUAL>(accumulator) += transcript_add_y_equal * (transcript_add_y_equal - 1) * scaling_factor;
71+
std::get<BOOL_BASE_INFINITY>(accumulator) += transcript_Pinfinity * (transcript_Pinfinity - 1) * scaling_factor;
72+
std::get<BOOL_MSM_INFINITY>(accumulator) +=
73+
transcript_msm_infinity * (transcript_msm_infinity - 1) * scaling_factor;
74+
std::get<BOOL_MSM_COUNT_ZERO_AT_TRANSITION>(accumulator) +=
75+
msm_count_zero_at_transition * (msm_count_zero_at_transition - 1) * scaling_factor;
76+
std::get<BOOL_MSM_TRANSITION_MSM>(accumulator) += msm_transition * (msm_transition - 1) * scaling_factor;
77+
std::get<BOOL_PRECOMPUTE_POINT_TRANSITION>(accumulator) +=
78+
precompute_point_transition * (precompute_point_transition - 1) * scaling_factor;
79+
std::get<BOOL_MSM_ADD>(accumulator) += msm_add * (msm_add - 1) * scaling_factor;
80+
std::get<BOOL_MSM_DOUBLE>(accumulator) += msm_double * (msm_double - 1) * scaling_factor;
81+
std::get<BOOL_MSM_SKEW>(accumulator) += msm_skew * (msm_skew - 1) * scaling_factor;
82+
std::get<BOOL_PRECOMPUTE_SELECT>(accumulator) += precompute_select * (precompute_select - 1) * scaling_factor;
83+
std::get<BOOL_MSM_ADD1>(accumulator) += msm_add1 * (msm_add1 - 1) * scaling_factor;
84+
std::get<BOOL_MSM_ADD2>(accumulator) += msm_add2 * (msm_add2 - 1) * scaling_factor;
85+
std::get<BOOL_MSM_ADD3>(accumulator) += msm_add3 * (msm_add3 - 1) * scaling_factor;
86+
std::get<BOOL_MSM_ADD4>(accumulator) += msm_add4 * (msm_add4 - 1) * scaling_factor;
8287
}
8388
} // namespace bb

barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ template <typename FF_> class ECCVMLookupRelationImpl {
2222
// 1 + polynomial degree of this relation
2323
static constexpr size_t LENGTH = NUM_LOOKUP_TERMS + NUM_TABLE_TERMS + 3; // 9
2424

25+
// Named subrelation indices — matches SUBRELATION_PARTIAL_LENGTHS ordering.
26+
enum SubrelationIndex : size_t {
27+
GRAND_PRODUCT = 0,
28+
LEFT_SHIFTABLE = 1,
29+
NUM_SUBRELATIONS,
30+
};
31+
2532
static constexpr std::array<size_t, 2> SUBRELATION_PARTIAL_LENGTHS{
2633
LENGTH, // grand product construction sub-relation
2734
LENGTH // left-shiftable polynomial sub-relation
2835
};
36+
static_assert(NUM_SUBRELATIONS == SUBRELATION_PARTIAL_LENGTHS.size());
2937

3038
static constexpr std::array<bool, 2> SUBRELATION_LINEARLY_INDEPENDENT = { true, false };
3139

barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,92 @@ namespace bb {
4343
template <typename FF_> class ECCVMMSMRelationImpl {
4444
public:
4545
using FF = FF_;
46+
47+
// Named subrelation indices — matches SUBRELATION_PARTIAL_LENGTHS ordering.
48+
// Grouped by logical function within the Strauss MSM algorithm.
49+
enum SubrelationIndex : size_t {
50+
// Addition round: accumulator update and slope constraints
51+
ADD_ACC_X = 0,
52+
ADD_ACC_Y = 1,
53+
ADD_SLOPE_1 = 2,
54+
// Skew round: accumulator update and slope constraint
55+
SKEW_ACC_X = 3,
56+
SKEW_ACC_Y = 4,
57+
SKEW_SLOPE_1 = 5,
58+
// Collision checks: x-coordinate non-equality for point additions
59+
COLLISION_CHECK_1 = 6,
60+
COLLISION_CHECK_2 = 7,
61+
COLLISION_CHECK_3 = 8,
62+
COLLISION_CHECK_4 = 9,
63+
// Doubling round: accumulator update and slope constraint
64+
DOUBLE_ACC_X = 10,
65+
DOUBLE_ACC_Y = 11,
66+
DOUBLE_SLOPE_1 = 12,
67+
// Inactive slice zeroing: force slice_i = 0 when add_i = 0
68+
INACTIVE_SLICE_1 = 13,
69+
INACTIVE_SLICE_2 = 14,
70+
INACTIVE_SLICE_3 = 15,
71+
INACTIVE_SLICE_4 = 16,
72+
// Phase selector mutual exclusivity: at most one of q_add, q_double, q_skew active
73+
PHASE_SELECTOR_MUTUAL_EXCLUSIVITY = 17,
74+
// Round transition forces round_delta == 1
75+
ROUND_TRANSITION_FORCES_DELTA_ONE = 18,
76+
// Round transition with skew implies round == 31
77+
ROUND_TRANSITION_SKEW_IMPLIES_ROUND_31 = 19,
78+
// Round transition requires exactly one of double or skew on next row
79+
ROUND_TRANSITION_EXACTLY_ONE_DOUBLE_OR_SKEW = 20,
80+
// Round transition needs double or skew (cannot have neither)
81+
ROUND_TRANSITION_NEEDS_DOUBLE_OR_SKEW = 21,
82+
// Double implies next row is an add row
83+
DOUBLE_IMPLIES_NEXT_IS_ADD = 22,
84+
// Count shift must be zero when round changes
85+
COUNT_SHIFT_ZERO_ON_ROUND_CHANGE = 23,
86+
// Count increments within the same round by number of active adds
87+
COUNT_INCREMENT_WITHIN_ROUND = 24,
88+
// Count must be zero at round boundary or MSM transition
89+
COUNT_ZERO_AT_ROUND_BOUNDARY_OR_TRANSITION = 25,
90+
// MSM transition implies round = 0
91+
MSM_TRANSITION_ROUND_ZERO = 26,
92+
// MSM transition: pc = pc_shift + msm_size
93+
MSM_TRANSITION_PC = 27,
94+
// Addition continuity: add2 requires add1
95+
ADD_CONTINUITY_2 = 28,
96+
// Addition continuity: add3 requires add2
97+
ADD_CONTINUITY_3 = 29,
98+
// Addition continuity: add4 requires add3
99+
ADD_CONTINUITY_4 = 30,
100+
// Cross-row continuity: if add spans two rows, add4 must be 1
101+
ADD_CROSS_ROW_CONTINUITY = 31,
102+
// add1 = q_add + q_skew
103+
ADD1_DECOMPOSITION = 32,
104+
// q_skew persists until MSM transition: q_skew && !msm_transition_shift => q_skew_shift
105+
SKEW_PERSISTS_UNTIL_MSM_TRANSITION = 33,
106+
// q_skew implies round == 32
107+
SKEW_IMPLIES_ROUND_32 = 34,
108+
// Doubling requires a round change (round_delta must be 1 if q_double_shift)
109+
DOUBLE_REQUIRES_ROUND_CHANGE = 35,
110+
// Additional addition slope constraints (split to prevent cancellation)
111+
ADD_SLOPE_2 = 36,
112+
ADD_SLOPE_3 = 37,
113+
ADD_SLOPE_4 = 38,
114+
// Additional doubling slope constraints (split to prevent cancellation)
115+
DOUBLE_SLOPE_2 = 39,
116+
DOUBLE_SLOPE_3 = 40,
117+
DOUBLE_SLOPE_4 = 41,
118+
// Additional skew slope constraints (split to prevent cancellation)
119+
SKEW_SLOPE_2 = 42,
120+
SKEW_SLOPE_3 = 43,
121+
SKEW_SLOPE_4 = 44,
122+
// Idle row: accumulator preserved when no phase selector is active
123+
IDLE_ROW_PRESERVES_ACC_X = 45,
124+
IDLE_ROW_PRESERVES_ACC_Y = 46,
125+
NUM_SUBRELATIONS,
126+
};
127+
46128
static constexpr std::array<size_t, 47> SUBRELATION_PARTIAL_LENGTHS{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
47129
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
48130
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
131+
static_assert(NUM_SUBRELATIONS == SUBRELATION_PARTIAL_LENGTHS.size());
49132

50133
template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
51134
static void accumulate(ContainerOverSubrelations& accumulator,

0 commit comments

Comments
 (0)