Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ecc_msm_relation.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Raju], commit: 2a49eb6 }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
9
10namespace bb {
11
12// Index of the final addition round in the Straus algorithm (rounds 0..LAST_ADDITION_ROUND are
13// addition rounds; round LAST_ADDITION_ROUND + 1 is the skew round). Used both by the MSM
14// relation (e.g. the round_minus_31_inv witness gate) and by the flavor's witness population.
15inline constexpr size_t LAST_ADDITION_ROUND = 31;
16
48template <typename FF_> class ECCVMMSMRelationImpl {
49 public:
50 using FF = FF_;
51 // Named subrelation indices — matches SUBRELATION_PARTIAL_LENGTHS ordering.
52 // Grouped by logical function within the Strauss MSM algorithm.
53 enum SubrelationIndex : size_t {
54 // Addition round: accumulator update and slope constraints
61 // Doubling round: accumulator update and slope constraint
68 // Skew round: accumulator update and slope constraint
75 // Collision checks: x-coordinate non-equality for point additions
80 // Inactive slice zeroing: force slice_i = 0 when add_i = 0
85 // Phase selector mutual exclusivity: at most one of q_add, q_double, q_skew active
87 // Round transition forces round_delta == 1
89 // Round transition with skew implies round == 31
91 // Round transition requires exactly one of double or skew on next row
93 // Round transition needs double or skew (cannot have neither)
95 // Double implies next row is an add row
97 // Count shift must be zero when round changes
99 // Count increments within the same round by number of active adds
101 // Count must be zero at round boundary or MSM transition
103 // MSM transition implies round = 0
105 // MSM transition: pc = pc_shift + msm_size
107 // Addition continuity: add2 requires add1
109 // Addition continuity: add3 requires add2
111 // Addition continuity: add4 requires add3
113 // Cross-row continuity: if add spans two rows, add4 must be 1
115 // add1 = q_add + q_skew
117 // q_skew persists until MSM transition: q_skew && !msm_transition_shift => q_skew_shift
119 // q_skew implies round == 32
121 // Doubling requires a round change (round_delta must be 1 if q_double_shift)
123 // Idle row: accumulator preserved when no phase selector is active
126 // If q_double_shift = 1, the current row cannot be the final addition round (round 31)
128 // MSM-start anchor: msm_transition must be 1 at the first row of every MSM block
130 // msm_pc is constant on every active row within an MSM segment (not the last row, where
131 // MSM_TRANSITION_PC pins the segment boundary). Without this, a malicious prover can
132 // swap msm_pc between two same-base MSMs on a single interior ADD row; the WNAF and
133 // point-table multisets still balance because both swapped tuples are valid writes, but
134 // the resulting MSM accumulators are swapped between segments — letting an op queue that
135 // should be rejected pass verification.
137 // msm_pc is constant across consecutive SKEW rows of an MSM segment. MSM_PC_CONTINUITY
138 // excludes q_skew (so it does not fire on the trace-final skew row, followed by idle rows
139 // where msm_transition_shift = 0), which leaves interior skew rows — present once a segment
140 // has >= 3 skew rows, i.e. msm_size >= 9 — pinned by neither MSM_PC_CONTINUITY nor
141 // MSM_TRANSITION_PC. A symmetric swap of (msm_pc, slice, x, y) between two segments on such a
142 // row balances the lookup multiset but swaps the segments' skew corrections. This term fires
143 // only between two consecutive skew rows (q_skew * q_skew_shift = 1), never at the trailing
144 // skew->idle boundary (where q_skew_shift = 0), so it closes the gap without the false
145 // positive that motivated dropping q_skew from MSM_PC_CONTINUITY.
148 };
149
150 static constexpr std::array<size_t, 51> SUBRELATION_PARTIAL_LENGTHS{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
151 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
152 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
153 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
154 static_assert(NUM_SUBRELATIONS == SUBRELATION_PARTIAL_LENGTHS.size());
155
156 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
157 static void accumulate(ContainerOverSubrelations& accumulator,
158 const AllEntities& in,
159 const Parameters& /* unused */,
160 const FF& scaling_factor);
161};
162
164
165} // namespace bb
MSM relations that evaluate the Strauss multiscalar multiplication algorithm.
static constexpr std::array< size_t, 51 > SUBRELATION_PARTIAL_LENGTHS
static void accumulate(ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters &, const FF &scaling_factor)
MSM relations that evaluate the Strauss multiscalar multiplication algorithm.
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr size_t LAST_ADDITION_ROUND