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
8
#include "
barretenberg/relations/relation_types.hpp
"
9
10
namespace
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.
15
inline
constexpr
size_t
LAST_ADDITION_ROUND
= 31;
16
48
template
<
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
55
ADD_ACC_X
= 0,
56
ADD_ACC_Y
= 1,
57
ADD_SLOPE_1
= 2,
58
ADD_SLOPE_2
= 3,
59
ADD_SLOPE_3
= 4,
60
ADD_SLOPE_4
= 5,
61
// Doubling round: accumulator update and slope constraint
62
DOUBLE_ACC_X
= 6,
63
DOUBLE_ACC_Y
= 7,
64
DOUBLE_SLOPE_1
= 8,
65
DOUBLE_SLOPE_2
= 9,
66
DOUBLE_SLOPE_3
= 10,
67
DOUBLE_SLOPE_4
= 11,
68
// Skew round: accumulator update and slope constraint
69
SKEW_ACC_X
= 12,
70
SKEW_ACC_Y
= 13,
71
SKEW_SLOPE_1
= 14,
72
SKEW_SLOPE_2
= 15,
73
SKEW_SLOPE_3
= 16,
74
SKEW_SLOPE_4
= 17,
75
// Collision checks: x-coordinate non-equality for point additions
76
COLLISION_CHECK_1
= 18,
77
COLLISION_CHECK_2
= 19,
78
COLLISION_CHECK_3
= 20,
79
COLLISION_CHECK_4
= 21,
80
// Inactive slice zeroing: force slice_i = 0 when add_i = 0
81
INACTIVE_SLICE_1
= 22,
82
INACTIVE_SLICE_2
= 23,
83
INACTIVE_SLICE_3
= 24,
84
INACTIVE_SLICE_4
= 25,
85
// Phase selector mutual exclusivity: at most one of q_add, q_double, q_skew active
86
PHASE_SELECTOR_MUTUAL_EXCLUSIVITY
= 26,
87
// Round transition forces round_delta == 1
88
ROUND_TRANSITION_FORCES_DELTA_ONE
= 27,
89
// Round transition with skew implies round == 31
90
ROUND_TRANSITION_SKEW_IMPLIES_ROUND_31
= 28,
91
// Round transition requires exactly one of double or skew on next row
92
ROUND_TRANSITION_EXACTLY_ONE_DOUBLE_OR_SKEW
= 29,
93
// Round transition needs double or skew (cannot have neither)
94
ROUND_TRANSITION_NEEDS_DOUBLE_OR_SKEW
= 30,
95
// Double implies next row is an add row
96
DOUBLE_IMPLIES_NEXT_IS_ADD
= 31,
97
// Count shift must be zero when round changes
98
COUNT_SHIFT_ZERO_ON_ROUND_CHANGE
= 32,
99
// Count increments within the same round by number of active adds
100
COUNT_INCREMENT_WITHIN_ROUND
= 33,
101
// Count must be zero at round boundary or MSM transition
102
COUNT_ZERO_AT_ROUND_BOUNDARY_OR_TRANSITION
= 34,
103
// MSM transition implies round = 0
104
MSM_TRANSITION_ROUND_ZERO
= 35,
105
// MSM transition: pc = pc_shift + msm_size
106
MSM_TRANSITION_PC
= 36,
107
// Addition continuity: add2 requires add1
108
ADD_CONTINUITY_2
= 37,
109
// Addition continuity: add3 requires add2
110
ADD_CONTINUITY_3
= 38,
111
// Addition continuity: add4 requires add3
112
ADD_CONTINUITY_4
= 39,
113
// Cross-row continuity: if add spans two rows, add4 must be 1
114
ADD_CROSS_ROW_CONTINUITY
= 40,
115
// add1 = q_add + q_skew
116
ADD1_DECOMPOSITION
= 41,
117
// q_skew persists until MSM transition: q_skew && !msm_transition_shift => q_skew_shift
118
SKEW_PERSISTS_UNTIL_MSM_TRANSITION
= 42,
119
// q_skew implies round == 32
120
SKEW_IMPLIES_ROUND_32
= 43,
121
// Doubling requires a round change (round_delta must be 1 if q_double_shift)
122
DOUBLE_REQUIRES_ROUND_CHANGE
= 44,
123
// Idle row: accumulator preserved when no phase selector is active
124
IDLE_ROW_PRESERVES_ACC_X
= 45,
125
IDLE_ROW_PRESERVES_ACC_Y
= 46,
126
// If q_double_shift = 1, the current row cannot be the final addition round (round 31)
127
DOUBLE_SHIFT_FORBIDS_ROUND_31
= 47,
128
// MSM-start anchor: msm_transition must be 1 at the first row of every MSM block
129
MSM_TRANSITION_AT_ACTIVE_START
= 48,
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.
136
MSM_PC_CONTINUITY
= 49,
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.
146
MSM_PC_SKEW_CONTINUITY
= 50,
147
NUM_SUBRELATIONS
,
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
163
template
<
typename
FF>
using
ECCVMMSMRelation
=
Relation<ECCVMMSMRelationImpl<FF>
>;
164
165
}
// namespace bb
bb::ECCVMMSMRelationImpl
MSM relations that evaluate the Strauss multiscalar multiplication algorithm.
Definition
ecc_msm_relation.hpp:48
bb::ECCVMMSMRelationImpl::SUBRELATION_PARTIAL_LENGTHS
static constexpr std::array< size_t, 51 > SUBRELATION_PARTIAL_LENGTHS
Definition
ecc_msm_relation.hpp:150
bb::ECCVMMSMRelationImpl::accumulate
static void accumulate(ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters &, const FF &scaling_factor)
MSM relations that evaluate the Strauss multiscalar multiplication algorithm.
Definition
ecc_msm_relation_impl.hpp:48
bb::ECCVMMSMRelationImpl::FF
FF_ FF
Definition
ecc_msm_relation.hpp:50
bb::ECCVMMSMRelationImpl::SubrelationIndex
SubrelationIndex
Definition
ecc_msm_relation.hpp:53
bb::ECCVMMSMRelationImpl::DOUBLE_SLOPE_4
@ DOUBLE_SLOPE_4
Definition
ecc_msm_relation.hpp:67
bb::ECCVMMSMRelationImpl::ADD_CONTINUITY_3
@ ADD_CONTINUITY_3
Definition
ecc_msm_relation.hpp:110
bb::ECCVMMSMRelationImpl::COUNT_INCREMENT_WITHIN_ROUND
@ COUNT_INCREMENT_WITHIN_ROUND
Definition
ecc_msm_relation.hpp:100
bb::ECCVMMSMRelationImpl::COUNT_SHIFT_ZERO_ON_ROUND_CHANGE
@ COUNT_SHIFT_ZERO_ON_ROUND_CHANGE
Definition
ecc_msm_relation.hpp:98
bb::ECCVMMSMRelationImpl::MSM_PC_SKEW_CONTINUITY
@ MSM_PC_SKEW_CONTINUITY
Definition
ecc_msm_relation.hpp:146
bb::ECCVMMSMRelationImpl::MSM_PC_CONTINUITY
@ MSM_PC_CONTINUITY
Definition
ecc_msm_relation.hpp:136
bb::ECCVMMSMRelationImpl::COLLISION_CHECK_4
@ COLLISION_CHECK_4
Definition
ecc_msm_relation.hpp:79
bb::ECCVMMSMRelationImpl::DOUBLE_SLOPE_2
@ DOUBLE_SLOPE_2
Definition
ecc_msm_relation.hpp:65
bb::ECCVMMSMRelationImpl::SKEW_ACC_Y
@ SKEW_ACC_Y
Definition
ecc_msm_relation.hpp:70
bb::ECCVMMSMRelationImpl::IDLE_ROW_PRESERVES_ACC_Y
@ IDLE_ROW_PRESERVES_ACC_Y
Definition
ecc_msm_relation.hpp:125
bb::ECCVMMSMRelationImpl::ROUND_TRANSITION_SKEW_IMPLIES_ROUND_31
@ ROUND_TRANSITION_SKEW_IMPLIES_ROUND_31
Definition
ecc_msm_relation.hpp:90
bb::ECCVMMSMRelationImpl::NUM_SUBRELATIONS
@ NUM_SUBRELATIONS
Definition
ecc_msm_relation.hpp:147
bb::ECCVMMSMRelationImpl::ADD_SLOPE_1
@ ADD_SLOPE_1
Definition
ecc_msm_relation.hpp:57
bb::ECCVMMSMRelationImpl::ADD_ACC_X
@ ADD_ACC_X
Definition
ecc_msm_relation.hpp:55
bb::ECCVMMSMRelationImpl::COLLISION_CHECK_1
@ COLLISION_CHECK_1
Definition
ecc_msm_relation.hpp:76
bb::ECCVMMSMRelationImpl::INACTIVE_SLICE_3
@ INACTIVE_SLICE_3
Definition
ecc_msm_relation.hpp:83
bb::ECCVMMSMRelationImpl::ROUND_TRANSITION_NEEDS_DOUBLE_OR_SKEW
@ ROUND_TRANSITION_NEEDS_DOUBLE_OR_SKEW
Definition
ecc_msm_relation.hpp:94
bb::ECCVMMSMRelationImpl::INACTIVE_SLICE_4
@ INACTIVE_SLICE_4
Definition
ecc_msm_relation.hpp:84
bb::ECCVMMSMRelationImpl::SKEW_IMPLIES_ROUND_32
@ SKEW_IMPLIES_ROUND_32
Definition
ecc_msm_relation.hpp:120
bb::ECCVMMSMRelationImpl::ADD_CONTINUITY_2
@ ADD_CONTINUITY_2
Definition
ecc_msm_relation.hpp:108
bb::ECCVMMSMRelationImpl::DOUBLE_REQUIRES_ROUND_CHANGE
@ DOUBLE_REQUIRES_ROUND_CHANGE
Definition
ecc_msm_relation.hpp:122
bb::ECCVMMSMRelationImpl::SKEW_SLOPE_2
@ SKEW_SLOPE_2
Definition
ecc_msm_relation.hpp:72
bb::ECCVMMSMRelationImpl::MSM_TRANSITION_AT_ACTIVE_START
@ MSM_TRANSITION_AT_ACTIVE_START
Definition
ecc_msm_relation.hpp:129
bb::ECCVMMSMRelationImpl::INACTIVE_SLICE_1
@ INACTIVE_SLICE_1
Definition
ecc_msm_relation.hpp:81
bb::ECCVMMSMRelationImpl::ADD_CONTINUITY_4
@ ADD_CONTINUITY_4
Definition
ecc_msm_relation.hpp:112
bb::ECCVMMSMRelationImpl::INACTIVE_SLICE_2
@ INACTIVE_SLICE_2
Definition
ecc_msm_relation.hpp:82
bb::ECCVMMSMRelationImpl::ADD1_DECOMPOSITION
@ ADD1_DECOMPOSITION
Definition
ecc_msm_relation.hpp:116
bb::ECCVMMSMRelationImpl::IDLE_ROW_PRESERVES_ACC_X
@ IDLE_ROW_PRESERVES_ACC_X
Definition
ecc_msm_relation.hpp:124
bb::ECCVMMSMRelationImpl::DOUBLE_ACC_X
@ DOUBLE_ACC_X
Definition
ecc_msm_relation.hpp:62
bb::ECCVMMSMRelationImpl::COLLISION_CHECK_2
@ COLLISION_CHECK_2
Definition
ecc_msm_relation.hpp:77
bb::ECCVMMSMRelationImpl::SKEW_SLOPE_3
@ SKEW_SLOPE_3
Definition
ecc_msm_relation.hpp:73
bb::ECCVMMSMRelationImpl::COLLISION_CHECK_3
@ COLLISION_CHECK_3
Definition
ecc_msm_relation.hpp:78
bb::ECCVMMSMRelationImpl::ADD_SLOPE_4
@ ADD_SLOPE_4
Definition
ecc_msm_relation.hpp:60
bb::ECCVMMSMRelationImpl::ADD_CROSS_ROW_CONTINUITY
@ ADD_CROSS_ROW_CONTINUITY
Definition
ecc_msm_relation.hpp:114
bb::ECCVMMSMRelationImpl::ADD_SLOPE_3
@ ADD_SLOPE_3
Definition
ecc_msm_relation.hpp:59
bb::ECCVMMSMRelationImpl::DOUBLE_SLOPE_1
@ DOUBLE_SLOPE_1
Definition
ecc_msm_relation.hpp:64
bb::ECCVMMSMRelationImpl::DOUBLE_SHIFT_FORBIDS_ROUND_31
@ DOUBLE_SHIFT_FORBIDS_ROUND_31
Definition
ecc_msm_relation.hpp:127
bb::ECCVMMSMRelationImpl::SKEW_PERSISTS_UNTIL_MSM_TRANSITION
@ SKEW_PERSISTS_UNTIL_MSM_TRANSITION
Definition
ecc_msm_relation.hpp:118
bb::ECCVMMSMRelationImpl::DOUBLE_SLOPE_3
@ DOUBLE_SLOPE_3
Definition
ecc_msm_relation.hpp:66
bb::ECCVMMSMRelationImpl::SKEW_SLOPE_4
@ SKEW_SLOPE_4
Definition
ecc_msm_relation.hpp:74
bb::ECCVMMSMRelationImpl::DOUBLE_ACC_Y
@ DOUBLE_ACC_Y
Definition
ecc_msm_relation.hpp:63
bb::ECCVMMSMRelationImpl::ROUND_TRANSITION_EXACTLY_ONE_DOUBLE_OR_SKEW
@ ROUND_TRANSITION_EXACTLY_ONE_DOUBLE_OR_SKEW
Definition
ecc_msm_relation.hpp:92
bb::ECCVMMSMRelationImpl::ADD_SLOPE_2
@ ADD_SLOPE_2
Definition
ecc_msm_relation.hpp:58
bb::ECCVMMSMRelationImpl::ADD_ACC_Y
@ ADD_ACC_Y
Definition
ecc_msm_relation.hpp:56
bb::ECCVMMSMRelationImpl::DOUBLE_IMPLIES_NEXT_IS_ADD
@ DOUBLE_IMPLIES_NEXT_IS_ADD
Definition
ecc_msm_relation.hpp:96
bb::ECCVMMSMRelationImpl::COUNT_ZERO_AT_ROUND_BOUNDARY_OR_TRANSITION
@ COUNT_ZERO_AT_ROUND_BOUNDARY_OR_TRANSITION
Definition
ecc_msm_relation.hpp:102
bb::ECCVMMSMRelationImpl::MSM_TRANSITION_ROUND_ZERO
@ MSM_TRANSITION_ROUND_ZERO
Definition
ecc_msm_relation.hpp:104
bb::ECCVMMSMRelationImpl::MSM_TRANSITION_PC
@ MSM_TRANSITION_PC
Definition
ecc_msm_relation.hpp:106
bb::ECCVMMSMRelationImpl::SKEW_SLOPE_1
@ SKEW_SLOPE_1
Definition
ecc_msm_relation.hpp:71
bb::ECCVMMSMRelationImpl::SKEW_ACC_X
@ SKEW_ACC_X
Definition
ecc_msm_relation.hpp:69
bb::ECCVMMSMRelationImpl::PHASE_SELECTOR_MUTUAL_EXCLUSIVITY
@ PHASE_SELECTOR_MUTUAL_EXCLUSIVITY
Definition
ecc_msm_relation.hpp:86
bb::ECCVMMSMRelationImpl::ROUND_TRANSITION_FORCES_DELTA_ONE
@ ROUND_TRANSITION_FORCES_DELTA_ONE
Definition
ecc_msm_relation.hpp:88
bb::MegaFlavor_Generated::AllEntities
Definition
mega_flavor_generated.hpp:277
bb::Relation
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
Definition
relation_types.hpp:129
bb
Entry point for Barretenberg command-line interface.
Definition
api.hpp:5
bb::LAST_ADDITION_ROUND
constexpr size_t LAST_ADDITION_ROUND
Definition
ecc_msm_relation.hpp:15
relation_types.hpp
bb::field< bb::Bn254FrParams >
src
barretenberg
relations
ecc_vm
ecc_msm_relation.hpp
Generated by
1.9.8