From a47e59e06bdf50a24500f8ac5672bf5b9e31931d Mon Sep 17 00:00:00 2001 From: guipublic Date: Thu, 6 Jun 2024 11:08:56 +0000 Subject: [PATCH 1/3] remove PedersenPoint --- noir_stdlib/src/hash.nr | 12 ++++-------- .../pedersen_commitment/src/main.nr | 2 +- .../should_fail_with_matches/src/main.nr | 10 +++++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/noir_stdlib/src/hash.nr b/noir_stdlib/src/hash.nr index ef1cb0889d7..6c295d127ab 100644 --- a/noir_stdlib/src/hash.nr +++ b/noir_stdlib/src/hash.nr @@ -5,6 +5,7 @@ mod poseidon2; use crate::default::Default; use crate::uint128::U128; use crate::sha256::{digest, sha256_var}; +use crate::embedded_curve_ops::EmbeddedCurvePoint; #[foreign(sha256)] // docs:start:sha256 @@ -25,12 +26,7 @@ pub fn blake3(input: [u8; N]) -> [u8; 32] {} // docs:start:pedersen_commitment -struct PedersenPoint { - x : Field, - y : Field, -} - -pub fn pedersen_commitment(input: [Field; N]) -> PedersenPoint { +pub fn pedersen_commitment(input: [Field; N]) -> EmbeddedCurvePoint { // docs:end:pedersen_commitment pedersen_commitment_with_separator(input, 0) } @@ -38,9 +34,9 @@ pub fn pedersen_commitment(input: [Field; N]) -> PedersenPoint { #[foreign(pedersen_commitment)] pub fn __pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> [Field; 2] {} -pub fn pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> PedersenPoint { +pub fn pedersen_commitment_with_separator(input: [Field; N], separator: u32) -> EmbeddedCurvePoint { let values = __pedersen_commitment_with_separator(input, separator); - PedersenPoint { x: values[0], y: values[1] } + EmbeddedCurvePoint { x: values[0], y: values[1], is_infinite: false } } // docs:start:pedersen_hash diff --git a/test_programs/execution_success/pedersen_commitment/src/main.nr b/test_programs/execution_success/pedersen_commitment/src/main.nr index 83cbe20851d..a3a9aea1cf0 100644 --- a/test_programs/execution_success/pedersen_commitment/src/main.nr +++ b/test_programs/execution_success/pedersen_commitment/src/main.nr @@ -1,7 +1,7 @@ // docs:start:pedersen-commitment use dep::std; -fn main(x: Field, y: Field, expected_commitment: std::hash::PedersenPoint) { +fn main(x: Field, y: Field, expected_commitment: std::embedded_curve_ops::EmbeddedCurvePoint) { let commitment = std::hash::pedersen_commitment([x, y]); assert_eq(commitment.x, expected_commitment.x); assert_eq(commitment.y, expected_commitment.y); diff --git a/test_programs/noir_test_success/should_fail_with_matches/src/main.nr b/test_programs/noir_test_success/should_fail_with_matches/src/main.nr index 56ee5cfa586..2354acec193 100644 --- a/test_programs/noir_test_success/should_fail_with_matches/src/main.nr +++ b/test_programs/noir_test_success/should_fail_with_matches/src/main.nr @@ -19,10 +19,10 @@ fn test_should_fail_without_runtime_match() { } struct InvalidPointError { - point: dep::std::hash::PedersenPoint, + point: dep::std::embedded_curve_ops::EmbeddedCurvePoint, } -#[test(should_fail_with = "InvalidPointError { point: PedersenPoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 } }")] +#[test(should_fail_with = "InvalidPointError { point: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 } }")] fn test_should_fail_with_struct() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, InvalidPointError { point: hash }); @@ -35,7 +35,7 @@ fn test_should_fail_with_basic_type_fmt_string() { assert_eq(a, b, f"A: {a} is not 1!"); } -#[test(should_fail_with = "Invalid hash: PedersenPoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 }")] +#[test(should_fail_with = "Invalid hash: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 }")] fn test_should_fail_with_struct_fmt_string() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, f"Invalid hash: {hash}"); @@ -63,7 +63,7 @@ unconstrained fn unconstrained_test_should_fail_without_runtime_match() { assert_eq(dep::std::hash::pedersen_commitment([27]).x, 0); } -#[test(should_fail_with = "InvalidPointError { point: PedersenPoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 } }")] +#[test(should_fail_with = "InvalidPointError { point: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 } }")] unconstrained fn unconstrained_test_should_fail_with_struct() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, InvalidPointError { point: hash }); @@ -76,7 +76,7 @@ unconstrained fn unconstrained_test_should_fail_with_basic_type_fmt_string() { assert_eq(a, b, f"A: {a} is not 1!"); } -#[test(should_fail_with = "Invalid hash: PedersenPoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 }")] +#[test(should_fail_with = "Invalid hash: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 }")] unconstrained fn unconstrained_test_should_fail_with_struct_fmt_string() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, f"Invalid hash: {hash}"); From 4ae75855259fc1f2e67a6a84d9b03eb65121837e Mon Sep 17 00:00:00 2001 From: guipublic Date: Thu, 6 Jun 2024 11:18:17 +0000 Subject: [PATCH 2/3] nargo fmt --- test_programs/execution_success/schnorr/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_programs/execution_success/schnorr/src/main.nr b/test_programs/execution_success/schnorr/src/main.nr index 8ff868bc61b..1067d9707b2 100644 --- a/test_programs/execution_success/schnorr/src/main.nr +++ b/test_programs/execution_success/schnorr/src/main.nr @@ -30,7 +30,7 @@ fn main( let pub_key = embedded_curve_ops::EmbeddedCurvePoint { x: pub_key_x, y: pub_key_y, is_infinite: false }; let valid_signature = verify_signature_noir(pub_key, signature, message2); assert(valid_signature); - assert_valid_signature(pub_key,signature,message2); + assert_valid_signature(pub_key, signature, message2); } // TODO: to put in the stdlib once we have numeric generics From c452a7a3d2491800f7b056d51e9347f2a1bd4787 Mon Sep 17 00:00:00 2001 From: guipublic Date: Thu, 6 Jun 2024 11:33:01 +0000 Subject: [PATCH 3/3] fix test case --- .../execution_success/pedersen_commitment/Prover.toml | 1 + .../should_fail_with_matches/src/main.nr | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test_programs/execution_success/pedersen_commitment/Prover.toml b/test_programs/execution_success/pedersen_commitment/Prover.toml index 6ad8c6bca57..0279f7d2096 100644 --- a/test_programs/execution_success/pedersen_commitment/Prover.toml +++ b/test_programs/execution_success/pedersen_commitment/Prover.toml @@ -4,3 +4,4 @@ y = "1" [expected_commitment] x = "0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402" y = "0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126" +is_infinite = false diff --git a/test_programs/noir_test_success/should_fail_with_matches/src/main.nr b/test_programs/noir_test_success/should_fail_with_matches/src/main.nr index 2354acec193..1f5c29e58a2 100644 --- a/test_programs/noir_test_success/should_fail_with_matches/src/main.nr +++ b/test_programs/noir_test_success/should_fail_with_matches/src/main.nr @@ -22,7 +22,7 @@ struct InvalidPointError { point: dep::std::embedded_curve_ops::EmbeddedCurvePoint, } -#[test(should_fail_with = "InvalidPointError { point: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 } }")] +#[test(should_fail_with = "InvalidPointError { point: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8, is_infinite: false } }")] fn test_should_fail_with_struct() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, InvalidPointError { point: hash }); @@ -35,7 +35,7 @@ fn test_should_fail_with_basic_type_fmt_string() { assert_eq(a, b, f"A: {a} is not 1!"); } -#[test(should_fail_with = "Invalid hash: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 }")] +#[test(should_fail_with = "Invalid hash: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8, is_infinite: false }")] fn test_should_fail_with_struct_fmt_string() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, f"Invalid hash: {hash}"); @@ -63,7 +63,7 @@ unconstrained fn unconstrained_test_should_fail_without_runtime_match() { assert_eq(dep::std::hash::pedersen_commitment([27]).x, 0); } -#[test(should_fail_with = "InvalidPointError { point: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 } }")] +#[test(should_fail_with = "InvalidPointError { point: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8, is_infinite: false } }")] unconstrained fn unconstrained_test_should_fail_with_struct() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, InvalidPointError { point: hash }); @@ -76,7 +76,7 @@ unconstrained fn unconstrained_test_should_fail_with_basic_type_fmt_string() { assert_eq(a, b, f"A: {a} is not 1!"); } -#[test(should_fail_with = "Invalid hash: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8 }")] +#[test(should_fail_with = "Invalid hash: EmbeddedCurvePoint { x: 0x1cea3a116d01eb94d568ef04c3dfbc39f96f015ed801ab8958e360d406503ce0, y: 0x2721b237df87234acc36a238b8f231a3d31d18fe3845fff4cc59f0bd873818f8, is_infinite: false }")] unconstrained fn unconstrained_test_should_fail_with_struct_fmt_string() { let hash = dep::std::hash::pedersen_commitment([27]); assert_eq(hash.x, 0, f"Invalid hash: {hash}");