Skip to content

Commit b8fed65

Browse files
committed
fix: update tests for is_infinite removal
1 parent 21d6288 commit b8fed65

9 files changed

Lines changed: 66 additions & 87 deletions

File tree

acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ mod tests {
647647
return values: []
648648
BLACKBOX::RANGE input: w1, bits: 128
649649
BLACKBOX::RANGE input: w2, bits: 128
650-
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4, 1], scalars: [w1, w2], predicate: 1, outputs: [w5, w6, w7]
650+
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4], scalars: [w1, w2], predicate: 1, outputs: [w5, w6]
651651
";
652652
let circuit = Circuit::from_str(src).unwrap();
653653
assert!(CircuitSimulator::check_circuit(&circuit).is_none());
@@ -673,7 +673,7 @@ mod tests {
673673
private parameters: [w1, w2, w3, w4, w5, w6]
674674
public parameters: []
675675
return values: []
676-
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4, 1], scalars: [w1, w2], predicate: 1, outputs: [w5, w6, w7]
676+
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4], scalars: [w1, w2], predicate: 1, outputs: [w5, w6]
677677
");
678678
}
679679

@@ -686,7 +686,7 @@ mod tests {
686686
return values: []
687687
BLACKBOX::RANGE input: w1, bits: 64
688688
BLACKBOX::RANGE input: w2, bits: 64
689-
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4, 1], scalars: [w1, w2], predicate: 1, outputs: [w5, w6, w7]
689+
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4], scalars: [w1, w2], predicate: 1, outputs: [w5, w6]
690690
";
691691
let circuit = Circuit::from_str(src).unwrap();
692692
assert!(CircuitSimulator::check_circuit(&circuit).is_none());
@@ -712,7 +712,7 @@ mod tests {
712712
return values: []
713713
BLACKBOX::RANGE input: w1, bits: 64
714714
BLACKBOX::RANGE input: w2, bits: 64
715-
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4, 1], scalars: [w1, w2], predicate: 1, outputs: [w5, w6, w7]
715+
BLACKBOX::MULTI_SCALAR_MUL points: [w3, w4], scalars: [w1, w2], predicate: 1, outputs: [w5, w6]
716716
");
717717
}
718718
}

compiler/noirc_evaluator/src/ssa/ir/dfg/simplify/call/blackbox.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,13 @@ mod embedded_curve_add {
386386
}"#;
387387
let ssa = Ssa::from_str_simplifying(src).unwrap();
388388

389-
assert_ssa_snapshot!(ssa, @"");
389+
assert_ssa_snapshot!(ssa, @r"
390+
acir(inline) fn main f0 {
391+
b0(v0: Field, v1: Field):
392+
v2 = make_array [v0, v1] : [(Field, Field); 1]
393+
return v2
394+
}
395+
");
390396
}
391397

392398
#[test]
@@ -428,7 +434,15 @@ mod multi_scalar_mul {
428434
}"#;
429435
let ssa = Ssa::from_str_simplifying(src).unwrap();
430436

431-
assert_ssa_snapshot!(ssa, @"");
437+
assert_ssa_snapshot!(ssa, @r"
438+
acir(inline) fn main f0 {
439+
b0():
440+
v3 = make_array [Field 2, Field 3, Field 5, Field 5] : [(Field, Field); 2]
441+
v6 = make_array [Field 1, Field 17631683881184975370165255887551781615748388533673675138860, Field 1, Field 17631683881184975370165255887551781615748388533673675138860] : [(Field, Field); 2]
442+
v9 = make_array [Field 1478523918288173385110236399861791147958001875200066088686689589556927843200, Field 700144278551281040379388961242974992655630750193306467120985766322057145630] : [(Field, Field); 1]
443+
return v9
444+
}
445+
");
432446
}
433447

434448
#[test]
@@ -445,7 +459,17 @@ mod multi_scalar_mul {
445459
}"#;
446460
let ssa = Ssa::from_str_simplifying(src).unwrap();
447461
//First point is zero (point at infinity), second scalar is zero, so we should be left with the scalar mul of the last point.
448-
assert_ssa_snapshot!(ssa, @"");
462+
assert_ssa_snapshot!(ssa, @r"
463+
acir(inline) fn main f0 {
464+
b0(v0: Field, v1: Field):
465+
v3 = make_array [v0, Field 0, Field 0, Field 0, v0, Field 0] : [(Field, Field); 3]
466+
v5 = make_array [Field 0, Field 0, v0, v1, Field 1, v0] : [(Field, Field); 3]
467+
v6 = make_array [v0, Field 0] : [(Field, Field); 1]
468+
v7 = make_array [Field 1, v0] : [(Field, Field); 1]
469+
v10 = call multi_scalar_mul(v7, v6, u1 1) -> [(Field, Field); 1]
470+
return v10
471+
}
472+
");
449473
}
450474

