Skip to content

Commit 0e2c862

Browse files
dbanks12claude
andcommitted
fix: add missing boolean constraint for start_sha256 in bitwise.pil
The start_sha256 column was declared but lacked a boolean constraint, which is required since it's used as a destination selector for lookups from SHA256 into the bitwise trace. Added: start_sha256 * (1 - start_sha256) = 0; This was found during a comprehensive audit of the bitwise component. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e4fe106 commit 0e2c862

File tree

4 files changed

+63
-56
lines changed

4 files changed

+63
-56
lines changed

barretenberg/cpp/pil/vm2/bitwise.pil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ start * (1 - start) = 0;
5757
pol commit start_keccak;
5858
pol commit start_sha256;
5959
start_keccak * (1 - start_keccak) = 0;
60+
start_sha256 * (1 - start_sha256) = 0;
6061
// If any of the above selectors is 1, then start must be 1.
6162
(start_keccak + start_sha256) * (1 - start) = 0;
6263

barretenberg/cpp/src/barretenberg/vm2/generated/flavor_variables.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct AvmFlavorVariables {
145145
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 124;
146146
static constexpr size_t NUM_WITNESS_ENTITIES = 3061;
147147
static constexpr size_t NUM_SHIFTED_ENTITIES = 344;
148-
static constexpr size_t NUM_WIRES = 2595;
148+
static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES;
149149
static constexpr size_t NUM_ALL_ENTITIES = 3529;
150150

151151
// Need to be templated for recursive verifier

barretenberg/cpp/src/barretenberg/vm2/generated/relations/bitwise.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ template <typename FF_> class bitwiseImpl {
1414
public:
1515
using FF = FF_;
1616

17-
static constexpr std::array<size_t, 23> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 5,
18-
3, 4, 4, 5, 3, 3, 3, 3, 3, 3, 3 };
17+
static constexpr std::array<size_t, 24> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5,
18+
5, 3, 4, 4, 5, 3, 3, 3, 3, 3, 3, 3 };
1919

