From 29d8170709fb93fccf0fe78db416c20ce5d69793 Mon Sep 17 00:00:00 2001 From: alfredmox <> Date: Tue, 22 Jan 2019 03:34:09 -0800 Subject: [PATCH 1/3] concurrency tests --- tests/functional_tests/core_concurrency_test.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 23bb8885..11594763 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -101,14 +101,17 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_ const currency::account_public_address& miner_addr = wallets[random_in_range(0, wallets.size() - 1)]->get_account().get_public_address(); currency::block b = AUTO_VAL_INIT(b); + currency::scratchpad_keeper sk; + crypto::hash seed = currency::null_hash; + sk.generate(seed, height); if (is_in_main_chain) { blobdata ex_nonce; wide_difficulty_type diff = 0; if (prev_block.height != 0) test_core_time::adjust(prev_block.bl.timestamp + DIFFICULTY_POW_TARGET); - r = bcs.create_block_template(b, miner_addr, diff, height, ex_nonce); + r = bcs.create_block_template(b, seed, miner_addr, diff, height, ex_nonce); CHECK_AND_ASSERT_MES(r, false, "create_block_template failed"); } else @@ -142,7 +145,7 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_ test_core_time::adjust(b.timestamp); currency::wide_difficulty_type diff = 0; - r = currency::miner::find_nonce_for_given_block(b, diff, height); + r = currency::miner::find_nonce_for_given_block(b, diff, height, seed, sk); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); From 256ab7d0ed5f4ee5c98cc50247312ec177c85255 Mon Sep 17 00:00:00 2001 From: alfredmox <> Date: Tue, 22 Jan 2019 03:35:07 -0800 Subject: [PATCH 2/3] keccak tests --- src/crypto/wild_keccak.h | 10 ++++------ tests/performance_tests/keccak_test.h | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/crypto/wild_keccak.h b/src/crypto/wild_keccak.h index eb017aef..f7abaf0c 100644 --- a/src/crypto/wild_keccak.h +++ b/src/crypto/wild_keccak.h @@ -30,12 +30,10 @@ extern "C" { namespace crypto { #define OPT_XOR_4_RES(A_, B_, C_, D_, Res) \ - crypto::hash A = A_;crypto::hash B = B_;crypto::hash C = C_; crypto::hash D = D_; \ - ((uint64_t*)&Res)[0] = ((const uint64_t*)&A)[0] ^ ((const uint64_t*)&B)[0] ^ ((const uint64_t*)&C)[0] ^ ((const uint64_t*)&D)[0]; \ - ((uint64_t*)&Res)[1] = ((const uint64_t*)&A)[1] ^ ((const uint64_t*)&B)[1] ^ ((const uint64_t*)&C)[1] ^ ((const uint64_t*)&D)[1]; \ - ((uint64_t*)&Res)[2] = ((const uint64_t*)&A)[2] ^ ((const uint64_t*)&B)[2] ^ ((const uint64_t*)&C)[2] ^ ((const uint64_t*)&D)[2]; \ - ((uint64_t*)&Res)[3] = ((const uint64_t*)&A)[3] ^ ((const uint64_t*)&B)[3] ^ ((const uint64_t*)&C)[3] ^ ((const uint64_t*)&D)[3]; - + ((uint64_t*)&Res)[0] = ((const uint64_t*)&A_)[0] ^ ((const uint64_t*)&B_)[0] ^ ((const uint64_t*)&C_)[0] ^ ((const uint64_t*)&D_)[0]; \ + ((uint64_t*)&Res)[1] = ((const uint64_t*)&A_)[1] ^ ((const uint64_t*)&B_)[1] ^ ((const uint64_t*)&C_)[1] ^ ((const uint64_t*)&D_)[1]; \ + ((uint64_t*)&Res)[2] = ((const uint64_t*)&A_)[2] ^ ((const uint64_t*)&B_)[2] ^ ((const uint64_t*)&C_)[2] ^ ((const uint64_t*)&D_)[2]; \ + ((uint64_t*)&Res)[3] = ((const uint64_t*)&A_)[3] ^ ((const uint64_t*)&B_)[3] ^ ((const uint64_t*)&C_)[3] ^ ((const uint64_t*)&D_)[3]; typedef uint64_t state_t_m[25]; typedef uint64_t mixin_t[KK_MIXIN_SIZE]; diff --git a/tests/performance_tests/keccak_test.h b/tests/performance_tests/keccak_test.h index 668a9873..14d0bdf3 100644 --- a/tests/performance_tests/keccak_test.h +++ b/tests/performance_tests/keccak_test.h @@ -111,7 +111,7 @@ public: #define SCR_I(i) m_scratchpad_vec[st[i]%m_scratchpad_vec.size()] for (size_t i = 0; i != 6; i++) { - *(crypto::hash*)&mix[i * 4] = XOR_4(SCR_I(i * 4), SCR_I(i * 4 + 1), SCR_I(i * 4 + 2), SCR_I(i * 4 + 3)); + OPT_XOR_4_RES(SCR_I(i * 4), SCR_I(i * 4 + 1), SCR_I(i * 4 + 2), SCR_I(i * 4 + 3), *(crypto::hash*)&mix[i * 4]); } }); @@ -177,7 +177,7 @@ void measure_keccak_over_scratchpad() crypto::hash res_to_test = { 0 }; crypto::hash res_etalon = { 0 }; OPT_XOR_4_RES(scratchpad_vec[0], scratchpad_vec[1], scratchpad_vec[2], scratchpad_vec[3], res_to_test); - res_etalon = XOR_4(scratchpad_vec[0], scratchpad_vec[1], scratchpad_vec[2], scratchpad_vec[3]); + OPT_XOR_4_RES(scratchpad_vec[0], scratchpad_vec[1], scratchpad_vec[2], scratchpad_vec[3], res_etalon); // @@ -222,7 +222,7 @@ void measure_keccak_over_scratchpad() uint64_t ticks_d = epee::misc_utils::get_tick_count(); for (size_t r = 0; r != measere_rounds; r++) { - crypto::get_wild_keccak2(has_str, res_h, 1, scratchpad_vec, i); + crypto::get_wild_keccak2(has_str, res_h, scratchpad_vec, i); } uint64_t ticks_e = epee::misc_utils::get_tick_count(); From e477762c14f2c43f1bbb10e81b95ebacb0cdf3ac Mon Sep 17 00:00:00 2001 From: alfredmox <> Date: Tue, 22 Jan 2019 12:43:38 -0800 Subject: [PATCH 3/3] unique name workaround --- src/crypto/wild_keccak.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/crypto/wild_keccak.h b/src/crypto/wild_keccak.h index f7abaf0c..f9fd7e32 100644 --- a/src/crypto/wild_keccak.h +++ b/src/crypto/wild_keccak.h @@ -29,11 +29,16 @@ extern "C" { namespace crypto { +#define CONCAT_IMPL(x, y) x##y +#define CONCAT(x, y) CONCAT_IMPL(x, y) +#define UNIQUE(x) CONCAT(x, __LINE__) + #define OPT_XOR_4_RES(A_, B_, C_, D_, Res) \ - ((uint64_t*)&Res)[0] = ((const uint64_t*)&A_)[0] ^ ((const uint64_t*)&B_)[0] ^ ((const uint64_t*)&C_)[0] ^ ((const uint64_t*)&D_)[0]; \ - ((uint64_t*)&Res)[1] = ((const uint64_t*)&A_)[1] ^ ((const uint64_t*)&B_)[1] ^ ((const uint64_t*)&C_)[1] ^ ((const uint64_t*)&D_)[1]; \ - ((uint64_t*)&Res)[2] = ((const uint64_t*)&A_)[2] ^ ((const uint64_t*)&B_)[2] ^ ((const uint64_t*)&C_)[2] ^ ((const uint64_t*)&D_)[2]; \ - ((uint64_t*)&Res)[3] = ((const uint64_t*)&A_)[3] ^ ((const uint64_t*)&B_)[3] ^ ((const uint64_t*)&C_)[3] ^ ((const uint64_t*)&D_)[3]; + crypto::hash UNIQUE(A) = A_;crypto::hash UNIQUE(B) = B_;crypto::hash UNIQUE(C) = C_; crypto::hash UNIQUE(D) = D_; \ + ((uint64_t*)&Res)[0] = ((const uint64_t*)&UNIQUE(A))[0] ^ ((const uint64_t*)&UNIQUE(B))[0] ^ ((const uint64_t*)&UNIQUE(C))[0] ^ ((const uint64_t*)&UNIQUE(D))[0]; \ + ((uint64_t*)&Res)[1] = ((const uint64_t*)&UNIQUE(A))[1] ^ ((const uint64_t*)&UNIQUE(B))[1] ^ ((const uint64_t*)&UNIQUE(C))[1] ^ ((const uint64_t*)&UNIQUE(D))[1]; \ + ((uint64_t*)&Res)[2] = ((const uint64_t*)&UNIQUE(A))[2] ^ ((const uint64_t*)&UNIQUE(B))[2] ^ ((const uint64_t*)&UNIQUE(C))[2] ^ ((const uint64_t*)&UNIQUE(D))[2]; \ + ((uint64_t*)&Res)[3] = ((const uint64_t*)&UNIQUE(A))[3] ^ ((const uint64_t*)&UNIQUE(B))[3] ^ ((const uint64_t*)&UNIQUE(C))[3] ^ ((const uint64_t*)&UNIQUE(D))[3]; typedef uint64_t state_t_m[25]; typedef uint64_t mixin_t[KK_MIXIN_SIZE];