Skip to content

Commit 38ec7ea

Browse files
asteriteTomAFrench
authored andcommitted
chore!: remove is_infinite from EmbeddedCurvePoint
1 parent 208359b commit 38ec7ea

37 files changed

Lines changed: 305 additions & 792 deletions

File tree

acvm-repo/acir/codegen/acir.cpp

Lines changed: 7 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ pub enum BlackBoxFuncCall<F> {
177177
/// Coordinates of each point must be all witnesses or all constants.
178178
/// Similarly, both halves (lo, hi) of each scalar must be all witnesses or
179179
/// all constants. This is a backend requirement from Barretenberg.
180+
///
181+
/// The point at infinity is represented as `(0, 0)`.
180182
MultiScalarMul {
181183
points: Vec<FunctionInput<F>>,
182184
scalars: Vec<FunctionInput<F>>,
183185
predicate: FunctionInput<F>,
184-
outputs: (Witness, Witness, Witness),
186+
outputs: (Witness, Witness),
185187
},
186188
/// Addition over the embedded curve on which the witness is defined.
187189
/// The opcode makes the following assumptions but does not enforce them because
@@ -193,13 +195,15 @@ pub enum BlackBoxFuncCall<F> {
193195
/// If not, it assumes that the points' x-coordinates are not equal.
194196
/// It also assumes neither point is the infinity point.
195197
///
198+
/// The point at infinity is represented as `(0, 0)`.
199+
///
196200
/// Coordinates of each point must be all witnesses or all constants.
197201
/// This is a backend requirement from Barretenberg.
198202
EmbeddedCurveAdd {
199-
input1: Box<[FunctionInput<F>; 3]>,
200-
input2: Box<[FunctionInput<F>; 3]>,
203+
input1: Box<[FunctionInput<F>; 2]>,
204+
input2: Box<[FunctionInput<F>; 2]>,
201205
predicate: FunctionInput<F>,
202-
outputs: (Witness, Witness, Witness),
206+
outputs: (Witness, Witness),
203207
},
204208
/// Keccak Permutation function of width 1600
205209
/// - inputs: An array of 25 64-bit Keccak lanes that represent a keccak sponge of 1600 bits
@@ -331,7 +335,7 @@ impl<F> BlackBoxFuncCall<F> {
331335
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
332336
BlackBoxFuncCall::MultiScalarMul { outputs, .. }
333337
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => {
334-
vec![outputs.0, outputs.1, outputs.2]
338+
vec![outputs.0, outputs.1]
335339
}
336340
BlackBoxFuncCall::RANGE { .. } | BlackBoxFuncCall::RecursiveAggregation { .. } => {
337341
vec![]
@@ -364,7 +368,7 @@ impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
364368
[points.as_slice(), scalars.as_slice(), &[*predicate]].concat()
365369
}
366370
BlackBoxFuncCall::EmbeddedCurveAdd { input1, input2, predicate, outputs: _ } => {
367-
vec![input1[0], input1[1], input1[2], input2[0], input2[1], input2[2], *predicate]
371+
vec![input1[0], input1[1], input2[0], input2[1], *predicate]
368372
}
369373
BlackBoxFuncCall::EcdsaSecp256k1 {
370374
public_key_x,
@@ -494,17 +498,17 @@ impl<F: std::fmt::Display + Copy> std::fmt::Display for BlackBoxFuncCall<F> {
494498
let scalars = slice_to_string(scalars);
495499
write!(
496500
f,
497-
"points: {points}, scalars: {scalars}, predicate: {predicate}, outputs: [{}, {}, {}]",
498-
outputs.0, outputs.1, outputs.2
501+
"points: {points}, scalars: {scalars}, predicate: {predicate}, outputs: [{}, {}]",
502+
outputs.0, outputs.1
499503
)?;
500504
}
501505
BlackBoxFuncCall::EmbeddedCurveAdd { input1, input2, predicate, outputs } => {
502506
let input1 = slice_to_string(&input1.to_vec());
503507
let input2 = slice_to_string(&input2.to_vec());
504508
write!(
505509
f,
506-
"input1: {input1}, input2: {input2}, predicate: {predicate}, outputs: [{}, {}, {}]",
507-
outputs.0, outputs.1, outputs.2
510+
"input1: {input1}, input2: {input2}, predicate: {predicate}, outputs: [{}, {}]",
511+
outputs.0, outputs.1
508512
)?;
509513
}
510514
BlackBoxFuncCall::Keccakf1600 { inputs, outputs } => {
@@ -627,6 +631,7 @@ mod arb {
627631
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
628632
let input = any::<FunctionInput<F>>();
629633
let input_vec = any::<Vec<FunctionInput<F>>>();
634+
let input_arr_2 = any::<Box<[FunctionInput<F>; 2]>>();
630635
let input_arr_3 = any::<Box<[FunctionInput<F>; 3]>>();
631636
let input_arr_8 = any::<Box<[FunctionInput<F>; 8]>>();
632637
let input_arr_16 = any::<Box<[FunctionInput<F>; 16]>>();
@@ -660,7 +665,7 @@ mod arb {
660665
},
661666
);
662667

663-
let case_xor = (input_arr_3.clone(), input_arr_8.clone(), witness.clone()).prop_map(
668+
let case_xor = (input_arr_3, input_arr_8.clone(), witness.clone()).prop_map(
664669
|(lhs, rhs, output)| BlackBoxFuncCall::XOR {
665670
lhs: lhs[0],
666671
rhs: rhs[1],
@@ -732,33 +737,26 @@ mod arb {
732737
input.clone(),
733738
witness.clone(),
734739
witness.clone(),
735-
witness.clone(),
736740
)
737-
.prop_map(|(points, scalars, predicate, w1, w2, w3)| {
741+
.prop_map(|(points, scalars, predicate, w1, w2)| {
738742
BlackBoxFuncCall::MultiScalarMul {
739743
points,
740744
scalars,
741745
predicate,
742-
outputs: (w1, w2, w3),
746+
outputs: (w1, w2),
743747
}
744748
});
745749

746-
let case_embedded_curve_add = (
747-
input_arr_3.clone(),
748-
input_arr_3,
749-
input.clone(),
750-
witness.clone(),
751-
witness.clone(),
752-
witness,
753-
)
754-
.prop_map(|(input1, input2, predicate, w1, w2, w3)| {
755-
BlackBoxFuncCall::EmbeddedCurveAdd {
756-
input1,
757-
input2,
758-
predicate,
759-
outputs: (w1, w2, w3),
760-
}
761-
});
750+
let case_embedded_curve_add =
751+
(input_arr_2.clone(), input_arr_2, input.clone(), witness.clone(), witness)
752+
.prop_map(|(input1, input2, predicate, w1, w2)| {
753+
BlackBoxFuncCall::EmbeddedCurveAdd {
754+
input1,
755+
input2,
756+
predicate,
757+
outputs: (w1, w2),
758+
}
759+
});
762760

763761
let case_keccakf1600 = (input_arr_25, witness_arr_25)
764762
.prop_map(|(inputs, outputs)| BlackBoxFuncCall::Keccakf1600 { inputs, outputs });

acvm-repo/acir/src/parser/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ impl<'a> Parser<'a> {
501501
let predicate = self.parse_blackbox_input(Keyword::Predicate)?;
502502
self.eat_comma_or_error()?;
503503

504-
let outputs = self.parse_blackbox_outputs_array::<3>()?;
505-
let outputs = (outputs[0], outputs[1], outputs[2]);
504+
let outputs = self.parse_blackbox_outputs_array::<2>()?;
505+
let outputs = (outputs[0], outputs[1]);
506506

507507
BlackBoxFuncCall::MultiScalarMul { points, scalars, predicate, outputs }
508508
}
@@ -542,17 +542,17 @@ impl<'a> Parser<'a> {
542542
}
543543
}
544544
BlackBoxFunc::EmbeddedCurveAdd => {
545-
let input1 = self.parse_blackbox_inputs_array::<3>(Keyword::Input1)?;
545+
let input1 = self.parse_blackbox_inputs_array::<2>(Keyword::Input1)?;
546546
self.eat_comma_or_error()?;
547547

548-
let input2 = self.parse_blackbox_inputs_array::<3>(Keyword::Input2)?;
548+
let input2 = self.parse_blackbox_inputs_array::<2>(Keyword::Input2)?;
549549
self.eat_comma_or_error()?;
550550

551551
let predicate = self.parse_blackbox_input(Keyword::Predicate)?;
552552
self.eat_comma_or_error()?;
553553

554-
let outputs = self.parse_blackbox_outputs_array::<3>()?;
555-
let outputs = (outputs[0], outputs[1], outputs[2]);
554+
let outputs = self.parse_blackbox_outputs_array::<2>()?;
555+
let outputs = (outputs[0], outputs[1]);
556556

557557
BlackBoxFuncCall::EmbeddedCurveAdd { input1, input2, predicate, outputs }
558558
}

acvm-repo/acir/src/parser/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn embedded_curve_add() {
370370
private parameters: []
371371
public parameters: []
372372
return values: []
373-
BLACKBOX::EMBEDDED_CURVE_ADD input1: [w0, w1, w2], input2: [w3, w4, w5], predicate: w6, outputs: [w7, w8, w9]
373+
BLACKBOX::EMBEDDED_CURVE_ADD input1: [w0, w1], input2: [w2, w3], predicate: w4, outputs: [w5, w6]
374374
";
375375
assert_circuit_roundtrip(src);
376376
}
@@ -382,7 +382,7 @@ fn embedded_curve_add_wrong_output_count() {
382382
private parameters: []
383383
public parameters: []
384384
return values: []
385-
BLACKBOX::EMBEDDED_CURVE_ADD input1: [w0, w1, w2], input2: [w3, w4, w5], predicate: w6, outputs: [w7, w8]
385+
BLACKBOX::EMBEDDED_CURVE_ADD input1: [w0, w1], input2: [w2, w3], predicate: w4, outputs: [w5]
386386
";
387387
let _ = Circuit::from_str(src).unwrap();
388388
}
@@ -449,7 +449,7 @@ fn multi_scalar_mul() {
449449
private parameters: []
450450
public parameters: []
451451
return values: []
452-
BLACKBOX::MULTI_SCALAR_MUL points: [w0, w1], scalars: [w2, w3], predicate: 1, outputs: [w4, w5, w6]
452+
BLACKBOX::MULTI_SCALAR_MUL points: [w0, w1], scalars: [w2, w3], predicate: 1, outputs: [w4, w5]
453453
";
454454
assert_circuit_roundtrip(src);
455455
}

acvm-repo/acir/tests/test_program_serialization.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ fn addition_circuit() {
5454
#[test]
5555
fn multi_scalar_mul_circuit() {
5656
let src = "
57-
private parameters: [w1, w2, w3, w4, w5, w6]
57+
private parameters: [w1, w2, w3, w4, w5]
5858
public parameters: []
59-
return values: [w7, w8, w9]
60-
BLACKBOX::MULTI_SCALAR_MUL points: [w1, w2, w3], scalars: [w4, w5], predicate: w6, outputs: [w7, w8, w9]
59+
return values: [w6, w7]
60+
BLACKBOX::MULTI_SCALAR_MUL points: [w1, w2], scalars: [w3, w4], predicate: w5, outputs: [w6, w7]
6161
";
6262
let circuit = Circuit::from_str(src).unwrap();
6363

6464
let program = Program { functions: vec![circuit], unconstrained_functions: vec![] };
6565

6666
let bytes_msgpack =
6767
Program::serialize_program_with_format(&program, SerializationFormat::Msgpack);
68-
insta::assert_compact_debug_snapshot!(bytes_msgpack, @"[31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 144, 189, 138, 66, 49, 16, 133, 241, 250, 179, 187, 175, 229, 194, 118, 91, 109, 177, 101, 24, 115, 71, 9, 198, 36, 204, 76, 196, 246, 138, 88, 95, 21, 172, 173, 188, 88, 248, 219, 248, 122, 6, 193, 96, 247, 49, 103, 206, 97, 206, 20, 243, 195, 48, 58, 45, 198, 59, 94, 45, 143, 47, 86, 14, 38, 184, 107, 124, 208, 190, 68, 94, 85, 151, 190, 5, 61, 238, 251, 217, 79, 90, 248, 6, 107, 171, 211, 111, 180, 98, 254, 52, 88, 160, 132, 139, 125, 240, 198, 9, 111, 170, 230, 223, 136, 67, 230, 86, 166, 34, 83, 187, 225, 167, 129, 215, 121, 212, 201, 212, 61, 4, 194, 210, 104, 16, 204, 179, 94, 227, 163, 132, 152, 114, 63, 62, 191, 110, 129, 204, 52, 169, 42, 0, 165, 243, 4, 137, 183, 173, 162, 221, 233, 246, 174, 33, 14, 172, 209, 111, 66, 125, 36, 148, 72, 78, 77, 193, 70, 124, 218, 207, 192, 140, 36, 106, 146, 114, 97, 132, 92, 223, 83, 151, 84, 91, 8, 140, 195, 82, 229, 63, 212, 15, 176, 100, 253, 143, 21, 1, 0, 0]");
68+
insta::assert_compact_debug_snapshot!(bytes_msgpack, @"[31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 143, 189, 10, 2, 49, 16, 132, 241, 252, 123, 47, 5, 59, 43, 11, 203, 176, 230, 86, 9, 198, 36, 236, 110, 196, 246, 68, 172, 79, 193, 222, 202, 195, 194, 223, 198, 215, 51, 10, 30, 118, 31, 59, 179, 195, 76, 182, 62, 79, 163, 211, 98, 188, 227, 221, 246, 242, 99, 229, 96, 129, 199, 202, 7, 237, 115, 228, 93, 113, 239, 89, 208, 243, 158, 95, 13, 146, 161, 15, 214, 22, 215, 97, 180, 98, 70, 26, 44, 80, 194, 205, 41, 120, 227, 132, 247, 69, 53, 54, 226, 144, 185, 81, 83, 86, 241, 215, 246, 39, 54, 107, 106, 157, 3, 97, 110, 52, 8, 214, 183, 118, 229, 163, 132, 152, 210, 58, 221, 103, 32, 179, 76, 162, 10, 64, 169, 147, 32, 241, 161, 145, 53, 91, 237, 71, 136, 19, 107, 244, 223, 189, 188, 16, 74, 36, 167, 150, 96, 35, 126, 158, 111, 192, 140, 36, 106, 145, 66, 97, 134, 92, 190, 82, 253, 180, 84, 8, 140, 195, 92, 213, 211, 203, 55, 238, 115, 64, 226, 8, 1, 0, 0]");
6969

7070
let bytes_default = Program::serialize_program(&program);
71-
insta::assert_compact_debug_snapshot!(bytes_default, @"[31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 61, 198, 187, 10, 128, 32, 20, 0, 80, 202, 158, 191, 101, 208, 214, 212, 208, 44, 210, 32, 93, 12, 82, 161, 213, 63, 240, 17, 206, 109, 109, 209, 39, 86, 203, 221, 14, 9, 62, 157, 222, 62, 20, 24, 95, 232, 186, 247, 70, 242, 142, 1, 216, 123, 48, 160, 197, 200, 25, 176, 237, 227, 17, 237, 53, 9, 45, 103, 165, 50, 84, 142, 34, 1, 89, 160, 74, 84, 21, 235, 166, 77, 89, 78, 138, 178, 114, 191, 157, 123, 1, 110, 20, 217, 141, 121, 0, 0, 0]");
71+
insta::assert_compact_debug_snapshot!(bytes_default, @"[31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 69, 200, 187, 10, 128, 32, 20, 0, 80, 242, 81, 255, 101, 208, 214, 212, 208, 124, 145, 6, 233, 98, 144, 10, 173, 254, 129, 74, 53, 183, 181, 69, 159, 152, 147, 109, 135, 67, 83, 60, 175, 232, 95, 129, 32, 103, 177, 108, 157, 211, 178, 5, 68, 255, 244, 14, 173, 26, 36, 32, 172, 153, 123, 242, 247, 168, 172, 158, 140, 169, 138, 200, 159, 180, 136, 21, 241, 84, 55, 71, 69, 40, 227, 33, 43, 132, 15, 97, 220, 166, 97, 108, 0, 0, 0]");
7272

7373
assert_deserialization(&program, [bytes_msgpack, bytes_default]);
7474
}

acvm-repo/acvm/src/compiler/optimizers/common_subexpression/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,17 @@ where
427427
self.fold_inputs(points.as_slice());
428428
self.fold_inputs(scalars.as_slice());
429429
self.fold_input(predicate);
430-
let (x, y, i) = outputs;
430+
let (x, y) = outputs;
431431
self.fold(*x);
432432
self.fold(*y);
433-
self.fold(*i);
434433
}
435434
BlackBoxFuncCall::EmbeddedCurveAdd { input1, input2, predicate, outputs } => {
436435
self.fold_inputs(input1.as_slice());
437436
self.fold_inputs(input2.as_slice());
438437
self.fold_input(predicate);
439-
let (x, y, i) = outputs;
438+
let (x, y) = outputs;
440439
self.fold(*x);
441440
self.fold(*y);
442-
self.fold(*i);
443441
}
444442
BlackBoxFuncCall::Keccakf1600 { inputs, outputs } => {
445443
self.fold_inputs(inputs.as_slice());

0 commit comments

Comments
 (0)