Skip to content

Commit

Permalink
wip debugging, use 'point == ..Affine::zero()' to check for infinity,…
Browse files Browse the repository at this point in the history
… check that bool's are valid
  • Loading branch information
michaeljklein committed Dec 11, 2024
1 parent 4b0df94 commit 5fe6eaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
15 changes: 9 additions & 6 deletions acvm-repo/bn254_blackbox_solver/src/embedded_curve_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub fn multi_scalar_mul(
let mut output_point = grumpkin::SWAffine::zero();

for i in (0..points.len()).step_by(3) {
if pedantic_solving && points[i + 2] > FieldElement::one() {
panic!("--pedantic-solving: is_infinity expected to be a bool, but found to be > 1")
}
let point =
create_point(points[i], points[i + 1], points[i + 2] == FieldElement::from(1_u128))
.map_err(|e| BlackBoxResolutionError::Failed(BlackBoxFunc::MultiScalarMul, e))?;
Expand Down Expand Up @@ -79,17 +82,21 @@ pub fn embedded_curve_add(
input2: [FieldElement; 3],
pedantic_solving: bool,
) -> Result<(FieldElement, FieldElement, FieldElement), BlackBoxResolutionError> {
if pedantic_solving && input1[2] > FieldElement::one() && input2[2] > FieldElement::one() {
panic!("--pedantic-solving: is_infinity expected to be a bool, but found to be > 1")
}

let point1 = create_point(input1[0], input1[1], input1[2] == FieldElement::one())
.map_err(|e| BlackBoxResolutionError::Failed(BlackBoxFunc::EmbeddedCurveAdd, e))?;
let point2 = create_point(input2[0], input2[1], input2[2] == FieldElement::one())
.map_err(|e| BlackBoxResolutionError::Failed(BlackBoxFunc::EmbeddedCurveAdd, e))?;

if pedantic_solving {
for point in [point1, point2] {
if point.to_flags().is_infinity() {
if point == grumpkin::SWAffine::zero() {
return Err(BlackBoxResolutionError::Failed(
BlackBoxFunc::EmbeddedCurveAdd,
format!("Infinite point input: {}", point),
format!("Infinite input: embedded_curve_add({}, {})", point1, point2),
));
}
}
Expand Down Expand Up @@ -118,11 +125,7 @@ fn create_point(
is_infinite: bool,
) -> Result<grumpkin::SWAffine, String> {
if is_infinite {
// TODO: only error when pedantic?

return Ok(grumpkin::SWAffine::zero());
// panic!("infinite input to EC operation")
// return Err(format!("Attempt to use infinite point in EC operation ({}, {})", x.to_hex(), y.to_hex()));
}
let point = grumpkin::SWAffine::new_unchecked(x.into_repr(), y.into_repr());
if !point.is_on_curve() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ fn test_embedded_curve_ops() {
let g1 = EmbeddedCurvePoint { x: 1, y: 17631683881184975370165255887551781615748388533673675138860, is_infinite: false };
let s1 = EmbeddedCurveScalar { lo: 1, hi: 0 };
let sum = g1 + g1;

// TODO
// let mul = multi_scalar_mul([g1, g1], [s1, s1]);
let mul = sum;
let mul = multi_scalar_mul([g1, g1], [s1, s1]);
(sum, mul)
};
assert_eq(sum, mul);
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Pa
panic!("JSON was not well-formatted {:?}\n\n{:?}", e, std::str::from_utf8(&output.stdout))
}});
let num_opcodes = &json["programs"][0]["functions"][0]["opcodes"];
assert_eq!(num_opcodes.as_u64().expect("number of opcodes should fit in a u64"), 0);
assert_eq!(num_opcodes.as_u64().expect("number of opcodes should fit in a u64"), 0, "expected the number of opcodes to be 0");
"#;

generate_test_cases(
Expand Down

0 comments on commit 5fe6eaa

Please sign in to comment.