2020
template <typename AllEntities> inline static bool skip(const AllEntities& in)
2121
{
@@ -36,20 +36,20 @@ template <typename FF> class bitwise : public Relation<bitwiseImpl<FF>> {
3636
static constexpr const std::string_view NAME = "bitwise";
3737

3838
// Subrelation indices constants, to be used in tests.
39-
static constexpr size_t SR_LAST_ON_ERROR = 8;
40-
static constexpr size_t SR_RES_TAG_SHOULD_MATCH_INPUT = 9;
41-
static constexpr size_t SR_INPUT_TAG_CANNOT_BE_FF = 10;
42-
static constexpr size_t SR_INPUT_TAGS_SHOULD_MATCH = 11;
43-
static constexpr size_t SR_BITW_OP_ID_REL = 12;
44-
static constexpr size_t SR_BITW_CTR_DECREMENT = 13;
45-
static constexpr size_t SR_BITW_SEL_CTR_NON_ZERO = 14;
46-
static constexpr size_t SR_BITW_LAST_FOR_CTR_ONE = 15;
47-
static constexpr size_t SR_BITW_INIT_A = 16;
48-
static constexpr size_t SR_BITW_INIT_B = 17;
49-
static constexpr size_t SR_BITW_INIT_C = 18;
50-
static constexpr size_t SR_BITW_ACC_REL_A = 19;
51-
static constexpr size_t SR_BITW_ACC_REL_B = 20;
52-
static constexpr size_t SR_BITW_ACC_REL_C = 21;
39+
static constexpr size_t SR_LAST_ON_ERROR = 9;
40+
static constexpr size_t SR_RES_TAG_SHOULD_MATCH_INPUT = 10;
41+
static constexpr size_t SR_INPUT_TAG_CANNOT_BE_FF = 11;
42+
static constexpr size_t SR_INPUT_TAGS_SHOULD_MATCH = 12;
43+
static constexpr size_t SR_BITW_OP_ID_REL = 13;
44+
static constexpr size_t SR_BITW_CTR_DECREMENT = 14;
45+
static constexpr size_t SR_BITW_SEL_CTR_NON_ZERO = 15;
46+
static constexpr size_t SR_BITW_LAST_FOR_CTR_ONE = 16;
47+
static constexpr size_t SR_BITW_INIT_A = 17;
48+
static constexpr size_t SR_BITW_INIT_B = 18;
49+
static constexpr size_t SR_BITW_INIT_C = 19;
50+
static constexpr size_t SR_BITW_ACC_REL_A = 20;
51+
static constexpr size_t SR_BITW_ACC_REL_B = 21;
52+
static constexpr size_t SR_BITW_ACC_REL_C = 22;
5353

5454
static std::string get_subrelation_label(size_t index)
5555
{

barretenberg/cpp/src/barretenberg/vm2/generated/relations/bitwise_impl.hpp

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,143 +37,149 @@ void bitwiseImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
3737
}
3838
{
3939
using View = typename std::tuple_element_t<3, ContainerOverSubrelations>::View;
40+
auto tmp = static_cast<View>(in.get(C::bitwise_start_sha256)) *
41+
(FF(1) - static_cast<View>(in.get(C::bitwise_start_sha256)));
42+
std::get<3>(evals) += (tmp * scaling_factor);
43+
}
44+
{
45+
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
4046
auto tmp =
4147
(static_cast<View>(in.get(C::bitwise_start_keccak)) + static_cast<View>(in.get(C::bitwise_start_sha256))) *
4248
(FF(1) - static_cast<View>(in.get(C::bitwise_start)));
43-
std::get<3>(evals) += (tmp * scaling_factor);
49+
std::get<4>(evals) += (tmp * scaling_factor);
4450
}
4551
{
46-
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
52+
using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
4753
auto tmp = static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)) *
4854
(FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)));
49-
std::get<4>(evals) += (tmp * scaling_factor);
55+
std::get<5>(evals) += (tmp * scaling_factor);
5056
}
5157
{
52-
using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
58+
using View = typename std::tuple_element_t<6, ContainerOverSubrelations>::View;
5359
auto tmp = static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err)) *
5460
(FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err)));
55-
std::get<5>(evals) += (tmp * scaling_factor);
61+
std::get<6>(evals) += (tmp * scaling_factor);
5662
}
5763
{
58-
using View = typename std::tuple_element_t<6, ContainerOverSubrelations>::View;
64+
using View = typename std::tuple_element_t<7, ContainerOverSubrelations>::View;
5965
auto tmp = (static_cast<View>(in.get(C::bitwise_err)) -
6066
(FF(1) - (FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err))) *
6167
(FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)))));
62-
std::get<6>(evals) += (tmp * scaling_factor);
68+
std::get<7>(evals) += (tmp * scaling_factor);
6369
}
6470
{
65-
using View = typename std::tuple_element_t<7, ContainerOverSubrelations>::View;
71+
using View = typename std::tuple_element_t<8, ContainerOverSubrelations>::View;
6672
auto tmp = static_cast<View>(in.get(C::bitwise_last)) * (FF(1) - static_cast<View>(in.get(C::bitwise_last)));
67-
std::get<7>(evals) += (tmp * scaling_factor);
73+
std::get<8>(evals) += (tmp * scaling_factor);
6874
}
6975
{ // LAST_ON_ERROR
70-
using View = typename std::tuple_element_t<8, ContainerOverSubrelations>::View;
76+
using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
7177
auto tmp = static_cast<View>(in.get(C::bitwise_err)) * (static_cast<View>(in.get(C::bitwise_last)) - FF(1));
72-
std::get<8>(evals) += (tmp * scaling_factor);
78+
std::get<9>(evals) += (tmp * scaling_factor);
7379
}
7480
{ // RES_TAG_SHOULD_MATCH_INPUT
75-
using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
81+
using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
7682
auto tmp = (FF(1) - static_cast<View>(in.get(C::bitwise_err))) * static_cast<View>(in.get(C::bitwise_start)) *
7783
(static_cast<View>(in.get(C::bitwise_tag_c)) - static_cast<View>(in.get(C::bitwise_tag_a)));
78-
std::get<9>(evals) += (tmp * scaling_factor);
84+
std::get<10>(evals) += (tmp * scaling_factor);
7985
}
8086
{ // INPUT_TAG_CANNOT_BE_FF
81-
using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
87+
using View = typename std::tuple_element_t<11, ContainerOverSubrelations>::View;
8288
auto tmp = static_cast<View>(in.get(C::bitwise_start)) *
8389
((CView(bitwise_TAG_A_DIFF) * (static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)) *
8490
(FF(1) - static_cast<View>(in.get(C::bitwise_tag_a_inv))) +
8591
static_cast<View>(in.get(C::bitwise_tag_a_inv))) -
8692
FF(1)) +
8793
static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)));
88-
std::get<10>(evals) += (tmp * scaling_factor);
94+
std::get<11>(evals) += (tmp * scaling_factor);
8995
}
9096
{ // INPUT_TAGS_SHOULD_MATCH
91-
using View = typename std::tuple_element_t<11, ContainerOverSubrelations>::View;
97+
using View = typename std::tuple_element_t<12, ContainerOverSubrelations>::View;
9298
auto tmp = static_cast<View>(in.get(C::bitwise_start)) *
9399
(CView(bitwise_TAG_AB_DIFF) * ((FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err))) *
94100
(FF(1) - static_cast<View>(in.get(C::bitwise_tag_ab_diff_inv))) +
95101
static_cast<View>(in.get(C::bitwise_tag_ab_diff_inv))) -
96102
static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err)));
97-
std::get<11>(evals) += (tmp * scaling_factor);
103+
std::get<12>(evals) += (tmp * scaling_factor);
98104
}
99105
{ // BITW_OP_ID_REL
100-
using View = typename std::tuple_element_t<12, ContainerOverSubrelations>::View;
106+
using View = typename std::tuple_element_t<13, ContainerOverSubrelations>::View;
101107
auto tmp = (static_cast<View>(in.get(C::bitwise_op_id_shift)) - static_cast<View>(in.get(C::bitwise_op_id))) *
102108
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
103-
std::get<12>(evals) += (tmp * scaling_factor);
109+
std::get<13>(evals) += (tmp * scaling_factor);
104110
}
105111
{ // BITW_CTR_DECREMENT
106-
using View = typename std::tuple_element_t<13, ContainerOverSubrelations>::View;
112+
using View = typename std::tuple_element_t<14, ContainerOverSubrelations>::View;
107113
auto tmp =
108114
static_cast<View>(in.get(C::bitwise_sel)) *
109115
((static_cast<View>(in.get(C::bitwise_ctr_shift)) - static_cast<View>(in.get(C::bitwise_ctr))) + FF(1)) *
110116
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
111-
std::get<13>(evals) += (tmp * scaling_factor);
117+
std::get<14>(evals) += (tmp * scaling_factor);
112118
}
113119
{ // BITW_SEL_CTR_NON_ZERO
114-
using View = typename std::tuple_element_t<14, ContainerOverSubrelations>::View;
120+
using View = typename std::tuple_element_t<15, ContainerOverSubrelations>::View;
115121
auto tmp =
116122
(static_cast<View>(in.get(C::bitwise_ctr)) * ((FF(1) - static_cast<View>(in.get(C::bitwise_sel))) *
117123
(FF(1) - static_cast<View>(in.get(C::bitwise_ctr_inv))) +
118124
static_cast<View>(in.get(C::bitwise_ctr_inv))) -
119125
static_cast<View>(in.get(C::bitwise_sel)));
120-
std::get<14>(evals) += (tmp * scaling_factor);
126+
std::get<15>(evals) += (tmp * scaling_factor);
121127
}
122128
{ // BITW_LAST_FOR_CTR_ONE
123-
using View = typename std::tuple_element_t<15, ContainerOverSubrelations>::View;
129+
using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
124130
auto tmp = static_cast<View>(in.get(C::bitwise_sel)) *
125131
(((static_cast<View>(in.get(C::bitwise_ctr)) - FF(1)) *
126132
(static_cast<View>(in.get(C::bitwise_last)) *
127133
(FF(1) - static_cast<View>(in.get(C::bitwise_ctr_min_one_inv))) +
128134
static_cast<View>(in.get(C::bitwise_ctr_min_one_inv))) +
129135
static_cast<View>(in.get(C::bitwise_last))) -
130136
FF(1));
131-
std::get<15>(evals) += (tmp * scaling_factor);
137+
std::get<16>(evals) += (tmp * scaling_factor);
132138
}
133139
{ // BITW_INIT_A
134-
using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
140+
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
135141
auto tmp = static_cast<View>(in.get(C::bitwise_last)) *
136142
(static_cast<View>(in.get(C::bitwise_acc_ia)) - static_cast<View>(in.get(C::bitwise_ia_byte)));
137-
std::get<16>(evals) += (tmp * scaling_factor);
143+
std::get<17>(evals) += (tmp * scaling_factor);
138144
}
139145
{ // BITW_INIT_B
140-
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
146+
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
141147
auto tmp = static_cast<View>(in.get(C::bitwise_last)) *
142148
(static_cast<View>(in.get(C::bitwise_acc_ib)) - static_cast<View>(in.get(C::bitwise_ib_byte)));
143-
std::get<17>(evals) += (tmp * scaling_factor);
149+
std::get<18>(evals) += (tmp * scaling_factor);
144150
}
145151
{ // BITW_INIT_C
146-
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
152+
using View = typename std::tuple_element_t<19, ContainerOverSubrelations>::View;
147153
auto tmp = static_cast<View>(in.get(C::bitwise_last)) *
148154
(static_cast<View>(in.get(C::bitwise_acc_ic)) - static_cast<View>(in.get(C::bitwise_ic_byte)));
149-
std::get<18>(evals) += (tmp * scaling_factor);
155+
std::get<19>(evals) += (tmp * scaling_factor);
150156
}
151157
{ // BITW_ACC_REL_A
152-
using View = typename std::tuple_element_t<19, ContainerOverSubrelations>::View;
158+
using View = typename std::tuple_element_t<20, ContainerOverSubrelations>::View;
153159
auto tmp = ((static_cast<View>(in.get(C::bitwise_acc_ia)) - static_cast<View>(in.get(C::bitwise_ia_byte))) -
154160
FF(256) * static_cast<View>(in.get(C::bitwise_acc_ia_shift))) *
155161
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
156-
std::get<19>(evals) += (tmp * scaling_factor);
162+
std::get<20>(evals) += (tmp * scaling_factor);
157163
}
158164
{ // BITW_ACC_REL_B
159-
using View = typename std::tuple_element_t<20, ContainerOverSubrelations>::View;
165+
using View = typename std::tuple_element_t<21, ContainerOverSubrelations>::View;
160166
auto tmp = ((static_cast<View>(in.get(C::bitwise_acc_ib)) - static_cast<View>(in.get(C::bitwise_ib_byte))) -
161167
FF(256) * static_cast<View>(in.get(C::bitwise_acc_ib_shift))) *
162168
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
163-
std::get<20>(evals) += (tmp * scaling_factor);
169+
std::get<21>(evals) += (tmp * scaling_factor);
164170
}
165171
{ // BITW_ACC_REL_C
166-
using View = typename std::tuple_element_t<21, ContainerOverSubrelations>::View;
172+
using View = typename std::tuple_element_t<22, ContainerOverSubrelations>::View;
167173
auto tmp = ((static_cast<View>(in.get(C::bitwise_acc_ic)) - static_cast<View>(in.get(C::bitwise_ic_byte))) -
168174
FF(256) * static_cast<View>(in.get(C::bitwise_acc_ic_shift))) *
169175
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
170-
std::get<21>(evals) += (tmp * scaling_factor);
176+
std::get<22>(evals) += (tmp * scaling_factor);
171177
}
172178
{
173-
using View = typename std::tuple_element_t<22, ContainerOverSubrelations>::View;
179+
using View = typename std::tuple_element_t<23, ContainerOverSubrelations>::View;
174180
auto tmp = (static_cast<View>(in.get(C::bitwise_sel_get_ctr)) -
175181
static_cast<View>(in.get(C::bitwise_start)) * (FF(1) - static_cast<View>(in.get(C::bitwise_err))));
176-
std::get<22>(evals) += (tmp * scaling_factor);
182+
std::get<23>(evals) += (tmp * scaling_factor);
177183
}
178184
}
179185

0 commit comments

Comments
 (0)