From 3ec02aee0ad9f1345c7a3a6c0d8f56093de556a7 Mon Sep 17 00:00:00 2001 From: danny-shterman Date: Thu, 30 Jan 2025 09:05:25 +0000 Subject: [PATCH] Spell checker --- icicle/backend/cpu/src/hash/cpu_poseidon2.cpp | 126 +++++++++--------- .../include/icicle/fields/quartic_extension.h | 2 +- icicle/include/icicle/fields/storage.h | 12 +- icicle/tests/test_hash_api.cpp | 108 +++++++-------- 4 files changed, 125 insertions(+), 123 deletions(-) diff --git a/icicle/backend/cpu/src/hash/cpu_poseidon2.cpp b/icicle/backend/cpu/src/hash/cpu_poseidon2.cpp index b737d361d..98fc0d9d8 100644 --- a/icicle/backend/cpu/src/hash/cpu_poseidon2.cpp +++ b/icicle/backend/cpu/src/hash/cpu_poseidon2.cpp @@ -202,21 +202,21 @@ namespace icicle { const unsigned arity = m_use_domain_tag ? m_t - 1 : m_t; bool is_sponge = false; int input_size_in_scalars = size / sizeof(S); - if ((config.batch == 1) && (input_size_in_scalars != (m_use_domain_tag ? m_t - 1 : m_t))) { // Check if sponge function. + if ((config.batch == 1) && (input_size_in_scalars != (m_use_domain_tag ? m_t - 1 : m_t))) { // Check if sponge + // function. is_sponge = true; if (config.batch != 1) { - ICICLE_LOG_ERROR - << "The only suppoorted value of config.batch for sponge functions is 1.\n"; + ICICLE_LOG_ERROR << "The only suppoorted value of config.batch for sponge functions is 1.\n"; return eIcicleError::INVALID_ARGUMENT; } - } // sponge function - else { // Non-sponge function. + } // sponge function + else { // Non-sponge function. if ((m_use_domain_tag ? input_size_in_scalars : input_size_in_scalars - 1) % (m_t - 1) != 0) { - ICICLE_LOG_ERROR - << "Padding isn't supported for non-sponge function hash. The following should be true: ((m_use_domain_tag ? size : size-1) % (m_t-1) != 0).\n"; + ICICLE_LOG_ERROR << "Padding isn't supported for non-sponge function hash. The following should be true: " + "((m_use_domain_tag ? size : size-1) % (m_t-1) != 0).\n"; return eIcicleError::INVALID_ARGUMENT; } - } // Non-sponge function. + } // Non-sponge function. const unsigned int T = m_t; bool is_unsupported_T_for_this_field = poseidon2_constants[T].nof_upper_full_rounds == 0; @@ -234,27 +234,27 @@ namespace icicle { S* partial_matrix_diagonal_m1 = poseidon2_constants[T].partial_matrix_diagonal_m1; // Allocate temporary memory for intermediate calcs and in order not to change the input. - // int sponge_nof_hashers = m_use_domain_tag ? (input_size_in_scalars / arity) : ((input_size_in_scalars - 1) / (arity - 1)); - // int tmp_fields_nof_scalars = is_sponge ? (T * sponge_nof_hashers) : (T * config.batch); - // S* tmp_fields = new S[tmp_fields_nof_scalars]; + // int sponge_nof_hashers = m_use_domain_tag ? (input_size_in_scalars / arity) : ((input_size_in_scalars - 1) / + // (arity - 1)); int tmp_fields_nof_scalars = is_sponge ? (T * sponge_nof_hashers) : (T * config.batch); S* + // tmp_fields = new S[tmp_fields_nof_scalars]; S* tmp_fields; - S* tmp_fields_init_ptr; // This pointer to keep initial tmp_fields value to perform a easy rollback when needed. + S* tmp_fields_init_ptr; // This pointer to keep initial tmp_fields value to perform a easy rollback when needed. int sponge_nof_hashers; const S* in_fields = (S*)(input); int padding_size = 0; S* padding; if (is_sponge) { - if (input_size_in_scalars < T) { // Single hasher in the chain. + if (input_size_in_scalars < T) { // Single hasher in the chain. sponge_nof_hashers = 1; padding_size = T - (input_size_in_scalars + (m_use_domain_tag == true)); - } else if (input_size_in_scalars >= T) { // More than a single hasher in the chain. - sponge_nof_hashers = (input_size_in_scalars - !(m_use_domain_tag == true) + (T - 2)) / (T - 1); - bool is_padding_needed = (input_size_in_scalars - !(m_use_domain_tag == true)) % (T - 1); - if (is_padding_needed ) { + } else if (input_size_in_scalars >= T) { // More than a single hasher in the chain. + sponge_nof_hashers = (input_size_in_scalars - !(m_use_domain_tag == true) + (T - 2)) / (T - 1); + bool is_padding_needed = (input_size_in_scalars - !(m_use_domain_tag == true)) % (T - 1); + if (is_padding_needed) { padding_size = (T - 1) - ((input_size_in_scalars - !(m_use_domain_tag == true)) % (T - 1)); } } - if (padding_size > 0) { // Fill padding array with 1,0,0,... + if (padding_size > 0) { // Fill padding array with 1,0,0,... padding = new S[padding_size]; padding[0] = S::from(1); for (int i = 1; i < padding_size; i++) { @@ -264,48 +264,45 @@ namespace icicle { tmp_fields = new S[T * sponge_nof_hashers]; tmp_fields_init_ptr = tmp_fields; // Take care of hasher 0. It's done separately of the rest of the hashers because of the domain tag. - if (m_use_domain_tag) { + if (m_use_domain_tag) { // Domain tag exists only for the first hasher. For the rest of the hashers this // input is undefined at this stage and its value will be set later. // tmp_fields = {{dt, in0}, {undef, in1}, {undef, in2}, etc.} memcpy(tmp_fields, &m_domain_tag, sizeof(S)); - } - else { + } else { // tmp_fields = {{in0 (T inputs)}, {undef, in1 (T-1 inputs)}, {under, in2 (T-1 inputs)}, etc.} memcpy(tmp_fields, &in_fields[0], sizeof(S)); - in_fields += 1; + in_fields += 1; } - tmp_fields += 1; + tmp_fields += 1; // Take care of rest of the hashers (T-1 scalar to each hasher). for (int hasher_idx = 0; hasher_idx < sponge_nof_hashers; hasher_idx++) { - if (hasher_idx == sponge_nof_hashers-1 && padding_size > 0) { + if (hasher_idx == sponge_nof_hashers - 1 && padding_size > 0) { // Last hasher in the chain. Take care of padding if needed. memcpy(tmp_fields, in_fields, (T - padding_size - 1) * sizeof(S)); memcpy(tmp_fields + T - padding_size - 1, padding, padding_size * sizeof(S)); - } - else { // Not a last hasher in the chain. There is no padding. + } else { // Not a last hasher in the chain. There is no padding. memcpy(tmp_fields, in_fields, (T - 1) * sizeof(S)); } in_fields += (T - 1); tmp_fields += T; } - tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. - } // if (is_sponge) { - else { // Not a sponge function. The is no padding. + tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. + } // if (is_sponge) { + else { // Not a sponge function. The is no padding. // Input of each hash should have domain tag at its input. // tmp_fields = {{dt, in0 (T-1 inputs)}, {dt, in1 (T-1 inputs)}, {dt, in2 (T-1 inputs)}, etc.} tmp_fields = new S[T * config.batch]; - tmp_fields_init_ptr = tmp_fields; // Keep tmp_fields pointer for delete. - if (m_use_domain_tag) { + tmp_fields_init_ptr = tmp_fields; // Keep tmp_fields pointer for delete. + if (m_use_domain_tag) { for (int batch_idx = 0; batch_idx < config.batch; batch_idx++) { memcpy(tmp_fields, &m_domain_tag, sizeof(S)); memcpy(tmp_fields + 1, in_fields, (T - 1) * sizeof(S)); in_fields += (T - 1); tmp_fields += T; } - tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. - } - else { + tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. + } else { // tmp_fields = {{in0 (T inputs)}, {in1 (T inputs)}, {in2 (T inputs)}, etc.} memcpy(tmp_fields, in_fields, T * config.batch * sizeof(S)); } @@ -313,48 +310,47 @@ namespace icicle { // Hashes processing. if (is_sponge) { - // Call hash_single for hasher[0] - eIcicleError err = hash_single(tmp_fields /* input */, tmp_fields /* output */, - alpha, nof_upper_full_rounds, nof_partial_rounds, nof_bottom_full_rounds, - rounds_constants, mds_matrix, partial_matrix_diagonal_m1); - S* tmp_fields_tmp_ptr = tmp_fields; // Save current pointer in order to access prev output. + // Call hash_single for hasher[0] + eIcicleError err = hash_single( + tmp_fields /* input */, tmp_fields /* output */, alpha, nof_upper_full_rounds, nof_partial_rounds, + nof_bottom_full_rounds, rounds_constants, mds_matrix, partial_matrix_diagonal_m1); + S* tmp_fields_tmp_ptr = tmp_fields; // Save current pointer in order to access prev output. if (err != eIcicleError::SUCCESS) return err; if (sponge_nof_hashers != 1) { - tmp_fields[T] = tmp_fields[0]; // Current first output is an input to the next hasher. + tmp_fields[T] = tmp_fields[0]; // Current first output is an input to the next hasher. } tmp_fields += T; // Process rest of the hashers. - for (int hasher_idx = 1; hasher_idx < sponge_nof_hashers; hasher_idx++) { + for (int hasher_idx = 1; hasher_idx < sponge_nof_hashers; hasher_idx++) { // The first output of the prev hasher is the first input of the current hasher. // The T-1 new inputs of the current hasher should be added to the T-1 outputs of the // prev hasher (starting fom index 1). for (int i = 1; i < T; i++) { tmp_fields[i] = tmp_fields_tmp_ptr[i] + tmp_fields[i]; } - eIcicleError err = hash_single(tmp_fields /* input */, tmp_fields /* output */, - alpha, nof_upper_full_rounds, nof_partial_rounds, nof_bottom_full_rounds, - rounds_constants, mds_matrix, partial_matrix_diagonal_m1); - tmp_fields_tmp_ptr = tmp_fields; // Save current pointer in order to access prev output. + eIcicleError err = hash_single( + tmp_fields /* input */, tmp_fields /* output */, alpha, nof_upper_full_rounds, nof_partial_rounds, + nof_bottom_full_rounds, rounds_constants, mds_matrix, partial_matrix_diagonal_m1); + tmp_fields_tmp_ptr = tmp_fields; // Save current pointer in order to access prev output. if (err != eIcicleError::SUCCESS) return err; - if (hasher_idx != sponge_nof_hashers - 1) // Not to do in the last loop to prevent mem leak. - tmp_fields[T] = tmp_fields[0]; // Fill first scalar of the input to the next hasher. - tmp_fields += T; // Now tmp_fields points to input of the next hasher before the addition. - } // for (int hasher_idx = 1; hasher_idx < sponge_nof_hashers; hasher_idx++) { - tmp_fields -= T; // Rollback to the last hasher output. + if (hasher_idx != sponge_nof_hashers - 1) // Not to do in the last loop to prevent mem leak. + tmp_fields[T] = tmp_fields[0]; // Fill first scalar of the input to the next hasher. + tmp_fields += T; // Now tmp_fields points to input of the next hasher before the addition. + } // for (int hasher_idx = 1; hasher_idx < sponge_nof_hashers; hasher_idx++) { + tmp_fields -= T; // Rollback to the last hasher output. memcpy(output, (std::byte*)(&tmp_fields[1]), sizeof(S)); - tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. - } - else { // Not a sponge function. + tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. + } else { // Not a sponge function. for (int batch_hash_idx = 0; batch_hash_idx < config.batch; batch_hash_idx++) { - eIcicleError err = hash_single(tmp_fields /* input */, tmp_fields /* output */, - alpha, nof_upper_full_rounds, nof_partial_rounds, nof_bottom_full_rounds, - rounds_constants, mds_matrix, partial_matrix_diagonal_m1); + eIcicleError err = hash_single( + tmp_fields /* input */, tmp_fields /* output */, alpha, nof_upper_full_rounds, nof_partial_rounds, + nof_bottom_full_rounds, rounds_constants, mds_matrix, partial_matrix_diagonal_m1); if (err != eIcicleError::SUCCESS) return err; memcpy(output, (std::byte*)(&tmp_fields[1]), sizeof(S)); tmp_fields += T; output += sizeof(S); } - tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. + tmp_fields = tmp_fields_init_ptr; // Rollback to initial value. } delete[] tmp_fields; @@ -362,7 +358,8 @@ namespace icicle { tmp_fields = nullptr; return eIcicleError::SUCCESS; - } // eIcicleError hash(const std::byte* input, uint64_t size, const HashConfig& config, std::byte* output) const override + } // eIcicleError hash(const std::byte* input, uint64_t size, const HashConfig& config, std::byte* output) const + // override private: // // DEBUG start. Do not remove!!! @@ -383,9 +380,16 @@ namespace icicle { // This function performs a single hash according to parameters in the poseidon2_constants[] struct. // eIcicleError hash_single(const std::byte* input, std::byte* output) const - eIcicleError hash_single(S* tmp_fields, S* hasher_output, int alpha, int nof_upper_full_rounds, - int nof_partial_rounds, int nof_bottom_full_rounds, - S* rounds_constants, S* mds_matrix, S* partial_matrix_diagonal_m1) const + eIcicleError hash_single( + S* tmp_fields, + S* hasher_output, + int alpha, + int nof_upper_full_rounds, + int nof_partial_rounds, + int nof_bottom_full_rounds, + S* rounds_constants, + S* mds_matrix, + S* partial_matrix_diagonal_m1) const { const unsigned int T = m_t; diff --git a/icicle/include/icicle/fields/quartic_extension.h b/icicle/include/icicle/fields/quartic_extension.h index 6478e915c..784298cac 100644 --- a/icicle/include/icicle/fields/quartic_extension.h +++ b/icicle/include/icicle/fields/quartic_extension.h @@ -241,7 +241,7 @@ class QuarticExtensionField FF::reduce( (CONFIG::nonresidue_is_negative ? (FF::mul_wide(xs.real, x0) + FF::template mul_unsigned(FF::mul_wide(xs.im2, x2))) - : (FF::mul_wide(xs.real, x0))-FF::template mul_unsigned(FF::mul_wide(xs.im2, x2)))), + : (FF::mul_wide(xs.real, x0)) - FF::template mul_unsigned(FF::mul_wide(xs.im2, x2)))), FF::reduce( (CONFIG::nonresidue_is_negative ? FWide::neg(FF::template mul_unsigned(FF::mul_wide(xs.im3, x2))) diff --git a/icicle/include/icicle/fields/storage.h b/icicle/include/icicle/fields/storage.h index 097db881f..76245db16 100644 --- a/icicle/include/icicle/fields/storage.h +++ b/icicle/include/icicle/fields/storage.h @@ -16,7 +16,8 @@ struct #ifdef __CUDA_ARCH__ __align__(LIMBS_ALIGNMENT(1)) #endif - storage<1> { + storage<1> +{ static constexpr unsigned LC = 1; uint32_t limbs[1]; }; @@ -27,7 +28,8 @@ struct #ifdef __CUDA_ARCH__ __align__(LIMBS_ALIGNMENT(1)) #endif - storage<3> { + storage<3> +{ static constexpr unsigned LC = 3; uint32_t limbs[3]; }; @@ -38,7 +40,8 @@ struct #ifdef __CUDA_ARCH__ __align__(LIMBS_ALIGNMENT(LIMBS_COUNT)) #endif - storage { + storage +{ static_assert(LIMBS_COUNT % 2 == 0, "odd number of limbs is not supported\n"); static constexpr unsigned LC = LIMBS_COUNT; union { // works only with even LIMBS_COUNT @@ -52,6 +55,7 @@ struct #ifdef __CUDA_ARCH__ __align__(LIMBS_ALIGNMENT(LIMBS_COUNT)) #endif - storage_array { + storage_array +{ storage storages[OMEGAS_COUNT]; }; \ No newline at end of file diff --git a/icicle/tests/test_hash_api.cpp b/icicle/tests/test_hash_api.cpp index 0a2eea7f1..8062d825b 100644 --- a/icicle/tests/test_hash_api.cpp +++ b/icicle/tests/test_hash_api.cpp @@ -1150,9 +1150,9 @@ TEST_F(HashApiTest, poseidon_tree) #endif // POSEIDON #ifdef POSEIDON2 -// DEBUG. This test could run only with bn254 curve. Dont remove!!! -// bn254: p = 0x303b6f7c86d043bfcbcc80214f26a30277a15d3f74ca654992defe7ff8d03570 -#include "icicle/fields/field_config.h" + // DEBUG. This test could run only with bn254 curve. Dont remove!!! + // bn254: p = 0x303b6f7c86d043bfcbcc80214f26a30277a15d3f74ca654992defe7ff8d03570 + #include "icicle/fields/field_config.h" using namespace field_config; TEST_F(HashApiTest, poseidon2_3_single_hasher) { @@ -1161,11 +1161,11 @@ TEST_F(HashApiTest, poseidon2_3_single_hasher) config.batch = 1; auto input = std::make_unique(config.batch * t); - for (int i=0; i(config.batch); run(IcicleTestBase::reference_device(), output_cpu.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); -#if FIELD_ID == BN254 + #if FIELD_ID == BN254 scalar_t expected_res = - scalar_t::hex_str2scalar("0x303b6f7c86d043bfcbcc80214f26a30277a15d3f74ca654992defe7ff8d03570"); + scalar_t::hex_str2scalar("0x303b6f7c86d043bfcbcc80214f26a30277a15d3f74ca654992defe7ff8d03570"); ASSERT_EQ(expected_res, *(output_cpu.get())); -#endif + #endif if (IcicleTestBase::main_device() == "CUDA") { std::cout << "Run CUDA test " << std::endl; @@ -1200,13 +1200,12 @@ TEST_F(HashApiTest, poseidon2_3_single_hasher) ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); std::cout << "End CUDA test " << std::endl; } -} // poseidon2_3_single_hasher - +} // poseidon2_3_single_hasher // Test used to generate expected result of the nd hasher. TEST_F(HashApiTest, poseidon2_3_gen_hasher_expected_result_cpu_only) { -#if FIELD_ID == BN254 + #if FIELD_ID == BN254 const unsigned t = 3; auto config = default_hash_config(); config.batch = 1; @@ -1221,7 +1220,7 @@ TEST_F(HashApiTest, poseidon2_3_gen_hasher_expected_result_cpu_only) input[2] = scalar_t::from(8); // input[3] = scalar_t::from(7); // for (int i = 0; i < t; i++) { - // std::cout << "poseidon2_3_gen_hasher_expected_result_cpu_only input " << input[i] << std::endl; + // std::cout << "poseidon2_3_gen_hasher_expected_result_cpu_only input " << input[i] << std::endl; // } auto run = [&](const std::string& dev_type, scalar_t* out, bool measure, const char* msg, int iters) { @@ -1242,9 +1241,8 @@ TEST_F(HashApiTest, poseidon2_3_gen_hasher_expected_result_cpu_only) auto output_cpu = std::make_unique(config.batch); run(IcicleTestBase::reference_device(), output_cpu.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); -#endif -} // poseidon2_3_gen_hasher_expected_result_cpu_only - + #endif +} // poseidon2_3_gen_hasher_expected_result_cpu_only // Sponge, chain of 2 hashers, no padding, no domain tag. TEST_F(HashApiTest, poseidon2_3_sponge_2_hashers_without_dt) @@ -1254,12 +1252,12 @@ TEST_F(HashApiTest, poseidon2_3_sponge_2_hashers_without_dt) int nof_hashers = 2; auto input = std::make_unique(1 + nof_hashers * (t - 1)); - for (int i=0; i(config.batch); // config.batch = 1 here. + auto output_cpu = std::make_unique(config.batch); // config.batch = 1 here. run(IcicleTestBase::reference_device(), output_cpu.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); -#if FIELD_ID == BN254 + #if FIELD_ID == BN254 scalar_t expected_res = - scalar_t::hex_str2scalar("0x0d54b4b71781dc4f30afe3a90f76559379f6f75aea6968d4c986512e2711ad20"); + scalar_t::hex_str2scalar("0x0d54b4b71781dc4f30afe3a90f76559379f6f75aea6968d4c986512e2711ad20"); ASSERT_EQ(expected_res, *(output_cpu.get())); -#endif + #endif std::string main_device = IcicleTestBase::main_device(); if (IcicleTestBase::main_device() == "CUDA") { @@ -1298,8 +1296,7 @@ TEST_F(HashApiTest, poseidon2_3_sponge_2_hashers_without_dt) run(IcicleTestBase::main_device(), output_mainDev.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); } -} // poseidon2_3_sponge_2_hashers_without_dt - +} // poseidon2_3_sponge_2_hashers_without_dt // Sponge, chain of 2 hashers, no padding, with domain tag. TEST_F(HashApiTest, poseidon2_3_sponge_2_hashers_with_dt) @@ -1314,8 +1311,8 @@ TEST_F(HashApiTest, poseidon2_3_sponge_2_hashers_with_dt) // Input will be 4,5,6,8. // With dt and padding it will be 4,5,6,7,8,1,0. auto input = std::make_unique(nof_valid_inputs); - for (int i=0; i(config.batch); // config.batch = 1 here. + auto output_cpu = std::make_unique(config.batch); // config.batch = 1 here. run(IcicleTestBase::reference_device(), output_cpu.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); -#if FIELD_ID == BN254 + #if FIELD_ID == BN254 scalar_t expected_res = - scalar_t::hex_str2scalar("0x286786cd695dbe838456c72a5edb4d2717a17a0971006671c26c0219c3de5abe"); + scalar_t::hex_str2scalar("0x286786cd695dbe838456c72a5edb4d2717a17a0971006671c26c0219c3de5abe"); ASSERT_EQ(expected_res, *(output_cpu.get())); -#endif + #endif if (IcicleTestBase::main_device() == "CUDA") { std::cout << "Run CUDA test " << std::endl; @@ -1352,8 +1349,7 @@ TEST_F(HashApiTest, poseidon2_3_sponge_2_hashers_with_dt) run(IcicleTestBase::main_device(), output_mainDev.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); } -} // poseidon2_3_sponge_2_hashers_with_dt - +} // poseidon2_3_sponge_2_hashers_with_dt // Sponge, chain of 1 hasher, with padding (2 scalars 1,0), no domain tag. TEST_F(HashApiTest, poseidon2_3_sponge_1_hasher_without_dt_with_padding) @@ -1364,8 +1360,8 @@ TEST_F(HashApiTest, poseidon2_3_sponge_1_hasher_without_dt_with_padding) int nof_valid_inputs = 2; auto input = std::make_unique(nof_valid_inputs); - for (int i=0; i(config.batch); // config.batch = 1 here. + auto output_cpu = std::make_unique(config.batch); // config.batch = 1 here. run(IcicleTestBase::reference_device(), output_cpu.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); -#if FIELD_ID == BN254 + #if FIELD_ID == BN254 scalar_t expected_res = - scalar_t::hex_str2scalar("0x2645a6e432f38bb4f197b1b4a69d6fac977cdb4927cfbb62f133a9e427dee146"); + scalar_t::hex_str2scalar("0x2645a6e432f38bb4f197b1b4a69d6fac977cdb4927cfbb62f133a9e427dee146"); ASSERT_EQ(expected_res, *(output_cpu.get())); -#endif + #endif if (IcicleTestBase::main_device() == "CUDA") { std::cout << "Run CUDA test " << std::endl; @@ -1402,8 +1398,7 @@ TEST_F(HashApiTest, poseidon2_3_sponge_1_hasher_without_dt_with_padding) run(IcicleTestBase::main_device(), output_mainDev.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); } -} // poseidon2_3_sponge_1_hasher_without_dt_with_padding - +} // poseidon2_3_sponge_1_hasher_without_dt_with_padding // Sponge, chain of 2 hashers, with padding (2 scalars 1,0), no domain tag. TEST_F(HashApiTest, poseidon2_4_sponge_2_hashers_without_dt_with_padding) @@ -1414,8 +1409,8 @@ TEST_F(HashApiTest, poseidon2_4_sponge_2_hashers_without_dt_with_padding) int nof_valid_inputs = 5; auto input = std::make_unique(nof_valid_inputs); - for (int i=0; i(config.batch); // config.batch = 1 here. + auto output_cpu = std::make_unique(config.batch); // config.batch = 1 here. run(IcicleTestBase::reference_device(), output_cpu.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); -#if FIELD_ID == BN254 + #if FIELD_ID == BN254 scalar_t expected_res = - scalar_t::hex_str2scalar("0x0353fae9638ef80c9a80786ce24c42d6e087695a40cd5ca29207f20b72f25379"); + scalar_t::hex_str2scalar("0x0353fae9638ef80c9a80786ce24c42d6e087695a40cd5ca29207f20b72f25379"); ASSERT_EQ(expected_res, *(output_cpu.get())); -#endif + #endif if (IcicleTestBase::main_device() == "CUDA") { std::cout << "Run CUDA test " << std::endl; @@ -1452,8 +1447,7 @@ TEST_F(HashApiTest, poseidon2_4_sponge_2_hashers_without_dt_with_padding) run(IcicleTestBase::main_device(), output_mainDev.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); } -} // poseidon2_4_sponge_2_hashers_without_dt_with_padding - +} // poseidon2_4_sponge_2_hashers_without_dt_with_padding // Test check single hash without domain tag. TEST_F(HashApiTest, poseidon2_3_single_hash_without_dt) @@ -1500,7 +1494,7 @@ TEST_F(HashApiTest, poseidon2_3_single_hash_without_dt) run(IcicleTestBase::main_device(), output_mainDev.get(), VERBOSE /*=measure*/, "poseidon2", ITERS); ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); -} // poseidon2_3_single_hash_without_dt +} // poseidon2_3_single_hash_without_dt TEST_F(HashApiTest, poseidon2_3_sponge_hash_2_without_dt) { @@ -1535,7 +1529,7 @@ TEST_F(HashApiTest, poseidon2_3_sponge_hash_2_without_dt) START_TIMER(POSEIDON2_sync) for (int i = 0; i < iters; ++i) { - ICICLE_CHECK(poseidon2.hash(input.get(), 1 + nof_hashers * (t-1), config, out)); + ICICLE_CHECK(poseidon2.hash(input.get(), 1 + nof_hashers * (t - 1), config, out)); } END_TIMER(POSEIDON2_sync, oss.str().c_str(), measure); }; @@ -1548,13 +1542,13 @@ TEST_F(HashApiTest, poseidon2_3_sponge_hash_2_without_dt) ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); int a = 5; -} // poseidon2_3_sponge_hash_2_without_dt +} // poseidon2_3_sponge_hash_2_without_dt TEST_F(HashApiTest, poseidon2_3_sponge_hash_1K_without_dt) { const unsigned t = 3; auto config = default_hash_config(); - int nof_hashers = 1<<10; + int nof_hashers = 1 << 10; auto input = std::make_unique(1 + nof_hashers * (t - 1)); scalar_t::rand_host_many(input.get(), 1 + nof_hashers * (t - 1)); @@ -1581,10 +1575,10 @@ TEST_F(HashApiTest, poseidon2_3_sponge_hash_1K_without_dt) auto poseidon2 = Poseidon2::create(t); - ICICLE_CHECK(poseidon2.hash(input.get(), 1 + nof_hashers * (t-1), config, out)); + ICICLE_CHECK(poseidon2.hash(input.get(), 1 + nof_hashers * (t - 1), config, out)); START_TIMER(POSEIDON2_sync) for (int i = 0; i < iters; ++i) { - ICICLE_CHECK(poseidon2.hash(input.get(), 1 + nof_hashers * (t-1), config, out)); + ICICLE_CHECK(poseidon2.hash(input.get(), 1 + nof_hashers * (t - 1), config, out)); } END_TIMER(POSEIDON2_sync, oss.str().c_str(), measure); }; @@ -1597,7 +1591,7 @@ TEST_F(HashApiTest, poseidon2_3_sponge_hash_1K_without_dt) ASSERT_EQ(0, memcmp(output_cpu.get(), output_mainDev.get(), config.batch * sizeof(scalar_t))); int a = 5; -} // poseidon2_3_sponge_hash_1K_without_dt +} // poseidon2_3_sponge_hash_1K_without_dt TEST_F(HashApiTest, poseidon2_invalid_t) {