From 1ab819b37e77ba71e74ace50a6f4ed94af25bf5d Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 7 Feb 2024 18:38:23 +0000 Subject: [PATCH 1/5] added validation test to cycle_group --- .../primitives/group/cycle_group.test.cpp | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp index 9a4fcd32c854..995893ca7f50 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp @@ -48,6 +48,27 @@ template class CycleGroupTest : public ::testing::Test { using CircuitTypes = ::testing::Types; TYPED_TEST_SUITE(CycleGroupTest, CircuitTypes); +TYPED_TEST(CycleGroupTest, TestValidateOnCurveSucceed) +{ + STDLIB_TYPE_ALIASES; + auto builder = Builder(); + + auto lhs = TestFixture::generators[0]; + cycle_group_ct a = cycle_group_ct::from_witness(&builder, lhs); + a.validate_is_on_curve(); + EXPECT_FALSE(builder.failed()); +} + +TYPED_TEST(CycleGroupTest, TestValidateOnCurveFail) +{ + STDLIB_TYPE_ALIASES; + auto builder = Builder(); + + cycle_group_ct a(1, 1, false); + a.validate_is_on_curve(); + EXPECT_TRUE(builder.failed()); +} + TYPED_TEST(CycleGroupTest, TestDbl) { STDLIB_TYPE_ALIASES; @@ -436,8 +457,8 @@ TYPED_TEST(CycleGroupTest, TestBatchMul) EXPECT_TRUE(result.is_point_at_infinity().get_value()); } - // case 5, fixed-base MSM with inputs that are combinations of constant and witnesses (group elements are in lookup - // table) + // case 5, fixed-base MSM with inputs that are combinations of constant and witnesses (group elements are in + // lookup table) { std::vector points; std::vector scalars; @@ -465,8 +486,8 @@ TYPED_TEST(CycleGroupTest, TestBatchMul) EXPECT_EQ(result.get_value(), crypto::pedersen_commitment::commit_native(scalars_native)); } - // case 6, fixed-base MSM with inputs that are combinations of constant and witnesses (some group elements are in - // lookup table) + // case 6, fixed-base MSM with inputs that are combinations of constant and witnesses (some group elements are + // in lookup table) { std::vector points; std::vector scalars; From c10521d8ab36d92e6d3de0c1af6483df25927f7e Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 7 Feb 2024 18:53:14 +0000 Subject: [PATCH 2/5] fixed bug and test --- .../stdlib/primitives/group/cycle_group.cpp | 3 ++- .../primitives/group/cycle_group.test.cpp | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp index f444e43f63b9..d6f3749e3b31 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp @@ -160,7 +160,8 @@ template void cycle_group::validate_is_on_curve() auto xx = x * x; auto xxx = xx * x; auto res = y.madd(y, -xxx - Group::curve_b); - res *= is_point_at_infinity(); + res *= !is_point_at_infinity(); // if the point is marked as the point at infinity, then res should be 0, but + // otherwise, we leave res unchanged res.assert_is_zero(); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp index 995893ca7f50..48185e2a197d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp @@ -59,12 +59,28 @@ TYPED_TEST(CycleGroupTest, TestValidateOnCurveSucceed) EXPECT_FALSE(builder.failed()); } +TYPED_TEST(CycleGroupTest, TestValidateOnCurveInfinitySucceed) +{ + STDLIB_TYPE_ALIASES; + auto builder = Builder(); + + auto x = stdlib::field_t::from_witness(&builder, 1); + auto y = stdlib::field_t::from_witness(&builder, 1); + + cycle_group_ct a(x, y, true); + a.validate_is_on_curve(); + EXPECT_FALSE(builder.failed()); +} + TYPED_TEST(CycleGroupTest, TestValidateOnCurveFail) { STDLIB_TYPE_ALIASES; auto builder = Builder(); - cycle_group_ct a(1, 1, false); + auto x = stdlib::field_t::from_witness(&builder, 1); + auto y = stdlib::field_t::from_witness(&builder, 1); + + cycle_group_ct a(x, y, false); a.validate_is_on_curve(); EXPECT_TRUE(builder.failed()); } From 5ad9af0515e68adaf54366d7f981dd5add008d77 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 7 Feb 2024 21:20:58 +0000 Subject: [PATCH 3/5] updated join_split test that compares hardcoded hash of vk --- .../join_split_example/proofs/join_split/join_split.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp index 5d110351dbb8..9d393d38b02a 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp @@ -707,7 +707,7 @@ TEST_F(join_split_tests, test_0_input_notes_and_detect_circuit_change) // The below part detects any changes in the join-split circuit constexpr uint32_t CIRCUIT_GATE_COUNT = 49492; constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 65535; - const uint256_t VK_HASH("cc3b14fad5465fe9b8c714e8a5d79012b86a70f6e37dfc23054e6def7eb1770f"); + const uint256_t VK_HASH("e253629a7f74dd33ac4288473df5fac928aae029cb8f5867bb413366b54c02ba"); auto number_of_gates_js = result.number_of_gates; std::cout << get_verification_key()->sha256_hash() << std::endl; From 696edbe4a1faa771d0572b438879efb48c883d95 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 8 Feb 2024 22:34:36 +0000 Subject: [PATCH 4/5] added comments --- .../stdlib/primitives/group/cycle_group.cpp | 5 ++-- .../primitives/group/cycle_group.test.cpp | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp index d6f3749e3b31..61fe555d88ff 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp @@ -160,8 +160,9 @@ template void cycle_group::validate_is_on_curve() auto xx = x * x; auto xxx = xx * x; auto res = y.madd(y, -xxx - Group::curve_b); - res *= !is_point_at_infinity(); // if the point is marked as the point at infinity, then res should be 0, but - // otherwise, we leave res unchanged + // if the point is marked as the point at infinity, then res should be changed to 0, but otherwise, we leave res + // unchanged from the original value + res *= !is_point_at_infinity(); res.assert_is_zero(); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp index 48185e2a197d..1e94ce9be31f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp @@ -48,10 +48,14 @@ template class CycleGroupTest : public ::testing::Test { using CircuitTypes = ::testing::Types; TYPED_TEST_SUITE(CycleGroupTest, CircuitTypes); +/** + * @brief Checks that a point on the curve passes the validate_is_on_curve check + * + */ TYPED_TEST(CycleGroupTest, TestValidateOnCurveSucceed) { STDLIB_TYPE_ALIASES; - auto builder = Builder(); + Builder builder; auto lhs = TestFixture::generators[0]; cycle_group_ct a = cycle_group_ct::from_witness(&builder, lhs); @@ -59,28 +63,38 @@ TYPED_TEST(CycleGroupTest, TestValidateOnCurveSucceed) EXPECT_FALSE(builder.failed()); } +/** + * @brief Checks that a point that is not on the curve but marked as the point at infinity passes the + * validate_is_on_curve check + * @details Should pass since marking it with _is_infinity=true makes whatever other point data invalid. + */ TYPED_TEST(CycleGroupTest, TestValidateOnCurveInfinitySucceed) { STDLIB_TYPE_ALIASES; - auto builder = Builder(); + Builder builder; auto x = stdlib::field_t::from_witness(&builder, 1); auto y = stdlib::field_t::from_witness(&builder, 1); - cycle_group_ct a(x, y, true); + cycle_group_ct a(x, y, /*_is_infinity=*/true); // marks this point as the point at infinity a.validate_is_on_curve(); EXPECT_FALSE(builder.failed()); } +/** + * @brief Checks that a point that is not on the curve but *not* marked as the point at infinity fails the + * validate_is_on_curve check + * @details (1, 1) is not on the either the Grumpkin curve or the BN254 curve. + */ TYPED_TEST(CycleGroupTest, TestValidateOnCurveFail) { STDLIB_TYPE_ALIASES; - auto builder = Builder(); + Builder builder; auto x = stdlib::field_t::from_witness(&builder, 1); auto y = stdlib::field_t::from_witness(&builder, 1); - cycle_group_ct a(x, y, false); + cycle_group_ct a(x, y, /*_is_infinity=*/false); a.validate_is_on_curve(); EXPECT_TRUE(builder.failed()); } From 244eec7f183d5d3a0ba3ef5227aeaeffcb43f506 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Fri, 9 Feb 2024 18:17:43 +0000 Subject: [PATCH 5/5] added check_circuit to tests --- .../barretenberg/stdlib/primitives/group/cycle_group.test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp index 1e94ce9be31f..71a88d52db30 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp @@ -61,6 +61,7 @@ TYPED_TEST(CycleGroupTest, TestValidateOnCurveSucceed) cycle_group_ct a = cycle_group_ct::from_witness(&builder, lhs); a.validate_is_on_curve(); EXPECT_FALSE(builder.failed()); + EXPECT_TRUE(builder.check_circuit()); } /** @@ -79,6 +80,7 @@ TYPED_TEST(CycleGroupTest, TestValidateOnCurveInfinitySucceed) cycle_group_ct a(x, y, /*_is_infinity=*/true); // marks this point as the point at infinity a.validate_is_on_curve(); EXPECT_FALSE(builder.failed()); + EXPECT_TRUE(builder.check_circuit()); } /** @@ -97,6 +99,7 @@ TYPED_TEST(CycleGroupTest, TestValidateOnCurveFail) cycle_group_ct a(x, y, /*_is_infinity=*/false); a.validate_is_on_curve(); EXPECT_TRUE(builder.failed()); + EXPECT_FALSE(builder.check_circuit()); } TYPED_TEST(CycleGroupTest, TestDbl)