From ebf5486513a605b4d3006ae849fefeb271d7e9a6 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 28 Apr 2021 07:00:32 +0300 Subject: [PATCH 1/8] 1) test_chain_unit_enchanced::check_hardfork_active implemented, 2) core runtime config minor improvement --- src/currency_core/core_runtime_config.h | 12 ++++++++++++ tests/core_tests/chaingen.cpp | 18 ++++++++++++++++++ tests/core_tests/chaingen.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/src/currency_core/core_runtime_config.h b/src/currency_core/core_runtime_config.h index 1f8302a5..a2bbe84d 100644 --- a/src/currency_core/core_runtime_config.h +++ b/src/currency_core/core_runtime_config.h @@ -26,6 +26,18 @@ namespace currency uint64_t hard_fork_02_starts_after_height; uint64_t hard_fork_03_starts_after_height; + bool is_hardfork_active_for_height(size_t hardfork_id, uint64_t height) const + { + switch (hardfork_id) + { + case 0: return true; + case 1: return height > hard_fork_01_starts_after_height; + case 2: return height > hard_fork_02_starts_after_height; + case 3: return height > hard_fork_03_starts_after_height; + default: return false; + } + } + static uint64_t _default_core_time_function() { return time(NULL); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index bbd61e4c..dd74c3cf 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -2099,6 +2099,7 @@ test_chain_unit_enchanced::test_chain_unit_enchanced() REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, print_tx_pool); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, remove_stuck_txs); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_offers_count); + REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_hardfork_active); } bool test_chain_unit_enchanced::configure_core(currency::core& c, size_t ev_index, const std::vector& events) @@ -2118,6 +2119,7 @@ void test_chain_unit_enchanced::set_hard_fork_heights_to_generator(test_generato { generator.set_hardfork_height(1, m_hardfork_01_height); generator.set_hardfork_height(2, m_hardfork_02_height); + generator.set_hardfork_height(3, m_hardfork_03_height); } bool test_chain_unit_enchanced::check_top_block(currency::core& c, size_t ev_index, const std::vector& events) @@ -2232,3 +2234,19 @@ bool test_chain_unit_enchanced::check_offers_count(currency::core& c, size_t ev_ return true; } + +bool test_chain_unit_enchanced::check_hardfork_active(currency::core& c, size_t ev_index, const std::vector& events) +{ + size_t hardfork_id_to_check = 0; + const std::string& params = boost::get(events[ev_index]).callback_params; + CHECK_AND_ASSERT_MES(epee::string_tools::hex_to_pod(params, hardfork_id_to_check), false, "hex_to_pod failed, params = " << params); + + uint64_t top_block_height = c.get_top_block_height(); + if (!c.get_blockchain_storage().get_core_runtime_config().is_hardfork_active_for_height(hardfork_id_to_check, top_block_height)) + { + LOG_ERROR("Hardfork #" << hardfork_id_to_check << " is not active yet (top block height is " << top_block_height << ")"); + return false; + } + + return true; +} diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index bcb04550..8ccec794 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -308,6 +308,7 @@ public: bool print_tx_pool(currency::core& c, size_t ev_index, const std::vector& events); bool remove_stuck_txs(currency::core& c, size_t ev_index, const std::vector& events); bool check_offers_count(currency::core& c, size_t ev_index, const std::vector& events); + bool check_hardfork_active(currency::core& c, size_t ev_index, const std::vector& events); protected: struct params_top_block @@ -322,6 +323,7 @@ protected: size_t m_unverifiable_tx_index; size_t m_orphan_block_index; + // the following members is intended to be set by coretests with specific HF-related needs uint64_t m_hardfork_01_height; uint64_t m_hardfork_02_height; uint64_t m_hardfork_03_height; From 85e46999c2fb3c3b09c84e98b5fca4f41a85d4d0 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 28 Apr 2021 07:01:47 +0300 Subject: [PATCH 2/8] coretests: 1) many hardfork 1 tests fixed to more correctly check HF status, 2) hard_fork_1_pos_and_locked_coins re-enabled --- tests/core_tests/chaingen_main.cpp | 2 +- tests/core_tests/hard_fork_1.cpp | 47 +++++++++++++++++------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index f4c22914..1f21fce7 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1007,7 +1007,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(hard_fork_1_chain_switch_pow_only); GENERATE_AND_PLAY(hard_fork_1_checkpoint_basic_test); GENERATE_AND_PLAY(hard_fork_1_pos_locked_height_vs_time); - //GENERATE_AND_PLAY(hard_fork_1_pos_and_locked_coins); + GENERATE_AND_PLAY(hard_fork_1_pos_and_locked_coins); diff --git a/tests/core_tests/hard_fork_1.cpp b/tests/core_tests/hard_fork_1.cpp index 21715e4f..c4083254 100644 --- a/tests/core_tests/hard_fork_1.cpp +++ b/tests/core_tests/hard_fork_1.cpp @@ -113,8 +113,8 @@ bool hard_fork_1_unlock_time_2_in_normal_tx::generate(std::vector(1)); // // after hardfork 1 @@ -218,8 +218,8 @@ bool hard_fork_1_unlock_time_2_in_coinbase::generate(std::vector(1)); // after hardfork 1 @@ -279,8 +279,8 @@ bool hard_fork_1_chain_switch_pow_only::generate(std::vector& MAKE_NEXT_BLOCK(events, blk_3a, blk_2a, miner_acc); // hardfork should happen here MAKE_NEXT_BLOCK(events, blk_4a, blk_3a, miner_acc); // make sure hardfork went okay - CHECK_AND_ASSERT_MES(blk_3a.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4a.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected"); - + CHECK_AND_ASSERT_MES(blk_3a.major_version != HF1_BLOCK_MAJOR_VERSION && blk_4a.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected"); + DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast(1)); // // after hardfork 1 @@ -357,7 +357,8 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector& MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc); // <-- hard fork MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_acc); // make sure hardfork went okay - CHECK_AND_ASSERT_MES(blk_3.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected"); + CHECK_AND_ASSERT_MES(blk_3.major_version != HF1_BLOCK_MAJOR_VERSION && blk_4.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected"); + DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast(1)); // // after hardfork 1 @@ -494,7 +495,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e DO_CALLBACK_PARAMS(events, "check_outputs_with_unique_amount", unique_amount_params(unique_amount_bob, 0) ); // create few locked outputs in the blockchain with unique amount - // tx_0 : miner -> Alice + // tx_0 : miner -> Alice (locked till block 100 using etc_tx_details_unlock_time) std::vector extra; etc_tx_details_unlock_time ut = AUTO_VAL_INIT(ut); ut.v = 100; // locked until block 100 @@ -509,7 +510,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_0); - // tx_1 : miner -> Bob + // tx_1 : miner -> Bob (locked till block 100 using etc_tx_details_unlock_time2) extra.clear(); uint64_t ut2_unlock_time = 100; // locked until block 100 etc_tx_details_unlock_time2 ut2 = AUTO_VAL_INIT(ut2); @@ -524,16 +525,19 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e transaction tx_1 = AUTO_VAL_INIT(tx_1); r = construct_tx_to_key(events, tx_1, blk_0r, miner_acc, destinations, TESTS_DEFAULT_FEE, 0, 0, extra); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); + DO_CALLBACK(events, "mark_invalid_tx"); events.push_back(tx_1); + // etc_tx_details_unlock_time is allowed prior to HF 1 so tx_0 should pass all the checks nicely MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); // block with tx_1 should be rejected because etc_tx_details_unlock_time2 is not allowed prior to hardfork 1 - DO_CALLBACK(events, "mark_invalid_block"); - MAKE_NEXT_BLOCK_TX1(events, blk_1b, blk_1, miner_acc, tx_1); + //DO_CALLBACK(events, "mark_invalid_block"); + //MAKE_NEXT_BLOCK_TX1(events, blk_1b, blk_1, miner_acc, tx_1); REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + // Alice should have received 5 * unique_amount_alice coins via tx_0 DO_CALLBACK_PARAMS(events, "check_outputs_with_unique_amount", unique_amount_params(unique_amount_alice, 5) ); // make sure outputs with m_unique_amount are still locked @@ -583,9 +587,9 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e MAKE_NEXT_BLOCK(events, blk_2, blk_1r, miner_acc); MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc); - // make sure hardfork went okay - CHECK_AND_ASSERT_MES(blk_2.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_3.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected"); - + // make sure hardfork 1 went okay + CHECK_AND_ASSERT_MES(blk_2.major_version != HF1_BLOCK_MAJOR_VERSION && blk_3.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected"); + DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast(1)); // try to make a PoS block with locked stake after the hardfork @@ -609,7 +613,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e pos_block_builder pb; pb.step1_init_header(height, prev_id); - pb.m_block.major_version = CURRENT_BLOCK_MAJOR_VERSION; + pb.m_block.major_version = HF1_BLOCK_MAJOR_VERSION; pb.step2_set_txs(std::vector()); pb.step3_build_stake_kernel(stake_output_amount, stake_output_gidx, stake_output_key_image, diff, prev_id, null_hash, prev_block.timestamp); pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(prev_block), miner_acc.get_public_address()); @@ -622,6 +626,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e events.push_back(blk_4b); // blk_4 with tx_1 (etc_tx_details_unlock_time2) should be accepted after hardfork 1 + events.push_back(tx_1); MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_1); block prev = blk_4; @@ -629,11 +634,13 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e { MAKE_NEXT_POS_BLOCK(events, b, prev, miner_acc, std::list{miner_acc}); prev = b; + events.push_back(event_core_time(get_actual_timestamp(b) + 100)); } //REWIND_BLOCKS_N_WITH_TIME(events, blk_4r, blk_4, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + // try to make a PoS block with the stake locked using etc_tx_details_unlock_time2 (it's still locked) block blk_5; { const block& prev_block = prev; @@ -654,7 +661,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e pos_block_builder pb; pb.step1_init_header(height, prev_id); - pb.m_block.major_version = CURRENT_BLOCK_MAJOR_VERSION; + pb.m_block.major_version = HF1_BLOCK_MAJOR_VERSION; pb.step2_set_txs(std::vector()); pb.step3_build_stake_kernel(stake_output_amount, stake_output_gidx, stake_output_key_image, diff, prev_id, null_hash, prev_block.timestamp); pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(prev_block), miner_acc.get_public_address()); @@ -666,7 +673,6 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector& e DO_CALLBACK(events, "mark_invalid_block"); events.push_back(blk_5); - return true; } @@ -726,7 +732,8 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector(1)); REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1); @@ -751,7 +758,7 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector()); pb.step3_build_stake_kernel(stake_output_amount, stake_output_gidx, stake_output_key_image, diff, prev_id, null_hash, prev_block.timestamp); pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(prev_block), miner_acc.get_public_address(), stakeholder.get_public_address()); @@ -796,7 +803,7 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector()); pb.step3_build_stake_kernel(stake_output_amount, stake_output_gidx, stake_output_key_image, diff, prev_id, null_hash, prev_block.timestamp); pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(prev_block), miner_acc.get_public_address(), stakeholder.get_public_address()); From c4abdc39df1483e5e1c9819919eba5cb97a9d2df Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 28 Apr 2021 21:26:23 +0300 Subject: [PATCH 3/8] typo fix --- src/currency_core/blockchain_storage.cpp | 4 ++-- src/currency_core/currency_config.h | 2 +- src/gui/qt-daemon/.gitignore | 2 +- tests/core_tests/chaingen.cpp | 6 +++--- tests/core_tests/pos_block_builder.cpp | 2 +- tests/functional_tests/core_concurrency_test.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index e422a446..d7926767 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1438,7 +1438,7 @@ bool blockchain_storage::create_block_template(const create_block_template_param CRITICAL_REGION_BEGIN(m_read_lock); height = m_db_blocks.size(); if(height <= m_core_runtime_config.hard_fork_01_starts_after_height) - b.major_version = BLOCK_MAJOR_VERSION_INITAL; + b.major_version = BLOCK_MAJOR_VERSION_INITIAL; else if(height <= m_core_runtime_config.hard_fork_03_starts_after_height) b.major_version = HF1_BLOCK_MAJOR_VERSION; else @@ -5770,7 +5770,7 @@ bool blockchain_storage::is_after_hardfork_3_zone(uint64_t height)const bool blockchain_storage::prevalidate_block(const block& bl) { //before hard_fork1 - if (bl.major_version == BLOCK_MAJOR_VERSION_INITAL && get_block_height(bl) <= m_core_runtime_config.hard_fork_01_starts_after_height) + if (bl.major_version == BLOCK_MAJOR_VERSION_INITIAL && get_block_height(bl) <= m_core_runtime_config.hard_fork_01_starts_after_height) return true; diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 0c43cc88..942f4e2d 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -232,7 +232,7 @@ //hard forks section #define BLOCK_MAJOR_VERSION_GENESIS 1 #define BLOCK_MINOR_VERSION_GENESIS 0 -#define BLOCK_MAJOR_VERSION_INITAL 0 +#define BLOCK_MAJOR_VERSION_INITIAL 0 #ifndef TESTNET #define ZANO_HARDFORK_01_AFTER_HEIGHT 194624 #define ZANO_HARDFORK_02_AFTER_HEIGHT 999999 diff --git a/src/gui/qt-daemon/.gitignore b/src/gui/qt-daemon/.gitignore index 8b95cebe..8a9d35c8 100644 --- a/src/gui/qt-daemon/.gitignore +++ b/src/gui/qt-daemon/.gitignore @@ -1 +1 @@ -*.user \ No newline at end of file +*.user diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index dd74c3cf..57f00b22 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -222,10 +222,10 @@ bool test_generator::construct_block(currency::block& blk, // if (height > m_hardfork_01_after_heigh) // blk.major_version = CURRENT_BLOCK_MAJOR_VERSION; // else -// blk.major_version = BLOCK_MAJOR_VERSION_INITAL; +// blk.major_version = BLOCK_MAJOR_VERSION_INITIAL; if (height <= m_hardfork_01_after_heigh) - blk.major_version = BLOCK_MAJOR_VERSION_INITAL; + blk.major_version = BLOCK_MAJOR_VERSION_INITIAL; else if (height <= m_hardfork_03_after_heigh) blk.major_version = HF1_BLOCK_MAJOR_VERSION; else @@ -878,7 +878,7 @@ bool test_generator::construct_block(int64_t manual_timestamp_adjustment, size_t txs_sizes/* = 0*/) { size_t height = get_block_height(prev_block) + 1; - blk.major_version = actual_params & bf_major_ver ? major_ver : BLOCK_MAJOR_VERSION_INITAL; + blk.major_version = actual_params & bf_major_ver ? major_ver : BLOCK_MAJOR_VERSION_INITIAL; blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION; blk.timestamp = actual_params & bf_timestamp ? timestamp : (height > 10 ? prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN: prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN-POW_DIFF_UP_TIMESTAMP_DELTA); // Keep difficulty unchanged blk.prev_id = actual_params & bf_prev_id ? prev_id : get_block_hash(prev_block); diff --git a/tests/core_tests/pos_block_builder.cpp b/tests/core_tests/pos_block_builder.cpp index 44e1b3d8..888a0d2c 100644 --- a/tests/core_tests/pos_block_builder.cpp +++ b/tests/core_tests/pos_block_builder.cpp @@ -24,7 +24,7 @@ void pos_block_builder::step1_init_header(size_t block_height, crypto::hash& pre { CHECK_AND_ASSERT_THROW_MES(m_step == 0, "pos_block_builder: incorrect step sequence"); m_block.minor_version = CURRENT_BLOCK_MINOR_VERSION; - m_block.major_version = BLOCK_MAJOR_VERSION_INITAL; + m_block.major_version = BLOCK_MAJOR_VERSION_INITIAL; m_block.timestamp = 0; // to be set at step 3 m_block.prev_id = prev_block_hash; m_block.flags = CURRENCY_BLOCK_FLAG_POS_BLOCK; diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 42dd7d9a..c2ffda19 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -46,7 +46,7 @@ typedef std::vector> cct_wallets_t; bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector& txs, const currency::account_public_address& miner_addr, currency::block& result) { result.flags = 0; - result.major_version = BLOCK_MAJOR_VERSION_INITAL; + result.major_version = BLOCK_MAJOR_VERSION_INITIAL; result.minor_version = CURRENT_BLOCK_MINOR_VERSION; result.nonce = 0; result.prev_id = get_block_hash(prev_block); From c8ba0418effa8e2833993a3e46edac17e92c7250 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 5 May 2021 06:38:07 +0300 Subject: [PATCH 4/8] crypto sugar minor improvements --- src/crypto/crypto-sugar.h | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index a064af19..fa5aaafd 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -394,7 +394,7 @@ namespace crypto friend std::ostream& operator<<(std::ostream& ss, const scalar_t &v) { - return ss << "0x" << pod_to_hex_reversed(v); + return ss << pod_to_hex(v); } std::string to_string_as_hex_number() const @@ -510,6 +510,11 @@ namespace crypto return result; } + void to_public_key(crypto::public_key& result) const + { + ge_p3_tobytes((unsigned char*)&result, &m_p3); + } + crypto::key_image to_key_image() const { crypto::key_image result; @@ -562,10 +567,17 @@ namespace crypto friend point_t operator*(const scalar_t& lhs, const point_t& rhs) { point_t result; - ge_scalarmult_p3(&result.m_p3, reinterpret_cast(&lhs), &rhs.m_p3); + ge_scalarmult_p3(&result.m_p3, lhs.m_s, &rhs.m_p3); return result; } + point_t& operator*=(const scalar_t& rhs) + { + // TODO: ge_scalarmult_vartime_p3 + ge_scalarmult_p3(&m_p3, rhs.m_s, &m_p3); + return *this; + } + friend point_t operator/(const point_t& lhs, const scalar_t& rhs) { point_t result; @@ -742,6 +754,11 @@ namespace crypto m_elements.reserve(elements_count); } + void resize(size_t elements_count) + { + m_elements.resize(elements_count); + } + void clear() { m_elements.clear(); @@ -771,6 +788,16 @@ namespace crypto m_elements.emplace_back(pk); } + scalar_t& access_scalar(size_t index) + { + return m_elements[index].scalar; + } + + public_key& access_public_key(size_t index) + { + return m_elements[index].pk; + } + void add_points_array(const std::vector& points_array) { for (size_t i = 0, size = points_array.size(); i < size; ++i) @@ -801,6 +828,7 @@ namespace crypto union item_t { + item_t() {} item_t(const scalar_t& scalar) : scalar(scalar) {} item_t(const crypto::public_key& pk) : pk(pk) {} item_t(const crypto::key_image& ki) : ki(ki) {} From 5013963e2119da4c743a818231864810c98bc213 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 7 May 2021 11:59:53 -0500 Subject: [PATCH 5/8] reset testnet --- src/currency_core/blockchain_storage.cpp | 2 +- src/currency_core/checkpoints_create.h | 2 +- src/currency_core/currency_config.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index e422a446..34e26385 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -5627,7 +5627,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt set_lost_tx_unmixable_for_height(bei.height); - LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED " << (is_pos_bl ? "[PoS]" : "[PoW]") << " Sq: " << sequence_factor + LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED " << (is_pos_bl ? "[PoS]" : "[PoW]") << "["<< static_cast(bei.bl.major_version) << "." << static_cast(bei.bl.minor_version) << "] "<< " Sq: " << sequence_factor << ENDL << "id:\t" << id << timestamp_str_entry.str() << ENDL << powpos_str_entry.str() << ENDL << "HEIGHT " << bei.height << ", difficulty: " << current_diffic << ", cumul_diff_precise: " << bei.cumulative_diff_precise << ", cumul_diff_adj: " << bei.cumulative_diff_adjusted << " (+" << cumulative_diff_delta << ")" diff --git a/src/currency_core/checkpoints_create.h b/src/currency_core/checkpoints_create.h index 9a14c2f8..ea87d78c 100644 --- a/src/currency_core/checkpoints_create.h +++ b/src/currency_core/checkpoints_create.h @@ -17,7 +17,7 @@ namespace currency inline bool create_checkpoints(currency::checkpoints& checkpoints) { #ifdef TESTNET - ADD_CHECKPOINT(50000, "492ef71f5d722a8a182d65eb0ff731b740e023a2d64881f43db9af7b39ba7988"); + //ADD_CHECKPOINT(50000, "492ef71f5d722a8a182d65eb0ff731b740e023a2d64881f43db9af7b39ba7988"); #else // MAINNET ADD_CHECKPOINT(425000, "46a6c36d5dec2d484d5e4845a8525ca322aafc06915ed9c8da2a241b51b7d1e8"); diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 0c43cc88..4f39e718 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -10,7 +10,7 @@ #ifndef TESTNET #define CURRENCY_FORMATION_VERSION 84 #else -#define CURRENCY_FORMATION_VERSION 87 +#define CURRENCY_FORMATION_VERSION 88 #endif #define CURRENCY_GENESIS_NONCE (CURRENCY_FORMATION_VERSION + 101011010121) //bender's nightmare From 182a0c59bb9d597c48c15e316846e400c4e536e1 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 11 May 2021 04:32:03 +0300 Subject: [PATCH 6/8] crypto sugar: scalar_t::reduce(), hs_t::assign_calc_hash() --- src/crypto/crypto-sugar.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index fa5aaafd..43e69c42 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -271,6 +271,11 @@ namespace crypto return sc_check(&m_s[0]) == 0; } + void reduce() + { + sc_reduce32(&m_s[0]); + } + scalar_t operator+(const scalar_t& v) const { scalar_t result; @@ -825,6 +830,16 @@ namespace crypto this->clear(); return scalar_t(hash); // this will reduce to L } + + void assign_calc_hash(scalar_t& result, bool clear = true) + { + static_assert(sizeof result == sizeof(crypto::hash), "size missmatch"); + size_t data_size_bytes = m_elements.size() * sizeof(item_t); + crypto::cn_fast_hash(m_elements.data(), data_size_bytes, (crypto::hash&)result); + result.reduce(); + if (clear) + this->clear(); + } union item_t { From e24be09046a3ec2720f72be439bcbb77f61106ae Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 11 May 2021 06:42:06 +0300 Subject: [PATCH 7/8] crypto: faster sc_invert from libsodium (my old naive one moved to the crypto_tests) --- src/crypto/crypto-ops.c | 261 ++++++------------------ tests/functional_tests/crypto_tests.cpp | 250 ++++++++++++++++++----- 2 files changed, 260 insertions(+), 251 deletions(-) diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c index 2ab08dc2..caf20a07 100644 --- a/src/crypto/crypto-ops.c +++ b/src/crypto/crypto-ops.c @@ -4110,209 +4110,66 @@ void sc_muladd(unsigned char* s, const unsigned char* a, s[31] = s11 >> 17; } - -// out = z ^ -1 (= z ^ (L - 2) according to Fermat little theorem) -void sc_invert(unsigned char* out, const unsigned char* z) +/* libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c */ +void sc_sqmul(unsigned char s[32], const int n, const unsigned char a[32]) { - memcpy(out, z, 32); - for (size_t i = 0; i < 128; ++i) - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, out); - sc_mul(out, out, z); - sc_mul(out, out, out); - sc_mul(out, out, z); + int i; + for (i = 0; i < n; ++i) + sc_mul(s, s, s); + sc_mul(s, s, a); +} + +/* libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c */ +void sc_invert(unsigned char* recip, const unsigned char* s) +{ + unsigned char _10[32], _100[32], _1000[32], _10000[32], _100000[32], + _1000000[32], _10010011[32], _10010111[32], _100110[32], _1010[32], + _1010000[32], _1010011[32], _1011[32], _10110[32], _10111101[32], + _11[32], _1100011[32], _1100111[32], _11010011[32], _1101011[32], + _11100111[32], _11101011[32], _11110101[32]; + + sc_mul(_10, s, s); + sc_mul(_11, s, _10); + sc_mul(_100, s, _11); + sc_mul(_1000, _100, _100); + sc_mul(_1010, _10, _1000); + sc_mul(_1011, s, _1010); + sc_mul(_10000, _1000, _1000); + sc_mul(_10110, _1011, _1011); + sc_mul(_100000, _1010, _10110); + sc_mul(_100110, _10000, _10110); + sc_mul(_1000000, _100000, _100000); + sc_mul(_1010000, _10000, _1000000); + sc_mul(_1010011, _11, _1010000); + sc_mul(_1100011, _10000, _1010011); + sc_mul(_1100111, _100, _1100011); + sc_mul(_1101011, _100, _1100111); + sc_mul(_10010011, _1000000, _1010011); + sc_mul(_10010111, _100, _10010011); + sc_mul(_10111101, _100110, _10010111); + sc_mul(_11010011, _10110, _10111101); + sc_mul(_11100111, _1010000, _10010111); + sc_mul(_11101011, _100, _11100111); + sc_mul(_11110101, _1010, _11101011); + + sc_mul(recip, _1011, _11110101); + + sc_sqmul(recip, 126, _1010011); + + sc_sqmul(recip, 9, _10); + sc_mul(recip, recip, _11110101); + sc_sqmul(recip, 7, _1100111); + sc_sqmul(recip, 9, _11110101); + sc_sqmul(recip, 11, _10111101); + sc_sqmul(recip, 8, _11100111); + sc_sqmul(recip, 9, _1101011); + sc_sqmul(recip, 6, _1011); + sc_sqmul(recip, 14, _10010011); + sc_sqmul(recip, 10, _1100011); + sc_sqmul(recip, 9, _10010111); + sc_sqmul(recip, 10, _11110101); + sc_sqmul(recip, 8, _11010011); + sc_sqmul(recip, 8, _11101011); } /* diff --git a/tests/functional_tests/crypto_tests.cpp b/tests/functional_tests/crypto_tests.cpp index 775e9b93..ba4313fd 100644 --- a/tests/functional_tests/crypto_tests.cpp +++ b/tests/functional_tests/crypto_tests.cpp @@ -80,56 +80,208 @@ sc_sqmul(unsigned char s[32], const int n, const unsigned char a[32]) sc_mul(s, s, a); } -void sc_invert2(unsigned char* recip, const unsigned char* s) +// out = z ^ -1 (= z ^ (L - 2) according to Fermat little theorem) +void sc_invert2(unsigned char* out, const unsigned char* z) { - unsigned char _10[32], _100[32], _1000[32], _10000[32], _100000[32], - _1000000[32], _10010011[32], _10010111[32], _100110[32], _1010[32], - _1010000[32], _1010011[32], _1011[32], _10110[32], _10111101[32], - _11[32], _1100011[32], _1100111[32], _11010011[32], _1101011[32], - _11100111[32], _11101011[32], _11110101[32]; - - sc_mul(_10, s, s); - sc_mul(_11, s, _10); - sc_mul(_100, s, _11); - sc_mul(_1000, _100, _100); - sc_mul(_1010, _10, _1000); - sc_mul(_1011, s, _1010); - sc_mul(_10000, _1000, _1000); - sc_mul(_10110, _1011, _1011); - sc_mul(_100000, _1010, _10110); - sc_mul(_100110, _10000, _10110); - sc_mul(_1000000, _100000, _100000); - sc_mul(_1010000, _10000, _1000000); - sc_mul(_1010011, _11, _1010000); - sc_mul(_1100011, _10000, _1010011); - sc_mul(_1100111, _100, _1100011); - sc_mul(_1101011, _100, _1100111); - sc_mul(_10010011, _1000000, _1010011); - sc_mul(_10010111, _100, _10010011); - sc_mul(_10111101, _100110, _10010111); - sc_mul(_11010011, _10110, _10111101); - sc_mul(_11100111, _1010000, _10010111); - sc_mul(_11101011, _100, _11100111); - sc_mul(_11110101, _1010, _11101011); - - sc_mul(recip, _1011, _11110101); - - sc_sqmul(recip, 126, _1010011); - - sc_sqmul(recip, 9, _10); - sc_mul(recip, recip, _11110101); - sc_sqmul(recip, 7, _1100111); - sc_sqmul(recip, 9, _11110101); - sc_sqmul(recip, 11, _10111101); - sc_sqmul(recip, 8, _11100111); - sc_sqmul(recip, 9, _1101011); - sc_sqmul(recip, 6, _1011); - sc_sqmul(recip, 14, _10010011); - sc_sqmul(recip, 10, _1100011); - sc_sqmul(recip, 9, _10010111); - sc_sqmul(recip, 10, _11110101); - sc_sqmul(recip, 8, _11010011); - sc_sqmul(recip, 8, _11101011); + memcpy(out, z, 32); + for (size_t i = 0; i < 128; ++i) + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, out); + sc_mul(out, out, z); + sc_mul(out, out, out); + sc_mul(out, out, z); } extern void *sha3(const void *in, size_t inlen, void *md, int mdlen); From bd9e57c6d8d82a78db26863731d8d292954ab61c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 25 May 2021 16:51:16 +0200 Subject: [PATCH 8/8] fixed subrepo(again) --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index e19aa811..0d3831a3 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit e19aa811be78b8ff3a0b622bd889b11a2685bc0c +Subproject commit 0d3831a3e4c13ab3016aca26d40d01f9e87c7282