Skip to content

Commit f336e19

Browse files
notnotrajunotnotraju
andauthored
chore: audit ECCVM msm relation (#16532)
Audit of the MSM relation. There were a couple of columns that I think were underconstrained. I have made the MSM relations more robust/clear as to why they are correct. Aside from a few changes to the relations, this PR mostly involves a lot of documentation. The most important part of this is re: the multiset equality check. The description of _why_ this suffices to correctly constrain the q_add columns is more transparent now. --------- Co-authored-by: notnotraju <[email protected]>
1 parent 6da0f67 commit f336e19

File tree

9 files changed

+635
-454
lines changed

9 files changed

+635
-454
lines changed

barretenberg/cpp/src/barretenberg/eccvm/README.md

Lines changed: 334 additions & 324 deletions
Large diffs are not rendered by default.

barretenberg/cpp/src/barretenberg/eccvm/eccvm_builder_types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ template <typename CycleGroup> struct ScalarMul {
2828
typename CycleGroup::affine_element base_point;
2929
std::array<int, NUM_WNAF_DIGITS_PER_SCALAR>
3030
wnaf_digits; // [a_{n-1}, a_{n-1}, ..., a_{0}], where each a_i ∈ {-2ʷ⁻¹ + 1, -2ʷ⁻¹ + 3, ..., 2ʷ⁻¹ - 3, 2ʷ⁻¹ -
31-
// 1} ∪ {0}. (here, w = `NUM_WNAF_DIGIT_BITS`). in particular, a_i is an odd integer with
31+
// 1}. (here, w = `NUM_WNAF_DIGIT_BITS`). in particular, a_i is an odd integer with
3232
// absolute value less than 2ʷ. Represents the number `scalar` = ∑ᵢ aᵢ 2⁴ⁱ - `wnaf_skew`.
3333
bool wnaf_skew; // necessary to represent _even_ integers
3434
// size bumped by 1 to record base_point.dbl()

barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class ECCVMCircuitBuilder {
182182
msm.resize(msm_sizes[i]);
183183
}
184184
// populate result using the auxiliary vectors `msm_opqueue_index` and `msm_mul_index`, together with
185-
// `eccvm_ops`. this first pass will *not* get the pc (program counter) correct. we explain why when we set it
185+
// `eccvm_ops`. this first pass will *not* get the pc (point counter) correct. we explain why when we set it
186186
// correctly.
187187
parallel_for_range(msm_opqueue_index.size(), [&](size_t start, size_t end) {
188188
for (size_t i = start; i < end; i++) {

barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ class ECCVMFlavor {
549549
* msm_lambda2: temp variable used for ecc point addition algorithm if msm_add2 = 1
550550
* msm_lambda3: temp variable used for ecc point addition algorithm if msm_add3 = 1
551551
* msm_lambda4: temp variable used for ecc point addition algorithm if msm_add4 = 1
552+
* msm_slice1: wNAF digit/slice for first add
553+
* msm_slice2: wNAF digit/slice for second add
554+
* msm_slice3: wNAF digit/slice for third add
555+
* msm_slice4: wNAF digit/slice for fourth add
552556
* msm_collision_x1: used to ensure incomplete ecc addition exceptions not triggered if msm_add1 = 1
553557
* msm_collision_x2: used to ensure incomplete ecc addition exceptions not triggered if msm_add2 = 1
554558
* msm_collision_x3: used to ensure incomplete ecc addition exceptions not triggered if msm_add3 = 1

barretenberg/cpp/src/barretenberg/eccvm/msm_builder.hpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ class ECCVMMSMMBuilder {
2727
static constexpr size_t NUM_WNAF_DIGITS_PER_SCALAR = bb::eccvm::NUM_WNAF_DIGITS_PER_SCALAR;
2828

2929
struct alignas(64) MSMRow {
30-
uint32_t pc = 0; // counter over all half-length (128 bit) scalar muls used to compute the required MSMs
31-
uint32_t msm_size = 0; // the number of points that will be scaled and summed
32-
uint32_t msm_count = 0; // number of multiplications processed so far in current MSM round
30+
uint32_t pc = 0; // decreasing point-counter, over all half-length (128 bit) scalar muls used to compute
31+
// the required MSMs. however, this value is _constant_ on a given MSM and more precisely
32+
// refers to the number of half-length scalar muls completed up until we have started
33+
// the current MSM.
34+
uint32_t msm_size = 0; // the number of points in (a.k.a. the length of) the MSM in whose computation
35+
// this VM row participates
36+
uint32_t msm_count = 0; // number of multiplications processed so far (not including this row) in current MSM
37+
// round (a.k.a. wNAF digit slot). this specifically refers to the number of wNAF-digit
38+
// * point scalar products we have looked up and accumulated.
3339
uint32_t msm_round = 0; // current "round" of MSM, in {0, ..., 32 = `NUM_WNAF_DIGITS_PER_SCALAR`}. With the
3440
// Straus algorithm, we proceed wNAF digit by wNAF digit, from left to right. (final
3541
// round deals with the `skew` bit.)
@@ -73,7 +79,7 @@ class ECCVMMSMMBuilder {
7379
* @brief Computes the row values for the Straus MSM columns of the ECCVM.
7480
*
7581
* For a detailed description of the Straus algorithm and its relation to the ECCVM, please see
76-
* https://hackmd.io/@aztec-network/rJ5xhuCsn
82+
* https://hackmd.io/@aztec-network/rJ5xhuCsn or, alternatively, the [ECCVM readme](README.md).
7783
*
7884
* @param msms A vector of vectors of `ScalarMul`s, a.k.a. a vector of `MSM`s.
7985
* @param point_table_read_counts Table of read counts to be populated.
@@ -96,17 +102,23 @@ class ECCVMMSMMBuilder {
96102
// row = point_idx * rows_per_point_table + (some function of the slice value)
97103
//
98104
// Illustration:
99-
// Block Structure Table structure:
100-
// | 0 | 1 | | Block_{0} | <-- pc = total_number_of_muls
101-
// | - | - | | Block_{1} | <-- pc = total_number_of_muls-(num muls in msm 0)
102-
// 1 | # | # | -1 | ... | ...
103-
// 3 | # | # | -3 | Block_{total_number_of_muls-1} | <-- pc = num muls in last msm
105+
// Block Structure:
106+
// | 0 | 1 |
107+
// | - | - |
108+
// 1 | # | # | -1
109+
// 3 | # | # | -3
104110
// 5 | # | # | -5
105111
// 7 | # | # | -7
106112
// 9 | # | # | -9
107113
// 11 | # | # | -11
108114
// 13 | # | # | -13
109115
// 15 | # | # | -15
116+
//
117+
// Table structure:
118+
// | Block_{0} | <-- pc = total_number_of_muls
119+
// | Block_{1} | <-- pc = total_number_of_muls-(num muls in msm 0)
120+
// | ... | ...
121+
// | Block_{total_number_of_muls-1} | <-- pc = num muls in last msm
110122

111123
const size_t num_rows_in_read_counts_table =
112124
static_cast<size_t>(total_number_of_muls) *
@@ -146,7 +158,7 @@ class ECCVMMSMMBuilder {
146158
std::vector<size_t> msm_row_counts;
147159
msm_row_counts.reserve(msms.size() + 1);
148160
msm_row_counts.push_back(1);
149-
// compute the program counter (i.e. the index among all single scalar muls) that each multiscalar
161+
// compute the point counter (i.e. the index among all single scalar muls) that each multiscalar
150162
// multiplication will start at.
151163
std::vector<size_t> pc_values;
152164
pc_values.reserve(msms.size() + 1);
@@ -203,7 +215,7 @@ class ECCVMMSMMBuilder {
203215
bool add = num_points_in_row > relative_point_idx;
204216
const size_t point_idx = offset + relative_point_idx;
205217
if (add) {
206-
// pc starts at total_number_of_muls and decreases non-uniformly to 0
218+
// `pc` starts at total_number_of_muls and decreases non-uniformly to 0.
207219
// -15 maps to the 1st point in the lookup table (array element 0)
208220
// -1 maps to the point in the lookup table that corresponds to the negation of the
209221
// original input point (i.e. the point we need to add into the accumulator if wnaf_skew

barretenberg/cpp/src/barretenberg/eccvm/transcript_builder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class ECCVMTranscriptBuilder {
109109

110110
// maintains the state of the VM at any given "time" (i.e., at any given value of pc).
111111
struct VMState {
112-
uint32_t pc = 0; // decreasing program counter that tracks the total number of multiplications that our virtual
113-
// machine has left to compute.
112+
uint32_t pc = 0; // decreasing point counter that tracks the total number of multiplications that our virtual
113+
// machine has left to compute.
114114
uint32_t count = 0; // Number of muls in the current MSM _excluding the current row_.
115115
Element accumulator = CycleGroup::affine_point_at_infinity; // accumulator for all group operations.
116116
Element msm_accumulator =

0 commit comments

Comments
 (0)