Skip to content

Commit dcd7a1e

Browse files
authored
fix: Consistent bit size for truncate (#4370)
# Description ## Problem\* Work towards #4369 ## Summary\* Uses consistent bit sizes for truncate and starts a refactor where we start to track bit sizes for values in brillig IR ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
1 parent e0ad0b2 commit dcd7a1e

File tree

9 files changed

+331
-252
lines changed

9 files changed

+331
-252
lines changed

compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ pub(crate) fn convert_black_box_call(
5656
}
5757
BlackBoxFunc::Keccak256 => {
5858
if let (
59-
[message, BrilligVariable::Simple(array_size)],
59+
[message, BrilligVariable::SingleAddr(array_size)],
6060
[BrilligVariable::BrilligArray(result_array)],
6161
) = (function_arguments, function_results)
6262
{
6363
let mut message_vector = convert_array_or_vector(brillig_context, message, bb_func);
64-
message_vector.size = *array_size;
64+
message_vector.size = array_size.address;
6565

6666
brillig_context.black_box_op_instruction(BlackBoxOp::Keccak256 {
6767
message: message_vector.to_heap_vector(),
@@ -88,7 +88,7 @@ pub(crate) fn convert_black_box_call(
8888
BlackBoxFunc::EcdsaSecp256k1 => {
8989
if let (
9090
[BrilligVariable::BrilligArray(public_key_x), BrilligVariable::BrilligArray(public_key_y), BrilligVariable::BrilligArray(signature), message],
91-
[BrilligVariable::Simple(result_register)],
91+
[BrilligVariable::SingleAddr(result_register)],
9292
) = (function_arguments, function_results)
9393
{
9494
let message_hash_vector =
@@ -98,7 +98,7 @@ pub(crate) fn convert_black_box_call(
9898
public_key_x: public_key_x.to_heap_array(),
9999
public_key_y: public_key_y.to_heap_array(),
100100
signature: signature.to_heap_array(),
101-
result: *result_register,
101+
result: result_register.address,
102102
});
103103
} else {
104104
unreachable!(
@@ -109,7 +109,7 @@ pub(crate) fn convert_black_box_call(
109109
BlackBoxFunc::EcdsaSecp256r1 => {
110110
if let (
111111
[BrilligVariable::BrilligArray(public_key_x), BrilligVariable::BrilligArray(public_key_y), BrilligVariable::BrilligArray(signature), message],
112-
[BrilligVariable::Simple(result_register)],
112+
[BrilligVariable::SingleAddr(result_register)],
113113
) = (function_arguments, function_results)
114114
{
115115
let message_hash_vector =
@@ -119,7 +119,7 @@ pub(crate) fn convert_black_box_call(
119119
public_key_x: public_key_x.to_heap_array(),
120120
public_key_y: public_key_y.to_heap_array(),
121121
signature: signature.to_heap_array(),
122-
result: *result_register,
122+
result: result_register.address,
123123
});
124124
} else {
125125
unreachable!(
@@ -130,14 +130,14 @@ pub(crate) fn convert_black_box_call(
130130

131131
BlackBoxFunc::PedersenCommitment => {
132132
if let (
133-
[message, BrilligVariable::Simple(domain_separator)],
133+
[message, BrilligVariable::SingleAddr(domain_separator)],
134134
[BrilligVariable::BrilligArray(result_array)],
135135
) = (function_arguments, function_results)
136136
{
137137
let message_vector = convert_array_or_vector(brillig_context, message, bb_func);
138138
brillig_context.black_box_op_instruction(BlackBoxOp::PedersenCommitment {
139139
inputs: message_vector.to_heap_vector(),
140-
domain_separator: *domain_separator,
140+
domain_separator: domain_separator.address,
141141
output: result_array.to_heap_array(),
142142
});
143143
} else {
@@ -146,48 +146,48 @@ pub(crate) fn convert_black_box_call(
146146
}
147147
BlackBoxFunc::PedersenHash => {
148148
if let (
149-
[message, BrilligVariable::Simple(domain_separator)],
150-
[BrilligVariable::Simple(result)],
149+
[message, BrilligVariable::SingleAddr(domain_separator)],
150+
[BrilligVariable::SingleAddr(result)],
151151
) = (function_arguments, function_results)
152152
{
153153
let message_vector = convert_array_or_vector(brillig_context, message, bb_func);
154154
brillig_context.black_box_op_instruction(BlackBoxOp::PedersenHash {
155155
inputs: message_vector.to_heap_vector(),
156-
domain_separator: *domain_separator,
157-
output: *result,
156+
domain_separator: domain_separator.address,
157+
output: result.address,
158158
});
159159
} else {
160160
unreachable!("ICE: Pedersen hash expects one array argument, a register for the domain separator, and one register result")
161161
}
162162
}
163163
BlackBoxFunc::SchnorrVerify => {
164164
if let (
165-
[BrilligVariable::Simple(public_key_x), BrilligVariable::Simple(public_key_y), BrilligVariable::BrilligArray(signature), message],
166-
[BrilligVariable::Simple(result_register)],
165+
[BrilligVariable::SingleAddr(public_key_x), BrilligVariable::SingleAddr(public_key_y), BrilligVariable::BrilligArray(signature), message],
166+
[BrilligVariable::SingleAddr(result_register)],
167167
) = (function_arguments, function_results)
168168
{
169169
let message_hash = convert_array_or_vector(brillig_context, message, bb_func);
170170
let signature = brillig_context.array_to_vector(signature);
171171
brillig_context.black_box_op_instruction(BlackBoxOp::SchnorrVerify {
172-
public_key_x: *public_key_x,
173-
public_key_y: *public_key_y,
172+
public_key_x: public_key_x.address,
173+
public_key_y: public_key_y.address,
174174
message: message_hash.to_heap_vector(),
175175
signature: signature.to_heap_vector(),
176-
result: *result_register,
176+
result: result_register.address,
177177
});
178178
} else {
179179
unreachable!("ICE: Schnorr verify expects two registers for the public key, an array for signature, an array for the message hash and one result register")
180180
}
181181
}
182182
BlackBoxFunc::FixedBaseScalarMul => {
183183
if let (
184-
[BrilligVariable::Simple(low), BrilligVariable::Simple(high)],
184+
[BrilligVariable::SingleAddr(low), BrilligVariable::SingleAddr(high)],
185185
[BrilligVariable::BrilligArray(result_array)],
186186
) = (function_arguments, function_results)
187187
{
188188
brillig_context.black_box_op_instruction(BlackBoxOp::FixedBaseScalarMul {
189-
low: *low,
190-
high: *high,
189+
low: low.address,
190+
high: high.address,
191191
result: result_array.to_heap_array(),
192192
});
193193
} else {
@@ -198,15 +198,15 @@ pub(crate) fn convert_black_box_call(
198198
}
199199
BlackBoxFunc::EmbeddedCurveAdd => {
200200
if let (
201-
[BrilligVariable::Simple(input1_x), BrilligVariable::Simple(input1_y), BrilligVariable::Simple(input2_x), BrilligVariable::Simple(input2_y)],
201+
[BrilligVariable::SingleAddr(input1_x), BrilligVariable::SingleAddr(input1_y), BrilligVariable::SingleAddr(input2_x), BrilligVariable::SingleAddr(input2_y)],
202202
[BrilligVariable::BrilligArray(result_array)],
203203
) = (function_arguments, function_results)
204204
{
205205
brillig_context.black_box_op_instruction(BlackBoxOp::EmbeddedCurveAdd {
206-
input1_x: *input1_x,
207-
input1_y: *input1_y,
208-
input2_x: *input2_x,
209-
input2_y: *input2_y,
206+
input1_x: input1_x.address,
207+
input1_y: input1_y.address,
208+
input2_x: input2_x.address,
209+
input2_y: input2_y.address,
210210
result: result_array.to_heap_array(),
211211
});
212212
} else {
@@ -229,14 +229,14 @@ pub(crate) fn convert_black_box_call(
229229
),
230230
BlackBoxFunc::BigIntAdd => {
231231
if let (
232-
[BrilligVariable::Simple(lhs), BrilligVariable::Simple(rhs)],
233-
[BrilligVariable::Simple(output)],
232+
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(rhs)],
233+
[BrilligVariable::SingleAddr(output)],
234234
) = (function_arguments, function_results)
235235
{
236236
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntAdd {
237-
lhs: *lhs,
238-
rhs: *rhs,
239-
output: *output,
237+
lhs: lhs.address,
238+
rhs: rhs.address,
239+
output: output.address,
240240
});
241241
} else {
242242
unreachable!(
@@ -246,14 +246,14 @@ pub(crate) fn convert_black_box_call(
246246
}
247247
BlackBoxFunc::BigIntSub => {
248248
if let (
249-
[BrilligVariable::Simple(lhs), BrilligVariable::Simple(rhs)],
250-
[BrilligVariable::Simple(output)],
249+
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(rhs)],
250+
[BrilligVariable::SingleAddr(output)],
251251
) = (function_arguments, function_results)
252252
{
253253
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntSub {
254-
lhs: *lhs,
255-
rhs: *rhs,
256-
output: *output,
254+
lhs: lhs.address,
255+
rhs: rhs.address,
256+
output: output.address,
257257
});
258258
} else {
259259
unreachable!(
@@ -263,14 +263,14 @@ pub(crate) fn convert_black_box_call(
263263
}
264264
BlackBoxFunc::BigIntMul => {
265265
if let (
266-
[BrilligVariable::Simple(lhs), BrilligVariable::Simple(rhs)],
267-
[BrilligVariable::Simple(output)],
266+
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(rhs)],
267+
[BrilligVariable::SingleAddr(output)],
268268
) = (function_arguments, function_results)
269269
{
270270
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntMul {
271-
lhs: *lhs,
272-
rhs: *rhs,
273-
output: *output,
271+
lhs: lhs.address,
272+
rhs: rhs.address,
273+
output: output.address,
274274
});
275275
} else {
276276
unreachable!(
@@ -280,14 +280,14 @@ pub(crate) fn convert_black_box_call(
280280
}
281281
BlackBoxFunc::BigIntDiv => {
282282
if let (
283-
[BrilligVariable::Simple(lhs), BrilligVariable::Simple(rhs)],
284-
[BrilligVariable::Simple(output)],
283+
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(rhs)],
284+
[BrilligVariable::SingleAddr(output)],
285285
) = (function_arguments, function_results)
286286
{
287287
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntDiv {
288-
lhs: *lhs,
289-
rhs: *rhs,
290-
output: *output,
288+
lhs: lhs.address,
289+
rhs: rhs.address,
290+
output: output.address,
291291
});
292292
} else {
293293
unreachable!(
@@ -296,15 +296,15 @@ pub(crate) fn convert_black_box_call(
296296
}
297297
}
298298
BlackBoxFunc::BigIntFromLeBytes => {
299-
if let ([inputs, modulus], [BrilligVariable::Simple(output)]) =
299+
if let ([inputs, modulus], [BrilligVariable::SingleAddr(output)]) =
300300
(function_arguments, function_results)
301301
{
302302
let inputs_vector = convert_array_or_vector(brillig_context, inputs, bb_func);
303303
let modulus_vector = convert_array_or_vector(brillig_context, modulus, bb_func);
304304
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntFromLeBytes {
305305
inputs: inputs_vector.to_heap_vector(),
306306
modulus: modulus_vector.to_heap_vector(),
307-
output: *output,
307+
output: output.address,
308308
});
309309
} else {
310310
unreachable!(
@@ -314,12 +314,12 @@ pub(crate) fn convert_black_box_call(
314314
}
315315
BlackBoxFunc::BigIntToLeBytes => {
316316
if let (
317-
[BrilligVariable::Simple(input)],
317+
[BrilligVariable::SingleAddr(input)],
318318
[BrilligVariable::BrilligVector(result_vector)],
319319
) = (function_arguments, function_results)
320320
{
321321
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntToLeBytes {
322-
input: *input,
322+
input: input.address,
323323
output: result_vector.to_heap_vector(),
324324
});
325325
} else {
@@ -330,15 +330,15 @@ pub(crate) fn convert_black_box_call(
330330
}
331331
BlackBoxFunc::Poseidon2Permutation => {
332332
if let (
333-
[message, BrilligVariable::Simple(state_len)],
333+
[message, BrilligVariable::SingleAddr(state_len)],
334334
[BrilligVariable::BrilligArray(result_array)],
335335
) = (function_arguments, function_results)
336336
{
337337
let message_vector = convert_array_or_vector(brillig_context, message, bb_func);
338338
brillig_context.black_box_op_instruction(BlackBoxOp::Poseidon2Permutation {
339339
message: message_vector.to_heap_vector(),
340340
output: result_array.to_heap_array(),
341-
len: *state_len,
341+
len: state_len.address,
342342
});
343343
} else {
344344
unreachable!("ICE: Poseidon2Permutation expects one array argument, a length and one array result")

0 commit comments

Comments
 (0)