451475
#[test]
@@ -461,7 +485,17 @@ mod multi_scalar_mul {
461485
}"#;
462486
let ssa = Ssa::from_str_simplifying(src).unwrap();
463487
//First and last scalar/point are constant, so we should be left with the msm of the middle point and the folded constant point
464-
assert_ssa_snapshot!(ssa, @"");
488+
assert_ssa_snapshot!(ssa, @r"
489+
acir(inline) fn main f0 {
490+
b0(v0: Field, v1: Field):
491+
v5 = make_array [Field 1, Field 0, v0, Field 0, Field 2, Field 0] : [(Field, Field); 3]
492+
v7 = make_array [Field 1, Field 17631683881184975370165255887551781615748388533673675138860, v0, v1, Field 1, Field 17631683881184975370165255887551781615748388533673675138860] : [(Field, Field); 3]
493+
v8 = make_array [v0, Field 0, Field 1, Field 0] : [(Field, Field); 2]
494+
v11 = make_array [v0, v1, Field -3227352362257037263902424173275354266044964400219754872043023745437788450996, Field 8902249110305491597038405103722863701255802573786510474664632793109847672620] : [(Field, Field); 2]
495+
v14 = call multi_scalar_mul(v11, v8, u1 1) -> [(Field, Field); 1]
496+
return v14
497+
}
498+
");
465499
}
466500
}
467501

tooling/ssa_fuzzer/fuzzer/src/fuzz_lib/block_context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl BlockContext {
589589
let p1 = p1.unwrap();
590590
let p2 = p2.unwrap();
591591
let acir_point = builder.point_add(p1, p2, predicate);
592-
for typed_value in [&acir_point.x, &acir_point.y, &acir_point.is_infinite] {
592+
for typed_value in [&acir_point.x, &acir_point.y] {
593593
self.store_variable(typed_value);
594594
}
595595
}
@@ -616,7 +616,7 @@ impl BlockContext {
616616
}
617617
let point =
618618
builder.multi_scalar_mul(points_vec.clone(), scalars_vec.clone(), predicate);
619-
for typed_value in [&point.x, &point.y, &point.is_infinite] {
619+
for typed_value in [&point.x, &point.y] {
620620
self.store_variable(typed_value);
621621
}
622622
}
@@ -698,12 +698,11 @@ impl BlockContext {
698698
let scalar = self.ssa_scalar_from_instruction_scalar(point.scalar);
699699
scalar.as_ref()?; // wtf clippy forbid me to write if scalar.is_none() {return None}
700700
let scalar = scalar.unwrap();
701-
let is_infinite = builder.insert_constant(point.is_infinite, NumericType::Boolean);
702701

703702
let point = if point.derive_from_scalar_mul {
704-
builder.base_scalar_mul(scalar, is_infinite)
703+
builder.base_scalar_mul(scalar)
705704
} else {
706-
builder.create_point_from_scalar(scalar, is_infinite)
705+
builder.create_point_from_scalar(scalar)
707706
};
708707
Some(point)
709708
}

tooling/ssa_fuzzer/fuzzer/src/fuzz_lib/instruction.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub(crate) struct Point {
3434
/// If true, the point will be derived from scalar multiplication using [`noir_ssa_fuzzer::builder::FuzzerBuilder::base_scalar_mul`]
3535
/// Otherwise, the point will be derived from scalar values using [`noir_ssa_fuzzer::builder::FuzzerBuilder::create_point_from_scalar`]
3636
pub(crate) derive_from_scalar_mul: bool,
37-
pub(crate) is_infinite: bool,
3837
}
3938

4039
pub(crate) type PointAndScalar = (Point, Scalar);

tooling/ssa_fuzzer/fuzzer/src/fuzz_lib/tests/embedded_curve_ops.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ fn smoke_test_embedded_curve_add() {
2424
p1: Point {
2525
scalar: Scalar { field_lo_idx: 1, field_hi_idx: 0 },
2626
derive_from_scalar_mul: true,
27-
is_infinite: false,
2827
},
2928
p2: Point {
3029
scalar: Scalar { field_lo_idx: 2, field_hi_idx: 0 },
3130
derive_from_scalar_mul: true,
32-
is_infinite: false,
3331
},
3432
predicate: true,
3533
};
@@ -74,7 +72,7 @@ fn smoke_test_embedded_multi_scalar_mul() {
7472
let base_scalar = Scalar { field_lo_idx: 1, field_hi_idx: 0 };
7573
let scalar_1 = Scalar { field_lo_idx: 2, field_hi_idx: 0 };
7674
let scalar_2 = Scalar { field_lo_idx: 4, field_hi_idx: 0 };
77-
let gen_point = Point { scalar: base_scalar, derive_from_scalar_mul: true, is_infinite: false };
75+
let gen_point = Point { scalar: base_scalar, derive_from_scalar_mul: true };
7876
let instruction = Instruction::MultiScalarMul {
7977
points_and_scalars: vec![(gen_point, scalar_1), (gen_point, scalar_2)],
8078
predicate: true,

tooling/ssa_fuzzer/fuzzer/src/mutations/basic_types/point.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use crate::mutations::basic_types::{
44
scalar::{generate_random_scalar, mutate_scalar},
55
};
66
use crate::mutations::configuration::{
7-
BASIC_POINT_MUTATION_CONFIGURATION, BOOL_MUTATION_CONFIGURATION_MOSTLY_FALSE,
8-
BOOL_MUTATION_CONFIGURATION_MOSTLY_TRUE, GENERATE_BOOL_CONFIGURATION_MOST_FALSE,
7+
BASIC_POINT_MUTATION_CONFIGURATION, BOOL_MUTATION_CONFIGURATION_MOSTLY_TRUE,
98
GENERATE_BOOL_CONFIGURATION_MOST_TRUE, PointMutationOptions,
109
};
1110
use rand::rngs::StdRng;
@@ -14,7 +13,6 @@ pub(crate) fn generate_random_point(rng: &mut StdRng) -> Point {
1413
Point {
1514
scalar: generate_random_scalar(rng),
1615
derive_from_scalar_mul: generate_random_bool(rng, GENERATE_BOOL_CONFIGURATION_MOST_TRUE),
17-
is_infinite: generate_random_bool(rng, GENERATE_BOOL_CONFIGURATION_MOST_FALSE),
1816
}
1917
}
2018

@@ -30,8 +28,5 @@ pub(crate) fn mutate_point(point: &mut Point, rng: &mut StdRng) {
3028
BOOL_MUTATION_CONFIGURATION_MOSTLY_TRUE,
3129
);
3230
}
33-
PointMutationOptions::IsInfinite => {
34-
mutate_bool(&mut point.is_infinite, rng, BOOL_MUTATION_CONFIGURATION_MOSTLY_FALSE);
35-
}
3631
}
3732
}

