From 7c34968d2d21f1d593421ab8ded545afe7b14338 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 14:19:00 +0000 Subject: [PATCH 1/3] `bool_t::must_imply` fail test. --- .../stdlib/primitives/bool/bool.test.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp b/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp index a9e99d496e..113a8986c6 100644 --- a/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp @@ -391,7 +391,26 @@ TEST(stdlib_bool, must_imply) EXPECT_EQ(result, true); } -// TODO: must_imply failure case +TEST(stdlib_bool, must_imply_fails) +{ + honk::StandardHonkComposer composer = honk::StandardHonkComposer(); + for (size_t j = 0; j < 3; ++j) { // ignore the case when both lhs and rhs are constants + bool lhs_constant = (bool)(j % 2); + bool rhs_constant = (bool)(j > 1 ? true : false); + + // If a number is divisible by 2 and 3, it is divisible by 6 + // => 8 is not divisible by 3, so it must not be divisible by 6 + const size_t i = 8; + bool a_val = (bool)(i % 2 == 0); + bool b_val = (bool)(i % 6 == 0); + bool_t a = lhs_constant ? bool_t(a_val) : (witness_t(&composer, a_val)); + bool_t b = rhs_constant ? bool_t(b_val) : (witness_t(&composer, b_val)); + a.must_imply(b, "div by 2 does not imply div by 8"); + + EXPECT_EQ(composer.failed(), true); + EXPECT_EQ(composer.err(), "div by 2 does not imply div by 8"); + } +} TEST(stdlib_bool, must_imply_multiple) { From da1238569798600a89021a2384fe2a8389ae8d0d Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Wed, 5 Apr 2023 12:18:54 +0000 Subject: [PATCH 2/3] Add edge-case tests to array. --- .../stdlib/primitives/field/array.test.cpp | 77 ++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp b/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp index cace1e5b56..41a17dcd30 100644 --- a/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp @@ -29,8 +29,6 @@ template class stdlib_array : public testing::Test { typedef stdlib::public_witness_t public_witness_ct; public: - // TODO: empty array and singleton array edge cases for all array functions. - static void test_array_length() { Composer composer = Composer(); @@ -375,6 +373,36 @@ template class stdlib_array : public testing::Test { EXPECT_TRUE(proof_result); } + static void test_pata_null_source() + { + // null means array size is 0 + Composer composer = Composer(); + + std::array source; + std::array target = { 1, 2, 0, 0 }; + std::array expected_target = { 1, 2, 0, 0 }; + bool proof_result; + std::string error; + std::tie(proof_result, error) = test_push_array_to_array_helper(composer, source, target, expected_target); + + EXPECT_TRUE(proof_result); + } + + static void test_pata_null_target_fails() + { + Composer composer = Composer(); + + std::array source = { 1, 2, 0, 0 }; + std::array target; + std::array expected_target; + bool proof_result; + std::string error; + std::tie(proof_result, error) = test_push_array_to_array_helper(composer, source, target, expected_target); + + EXPECT_FALSE(proof_result); + EXPECT_EQ(error, "push_array_to_array target array capacity exceeded"); + } + static void test_pata_singletons_full_to_not_full() { Composer composer = Composer(); @@ -389,6 +417,35 @@ template class stdlib_array : public testing::Test { EXPECT_TRUE(proof_result); } + static void test_pata_singletons_not_full_to_full() + { + Composer composer = Composer(); + + std::array source = { 0 }; + std::array target = { 1 }; + std::array expected_target = { 1 }; + bool proof_result; + std::string error; + std::tie(proof_result, error) = test_push_array_to_array_helper(composer, source, target, expected_target); + + EXPECT_TRUE(proof_result); + } + + static void test_pata_singletons_full_to_full() + { + Composer composer = Composer(); + + std::array source = { 2 }; + std::array target = { 1 }; + std::array expected_target = { 1 }; + bool proof_result; + std::string error; + std::tie(proof_result, error) = test_push_array_to_array_helper(composer, source, target, expected_target); + + EXPECT_FALSE(proof_result); + EXPECT_EQ(error, "push_array_to_array target array capacity exceeded"); + } + static void test_pata_same_size_full_to_full_fails() { Composer composer = Composer(); @@ -608,10 +665,26 @@ TYPED_TEST(stdlib_array, test_pata_smaller_source_full_to_not_full) { TestFixture::test_pata_smaller_source_full_to_not_full(); } +TYPED_TEST(stdlib_array, test_pata_null_source) +{ + TestFixture::test_pata_null_source(); +} +TYPED_TEST(stdlib_array, test_pata_null_target_fails) +{ + TestFixture::test_pata_null_target_fails(); +} TYPED_TEST(stdlib_array, test_pata_singletons_full_to_not_full) { TestFixture::test_pata_singletons_full_to_not_full(); } +TYPED_TEST(stdlib_array, test_pata_singletons_not_full_to_full) +{ + TestFixture::test_pata_singletons_not_full_to_full(); +} +TYPED_TEST(stdlib_array, test_pata_singletons_full_to_full) +{ + TestFixture::test_pata_singletons_full_to_full(); +} TYPED_TEST(stdlib_array, test_pata_same_size_full_to_full_fails) { TestFixture::test_pata_same_size_full_to_full_fails(); From 989c2ef3af9804d54e6ff60dd8d060c51e845b4f Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Wed, 5 Apr 2023 12:32:50 +0000 Subject: [PATCH 3/3] add null len test. --- .../stdlib/primitives/field/array.test.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp b/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp index 41a17dcd30..8ad43f5e55 100644 --- a/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp @@ -53,6 +53,23 @@ template class stdlib_array : public testing::Test { EXPECT_EQ(proof_result, true); } + static void test_array_length_null() + { + Composer composer = Composer(); + + std::array values_ct; + auto filled_len = array_length(values_ct); + EXPECT_EQ(filled_len.get_value(), 0); + EXPECT_TRUE(filled_len.is_constant()); + + auto prover = composer.create_prover(); + auto verifier = composer.create_verifier(); + auto proof = prover.construct_proof(); + info("composer gates = ", composer.get_num_gates()); + bool proof_result = verifier.verify_proof(proof); + EXPECT_EQ(proof_result, true); + } + static void test_array_length_fails() { Composer composer = Composer(); @@ -285,7 +302,7 @@ template class stdlib_array : public testing::Test { } bool proof_result = false; - if (composer.err().empty()) { + if (!composer.failed()) { auto prover = composer.create_prover(); auto verifier = composer.create_verifier(); auto proof = prover.construct_proof(); @@ -616,6 +633,10 @@ TYPED_TEST(stdlib_array, test_array_length) { TestFixture::test_array_length(); } +TYPED_TEST(stdlib_array, test_array_length_null) +{ + TestFixture::test_array_length_null(); +} TYPED_TEST(stdlib_array, test_array_length_fails) { TestFixture::test_array_length_fails();