tooling/ssa_fuzzer/fuzzer/src/mutations/configuration.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ pub(crate) const BASIC_BOOL_MUTATION_CONFIGURATION: BoolMutationConfig =
230230

231231
pub(crate) const BOOL_MUTATION_CONFIGURATION_MOSTLY_TRUE: BoolMutationConfig =
232232
BoolMutationConfig::new([(BoolMutationOptions::True, 1000), (BoolMutationOptions::False, 1)]);
233-
pub(crate) const BOOL_MUTATION_CONFIGURATION_MOSTLY_FALSE: BoolMutationConfig =
234-
BoolMutationConfig::new([(BoolMutationOptions::True, 1), (BoolMutationOptions::False, 1000)]);
235233

236234
#[derive(Copy, Clone, Debug)]
237235
pub(crate) enum UsizeMutationOptions {
@@ -393,14 +391,12 @@ pub(crate) const BASIC_SCALAR_MUTATION_CONFIGURATION: ScalarMutationConfig =
393391
pub(crate) enum PointMutationOptions {
394392
Scalar,
395393
DeriveFromScalarMul,
396-
IsInfinite,
397394
}
398-
pub(crate) type PointMutationConfig = WeightedSelectionConfig<PointMutationOptions, 3>;
395+
pub(crate) type PointMutationConfig = WeightedSelectionConfig<PointMutationOptions, 2>;
399396
pub(crate) const BASIC_POINT_MUTATION_CONFIGURATION: PointMutationConfig =
400397
PointMutationConfig::new([
401398
(PointMutationOptions::Scalar, 1),
402399
(PointMutationOptions::DeriveFromScalarMul, 1),
403-
(PointMutationOptions::IsInfinite, 1),
404400
]);
405401

406402
// =================== GENERATION CONFIGURATIONS ==================

tooling/ssa_fuzzer/src/builder.rs

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,12 @@ impl FuzzerBuilder {
786786
///
787787
/// # Arguments
788788
/// * `scalar` - The scalar value to multiply
789-
/// * `is_infinite` - The boolean value indicating if the resulting point is on the curve (setting it by ourself)
790789
///
791790
/// # Returns
792-
/// [`Point`] corresponding to `value` * G with overwritten on_curve value
793-
pub fn base_scalar_mul(&mut self, scalar: Scalar, is_infinite: TypedValue) -> Point {
791+
/// [`Point`] corresponding to `value` * G
792+
pub fn base_scalar_mul(&mut self, scalar: Scalar) -> Point {
794793
assert!(scalar.validate());
795-
assert!(matches!(is_infinite.type_of_variable, Type::Numeric(NumericType::Boolean)));
796794
let field_type = Type::Numeric(NumericType::Field);
797-
let boolean_type = Type::Numeric(NumericType::Boolean);
798795
let intrinsic = self
799796
.builder
800797
.import_intrinsic("multi_scalar_mul")
@@ -809,16 +806,11 @@ impl FuzzerBuilder {
809806
.unwrap(),
810807
NumericType::Field.into(),
811808
);
812-
let is_infinite_g_id = self.builder.numeric_constant(0_u32, NumericType::Boolean.into());
813-
let elements = vec![g_x_id, g_y_id, is_infinite_g_id].into_iter().collect();
809+
let elements = vec![g_x_id, g_y_id].into_iter().collect();
814810
let basic_point = self.builder.insert_make_array(
815811
elements,
816812
SsaType::Array(
817-
Arc::new(vec![
818-
field_type.clone().into(),
819-
field_type.clone().into(),
820-
boolean_type.clone().into(),
821-
]),
813+
Arc::new(vec![field_type.clone().into(), field_type.clone().into()]),
822814
SemanticLength(1),
823815
),
824816
);
@@ -829,8 +821,7 @@ impl FuzzerBuilder {
829821
SemanticLength(1),
830822
),
831823
);
832-
let return_type =
833-
Type::Array(Arc::new(vec![field_type.clone(), field_type.clone(), boolean_type]), 1);
824+
let return_type = Type::Array(Arc::new(vec![field_type.clone(), field_type.clone()]), 1);
834825
let predicate = self.builder.numeric_constant(1_u32, NumericType::Boolean.into());
835826
let result = self.builder.insert_call(
836827
intrinsic,
@@ -843,24 +834,18 @@ impl FuzzerBuilder {
843834
let y_idx = self.builder.numeric_constant(1_u32, NumericType::U32.into());
844835
let x = self.builder.insert_array_get(result, x_idx, field_type.clone().into());
845836
let y = self.builder.insert_array_get(result, y_idx, field_type.clone().into());
846-
Point {
847-
x: TypedValue::new(x, field_type.clone()),
848-
y: TypedValue::new(y, field_type),
849-
is_infinite,
850-
}
837+
Point { x: TypedValue::new(x, field_type.clone()), y: TypedValue::new(y, field_type) }
851838
}
852839

853-
/// Creates a point from an affine x coordinate (scalar.lo, scalar.hi, is_infinite)
840+
/// Creates a point from an affine x coordinate (scalar.lo, scalar.hi)
854841
/// Mostly invalid
855842
/// # Arguments
856843
/// * `scalar` - The scalar value to take coordinates from
857-
/// * `is_infinite` - The boolean value indicating if the resulting point is on the curve (setting it by ourself)
858844
/// # Returns
859-
/// Point (scalar.lo, scalar.hi, is_infinite)
860-
pub fn create_point_from_scalar(&mut self, scalar: Scalar, is_infinite: TypedValue) -> Point {
845+
/// Point (scalar.lo, scalar.hi)
846+
pub fn create_point_from_scalar(&mut self, scalar: Scalar) -> Point {
861847
assert!(scalar.validate());
862-
assert!(matches!(is_infinite.type_of_variable, Type::Numeric(NumericType::Boolean)));
863-
Point { x: scalar.lo, y: scalar.hi, is_infinite }
848+
Point { x: scalar.lo, y: scalar.hi }
864849
}
865850

866851
pub fn multi_scalar_mul(
@@ -879,7 +864,6 @@ impl FuzzerBuilder {
879864
let predicate =
880865
self.builder.numeric_constant(u32::from(predicate), NumericType::Boolean.into());
881866
let field_type = Type::Numeric(NumericType::Field);
882-
let boolean_type = Type::Numeric(NumericType::Boolean);
883867
let intrinsic = self
884868
.builder
885869
.import_intrinsic("multi_scalar_mul")
@@ -889,11 +873,7 @@ impl FuzzerBuilder {
889873
let point_ids_array = self.builder.insert_make_array(
890874
point_ids.into_iter().collect(),
891875
SsaType::Array(
892-
Arc::new(vec![
893-
field_type.clone().into(),
894-
field_type.clone().into(),
895-
boolean_type.clone().into(),
896-
]),
876+
Arc::new(vec![field_type.clone().into(), field_type.clone().into()]),
897877
SemanticLength(points.len() as u32),
898878
),
899879
);
@@ -904,10 +884,7 @@ impl FuzzerBuilder {
904884
SemanticLength(scalars.len() as u32),
905885
),
906886
);
907-
let return_type = Type::Array(
908-
Arc::new(vec![field_type.clone(), field_type.clone(), boolean_type.clone()]),
909-
1,
910-
);
887+
let return_type = Type::Array(Arc::new(vec![field_type.clone(), field_type.clone()]), 1);
911888
let result = self.builder.insert_call(
912889
intrinsic,
913890
vec![point_ids_array, scalar_ids_array, predicate],
@@ -917,23 +894,15 @@ impl FuzzerBuilder {
917894
let result = result[0];
918895
let x_idx = self.builder.numeric_constant(0_u32, NumericType::U32.into());
919896
let y_idx = self.builder.numeric_constant(1_u32, NumericType::U32.into());
920-
let is_infinite_idx = self.builder.numeric_constant(2_u32, NumericType::U32.into());
921897
let x = self.builder.insert_array_get(result, x_idx, field_type.clone().into());
922898
let y = self.builder.insert_array_get(result, y_idx, field_type.clone().into());
923-
let is_infinite =
924-
self.builder.insert_array_get(result, is_infinite_idx, boolean_type.clone().into());
925-
Point {
926-
x: TypedValue::new(x, field_type.clone()),
927-
y: TypedValue::new(y, field_type),
928-
is_infinite: TypedValue::new(is_infinite, boolean_type),
929-
}
899+
Point { x: TypedValue::new(x, field_type.clone()), y: TypedValue::new(y, field_type) }
930900
}
931901

932902
pub fn point_add(&mut self, p1: Point, p2: Point, predicate: bool) -> Point {
933903
assert!(p1.validate());
934904
assert!(p2.validate());
935905
let field_type = Type::Numeric(NumericType::Field);
936-
let boolean_type = Type::Numeric(NumericType::Boolean);
937906
let predicate =
938907
self.builder.numeric_constant(u32::from(predicate), NumericType::Boolean.into());
939908
let intrinsic = self
@@ -942,25 +911,15 @@ impl FuzzerBuilder {
942911
.expect("embedded_curve_add intrinsic should be available");
943912
let mut arguments = p1.to_id_vec().into_iter().chain(p2.to_id_vec()).collect::<Vec<_>>();
944913
arguments.push(predicate);
945-
let return_type = Type::Array(
946-
Arc::new(vec![field_type.clone(), field_type.clone(), boolean_type.clone()]),
947-
1,
948-
);
914+
let return_type = Type::Array(Arc::new(vec![field_type.clone(), field_type.clone()]), 1);
949915
let result = self.builder.insert_call(intrinsic, arguments, vec![return_type.into()]);
950916
assert_eq!(result.len(), 1);
951917
let result = result[0];
952918
let x_idx = self.builder.numeric_constant(0_u32, NumericType::U32.into());
953919
let y_idx = self.builder.numeric_constant(1_u32, NumericType::U32.into());
954-
let is_infinite_idx = self.builder.numeric_constant(2_u32, NumericType::U32.into());
955920
let x = self.builder.insert_array_get(result, x_idx, field_type.clone().into());
956921
let y = self.builder.insert_array_get(result, y_idx, field_type.clone().into());
957-
let is_infinite =
958-
self.builder.insert_array_get(result, is_infinite_idx, boolean_type.clone().into());
959-
Point {
960-
x: TypedValue::new(x, field_type.clone()),
961-
y: TypedValue::new(y, field_type),
962-
is_infinite: TypedValue::new(is_infinite, boolean_type),
963-
}
922+
Point { x: TypedValue::new(x, field_type.clone()), y: TypedValue::new(y, field_type) }
964923
}
965924

966925
fn bytes_to_ssa_array(&mut self, vec: Vec<u8>) -> TypedValue {

0 commit comments

Comments
 (0)