From 1e3c0cd396a3b54f2822bcc1a3a59b743ad1c9c0 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 3 Jun 2020 13:05:49 +0300 Subject: [PATCH 01/12] coretests: random_outs_and_burnt_coins test added --- tests/core_tests/chaingen_main.cpp | 1 + tests/core_tests/get_random_outs.cpp | 127 +++++++++++++++++++++++++++ tests/core_tests/get_random_outs.h | 11 +++ 3 files changed, 139 insertions(+) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 68ff8c68..ca1be5b8 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -914,6 +914,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(get_random_outs_test); GENERATE_AND_PLAY(mix_attr_tests); GENERATE_AND_PLAY(mix_in_spent_outs); + GENERATE_AND_PLAY(random_outs_and_burnt_coins); // Block verification tests GENERATE_AND_PLAY(gen_block_big_major_version); diff --git a/tests/core_tests/get_random_outs.cpp b/tests/core_tests/get_random_outs.cpp index 2ab5f0c1..c1bf1e62 100644 --- a/tests/core_tests/get_random_outs.cpp +++ b/tests/core_tests/get_random_outs.cpp @@ -58,5 +58,132 @@ bool get_random_outs_test::check_get_rand_outs(currency::core& c, size_t ev_inde c.get_blockchain_storage().get_random_outs_for_amounts(req, res); CHECK_AND_ASSERT_MES(res.outs[0].outs.size() == 3, false, "Incorrect number of random outs returned."); + return true; +} + +//------------------------------------------------------------------------------ + +random_outs_and_burnt_coins::random_outs_and_burnt_coins() +{ + REGISTER_CALLBACK_METHOD(random_outs_and_burnt_coins, c1); +} + +bool random_outs_and_burnt_coins::generate(std::vector& events) const +{ + // Test idead: make sure burned coins (that are technically will NEVER EVER been spent) + // cannot be used for mixing in, as it reduces anonimity. + + bool r = false; + + m_accounts.resize(TOTAL_ACCS_COUNT); + account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); + account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); + account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 4); + + // find unique amount and store it to m_amount + uint64_t stub; + r = calculate_amounts_many_outs_have_and_no_outs_have(get_outs_money_amount(blk_0r.miner_tx), stub, m_amount); + CHECK_AND_ASSERT_MES(r, false, "calculate_amounts_many_outs_have_and_no_outs_have failed"); + + // prepare fake outputs and burn it + // make m_fake_amounts_count outputs each of amount amount_no_outs_have + std::vector destinations; + for(size_t i = 0; i < m_fake_amounts_count; ++i) + destinations.push_back(tx_destination_entry(m_amount, null_pub_addr)); + std::vector sources; + + r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), m_amount * m_fake_amounts_count + TESTS_DEFAULT_FEE, 0); + CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); + + transaction tx_0 = AUTO_VAL_INIT(tx_0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, 0); + CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); + + uint64_t burned_tx_amount_total = get_burned_amount(tx_0); + CHECK_AND_ASSERT_MES(burned_tx_amount_total == m_fake_amounts_count * m_amount, false, "incorrect value of burned amount: " << burned_tx_amount_total << ", expected: " << m_fake_amounts_count * m_amount); + + events.push_back(tx_0); + + // send to Alice amount_no_outs_have coins + MAKE_TX(events, tx_1, miner_acc, alice_acc, m_amount, blk_0r); + + MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, std::list({tx_0, tx_1})); + + MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); + + DO_CALLBACK(events, "c1"); + + return true; +} + +bool random_outs_and_burnt_coins::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]); + std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); + std::shared_ptr bob_wlt = init_playtime_test_wallet(events, c, m_accounts[BOB_ACC_IDX]); + + bool r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, + m_amount, // expected total + false, + CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 6 + WALLET_DEFAULT_TX_SPENDABLE_AGE, + m_amount // expected unlocked + ), false, ""); + + std::vector destinations({tx_destination_entry(m_amount - TESTS_DEFAULT_FEE, m_accounts[BOB_ACC_IDX].get_public_address())}); + + // make sure it's impossible to mixin an output with m_amount amount (because each one is burned) + for (uint64_t fake_outs = m_fake_amounts_count + 1; fake_outs > 0; --fake_outs) + { + LOG_PRINT_L0("trying transfer with fake_outs = " << fake_outs); + r = false; + try + { + alice_wlt->transfer(destinations, fake_outs, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment); + } + catch (tools::error::not_enough_outs_to_mix&) + { + r = true; + } + CHECK_AND_ASSERT_MES(r, false, "exception was not cought as expected for fake_outs = " << fake_outs); + } + + + // make normal output with m_amount amount and try to use it as mixin + miner_wlt->refresh(); + miner_wlt->transfer(m_amount, m_accounts[BOB_ACC_IDX].get_public_address()); + + // miner few blocks to make it mixable + r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + alice_wlt->refresh(); + + // try with 2 fake outputs -- should not work, as we've just added to the blockchain only one + r = false; + try + { + alice_wlt->transfer(destinations, 2 /* fake outs count */, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment); + } + catch (tools::error::not_enough_outs_to_mix&) + { + r = true; + } + CHECK_AND_ASSERT_MES(r, false, "exception was not cought as expected"); + + // one mixin should perfectly work + alice_wlt->transfer(destinations, 1 /* fake outs count */, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment); + + // check Bob's balance + CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, m_amount * 2 - TESTS_DEFAULT_FEE, false, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 6 + WALLET_DEFAULT_TX_SPENDABLE_AGE * 2), false, ""); + + return true; } diff --git a/tests/core_tests/get_random_outs.h b/tests/core_tests/get_random_outs.h index 0f7c91ec..15151edb 100644 --- a/tests/core_tests/get_random_outs.h +++ b/tests/core_tests/get_random_outs.h @@ -6,6 +6,7 @@ #pragma once #include "chaingen.h" +#include "wallet_tests_basic.h" struct get_random_outs_test : public test_chain_unit_enchanced { @@ -16,3 +17,13 @@ struct get_random_outs_test : public test_chain_unit_enchanced private: mutable uint64_t m_amount; }; + +struct random_outs_and_burnt_coins : public wallet_test +{ + random_outs_and_burnt_coins(); + bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector& events); + + mutable uint64_t m_amount; + static constexpr uint64_t m_fake_amounts_count = 3; +}; From eb8b3f30b730639f58052d4751c9bb015558bf1c Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 3 Jun 2020 13:09:43 +0300 Subject: [PATCH 02/12] do not use burned coins for mixing in (anonymity improvement) --- src/currency_core/blockchain_storage.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 253d1f6e..d05a21b1 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2363,6 +2363,7 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU const transaction& tx = tx_ptr->tx; CHECK_AND_ASSERT_MES(tx.vout[out_ptr->out_no].target.type() == typeid(txout_to_key), false, "unknown tx out type"); + const txout_to_key& otk = boost::get(tx.vout[out_ptr->out_no].target); CHECK_AND_ASSERT_MES(tx_ptr->m_spent_flags.size() == tx.vout.size(), false, "internal error"); @@ -2370,12 +2371,16 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU if (tx_ptr->m_spent_flags[out_ptr->out_no]) return false; + // do not use burned coins + if (otk.key == null_pkey) + return false; + //check if transaction is unlocked if (!is_tx_spendtime_unlocked(get_tx_unlock_time(tx, out_ptr->out_no))) return false; //use appropriate mix_attr out - uint8_t mix_attr = boost::get(tx.vout[out_ptr->out_no].target).mix_attr; + uint8_t mix_attr = otk.mix_attr; if(mix_attr == CURRENCY_TO_KEY_OUT_FORCED_NO_MIX) return false; //COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS call means that ring signature will have more than one entry. @@ -2387,7 +2392,7 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry& oen = *result_outs.outs.insert(result_outs.outs.end(), COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry()); oen.global_amount_index = i; - oen.out_key = boost::get(tx.vout[out_ptr->out_no].target).key; + oen.out_key = otk.key; return true; } //------------------------------------------------------------------ From 9c9d60d33962926a37dcde9f0e34e5a8c652c0e9 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 23 Apr 2020 17:33:15 +0300 Subject: [PATCH 03/12] get rid of obsolete function argument modifier --- contrib/epee/include/file_io_utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/epee/include/file_io_utils.h b/contrib/epee/include/file_io_utils.h index 3e850493..7ece78b1 100644 --- a/contrib/epee/include/file_io_utils.h +++ b/contrib/epee/include/file_io_utils.h @@ -79,7 +79,7 @@ namespace file_io_utils #ifdef BOOST_LEXICAL_CAST_INCLUDED inline - bool get_not_used_filename(const std::string& folder, OUT std::string& result_name) + bool get_not_used_filename(const std::string& folder, std::string& result_name) { DWORD folder_attr = ::GetFileAttributesA(folder.c_str()); if(folder_attr == INVALID_FILE_ATTRIBUTES) @@ -359,7 +359,7 @@ namespace file_io_utils } */ inline - bool get_file_time(const std::string& path_to_file, OUT time_t& ft) + bool get_file_time(const std::string& path_to_file, time_t& ft) { boost::system::error_code ec; ft = boost::filesystem::last_write_time(epee::string_encoding::utf8_to_wstring(path_to_file), ec); @@ -538,7 +538,7 @@ namespace file_io_utils } */ #ifdef WINDOWS_PLATFORM - inline bool get_folder_content(const std::string& path, std::list& OUT target_list) + inline bool get_folder_content(const std::string& path, std::list& target_list) { WIN32_FIND_DATAA find_data = {0}; HANDLE hfind = ::FindFirstFileA((path + "\\*.*").c_str(), &find_data); @@ -556,7 +556,7 @@ namespace file_io_utils return true; } #endif - inline bool get_folder_content(const std::string& path, std::list& OUT target_list, bool only_files = false) + inline bool get_folder_content(const std::string& path, std::list& target_list, bool only_files = false) { try { From 12af2a9c3038ec418a1295ac8ca53417ef92ed63 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 3 Jun 2020 19:10:26 +0300 Subject: [PATCH 04/12] win build: all pdbs now go along with installer and zip-archive --- utils/build_script_windows.bat | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index 9238a5aa..b83def07 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -91,11 +91,8 @@ echo '%version%' set build_zip_filename=%ACHIVE_NAME_PREFIX%%version%.zip set build_zip_path=%BUILDS_PATH%\builds\%build_zip_filename% -set pdbs_zip_filename=%ACHIVE_NAME_PREFIX%%version%_pdbs.zip -set pdbs_zip_path=%BUILDS_PATH%\builds\%pdbs_zip_filename% del /F /Q %build_zip_path% -del /F /Q %pdbs_zip_path% cd src\release @@ -109,13 +106,12 @@ mkdir bunch copy /Y Zano.exe bunch copy /Y zanod.exe bunch copy /Y simplewallet.exe bunch +copy /Y *.pdb bunch %QT_PREFIX_PATH%\bin\windeployqt.exe bunch\Zano.exe cd bunch -zip -9 %pdbs_zip_path% ..\*.pdb - zip -r %build_zip_path% *.* IF %ERRORLEVEL% NEQ 0 ( goto error @@ -196,14 +192,7 @@ IF %ERRORLEVEL% NEQ 0 ( ) call :sha256 %build_zip_path% build_zip_checksum -pscp -load zano_build_server %pdbs_zip_path% build.zano.org:/var/www/html/builds -IF %ERRORLEVEL% NEQ 0 ( - @echo "FAILED TO UPLOAD PDBS TO SERVER" - goto error -) -call :sha256 %pdbs_zip_path% pdbs_zip_path_checksum - -set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: http://build.zano.org:8081/builds/%installer_file%
sha256: %installer_checksum%

ZIP: http://build.zano.org:8081/builds/%build_zip_filename%
sha256: %build_zip_checksum%
PDBs: http://build.zano.org:8081/builds/%pdbs_zip_filename%
sha256: %pdbs_zip_path_checksum%" +set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: http://build.zano.org:8081/builds/%installer_file%
sha256: %installer_checksum%

ZIP: http://build.zano.org:8081/builds/%build_zip_filename%
sha256: %build_zip_checksum%
" echo %mail_msg% From c638a8b2f625b5026ffeb8339bd330c84a0c61ce Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 8 Jun 2020 11:49:20 +0300 Subject: [PATCH 05/12] plain wallet API: minor fixes --- src/wallet/plain_wallet_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 1073919a..04f6b4e1 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -345,8 +345,8 @@ namespace plain_wallet //lazy to make struct for it std::stringstream res; res << "{ \"valid\": " << (valid?"true":"false") << ", \"auditable\": " - << (apa.flags&ACCOUNT_PUBLIC_ADDRESS_FLAG_AUDITABLE ? "true" : "false") - << ",\"payment_is\": " << (pid.size() ? "true" : "false") << "}"; + << (apa.is_auditable() ? "true" : "false") + << ",\"payment_id\": " << (pid.size() ? "true" : "false") << "}"; return res.str(); } From 1db364fbf63733004e61c5552168e44f1a8c0033 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 8 Jun 2020 18:05:32 +0300 Subject: [PATCH 06/12] minor log improvement --- src/currency_core/blockchain_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index b196fbee..51589fe9 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -5155,7 +5155,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt TIME_MEASURE_START_PD(tx_append_time); if(!add_transaction_from_block(tx, tx_id, id, current_bc_size, actual_timestamp)) { - LOG_PRINT_L0("Block with id: " << id << " failed to add transaction to blockchain storage"); + LOG_PRINT_L0("Block " << id << " contains tx " << tx_id << " that can't be added to the blockchain storage"); if (taken_from_pool) { currency::tx_verification_context tvc = AUTO_VAL_INIT(tvc); From 36eabb916b95c7db06bdfb5d34d9820bd94b82df Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 9 Jun 2020 15:15:48 +0300 Subject: [PATCH 07/12] predownload files updated for testnet up to height 349999 --- src/common/pre_download.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/pre_download.h b/src/common/pre_download.h index 29c0a269..e333b294 100644 --- a/src/common/pre_download.h +++ b/src/common/pre_download.h @@ -24,8 +24,8 @@ namespace tools static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.43.225/pre-download/zano_lmdb_94_524999.pak", "ac46a4932813e28fe11ec160a2be4e48c961dce701ecace5133184cff2754d3d", 747173581, 1087696896 }; static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.43.225/pre-download/zano_mdbx_94_524999.pak", "b195fdc1bda7173469db0b313f2ead2dbda1788639ba0aedb7001a6cc640fc47", 561335640, 1342156800 }; #else - static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.43.225/pre-download/zano_testnet_lmdb_96_99000.pak", "9e8522b287ac7637ca770970542e94702f9fbaa267633cfcaeee4383dfe15bd0", 83851119, 131493888 }; - static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.43.225/pre-download/zano_testnet_mdbx_96_99000.pak", "de33646711f2276e5b22db5741d7b2bf6a8e4c4231d393b730f9a4fce1d7ec03", 63257747, 268431360 }; + static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.43.225/pre-download/zano_testnet_lmdb_96_349999.pak", "300a52c4c681f3d01f9d52eaca0461397a13d5507fc56438e18c3dfcb9459ebb", 345490545, 506789888 }; + static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.43.225/pre-download/zano_testnet_mdbx_96_349999.pak", "0a3e56e915fde6b0b656014909f91726489f9478b04d39d7f4ac30fd49732909", 253066780, 536862720 }; #endif static constexpr uint64_t pre_download_min_size_difference = 512 * 1024 * 1024; // minimum difference in size between local DB and the downloadable one to start downloading From a95316bfb7a11f3b4a260a0f00f1d5dd0e7d745a Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 10 Jun 2020 19:31:05 +0300 Subject: [PATCH 08/12] coretests: hard_fork_2_alias_update_using_old_tx added, exposes a bug --- tests/core_tests/chaingen_main.cpp | 2 + tests/core_tests/hard_fork_2.cpp | 128 +++++++++++++++++++++++++++++ tests/core_tests/hard_fork_2.h | 16 +++- 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index e7a0b10f..891992c2 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1007,6 +1007,8 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(hard_fork_2_no_new_structures_before_hf); GENERATE_AND_PLAY(hard_fork_2_awo_wallets_basic_test); GENERATE_AND_PLAY(hard_fork_2_awo_wallets_basic_test); + GENERATE_AND_PLAY(hard_fork_2_alias_update_using_old_tx); + GENERATE_AND_PLAY(hard_fork_2_alias_update_using_old_tx); // GENERATE_AND_PLAY(gen_block_reward); diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index 20aecd80..173b3ce2 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -1114,3 +1114,131 @@ template hard_fork_2_awo_wallets_basic_test::hard_fork_2_awo_wallets_basi template bool hard_fork_2_awo_wallets_basic_test::generate(std::vector& events) const; template hard_fork_2_awo_wallets_basic_test::hard_fork_2_awo_wallets_basic_test(); template bool hard_fork_2_awo_wallets_basic_test::generate(std::vector& events) const; + + +//------------------------------------------------------------------------------ + + +template +hard_fork_2_alias_update_using_old_tx::hard_fork_2_alias_update_using_old_tx() + : hard_fork_2_base_test(before_hf_2 ? 100 : 3) +{ + REGISTER_CALLBACK_METHOD(hard_fork_2_alias_update_using_old_tx, c1); + + random_state_test_restorer::reset_random(0); // deterministic test +} + +template +bool hard_fork_2_alias_update_using_old_tx::generate(std::vector& events) const +{ + // Test idea: make sure that if old, pre-auditable and pre-HF2 code updates an alias is it correctly handled by the most most recent code + // TODO: difficult to support, we need to implement it another way + + bool r = false; + uint64_t ts = 1591713000; + test_core_time::adjust(ts); + + m_accounts.resize(TOTAL_ACCS_COUNT); + account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); // miner_acc.restore_from_braindata("use use use use use use use use use use use use use use use use use use use use use use use use out"); + miner_acc.set_createtime(ts); + account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); // alice_acc.restore_from_braindata("any any any any any any any any any any any any any any any any any any any any any any any any out"); + alice_acc.set_createtime(ts); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); + set_hard_fork_heights_to_generator(generator); + DO_CALLBACK(events, "configure_core"); + events.push_back(event_core_time(ts)); + + REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + + transaction tx_0 = AUTO_VAL_INIT(tx_0); + r = construct_tx_with_many_outputs(events, blk_0r, miner_acc.get_keys(), alice_acc.get_public_address(), MK_TEST_COINS(110), 10, TESTS_DEFAULT_FEE, tx_0); + CHECK_AND_ASSERT_MES(r, false, "construct_tx_with_many_outputs failed"); + events.push_back(tx_0); + + MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); + + REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, WALLET_DEFAULT_TX_SPENDABLE_AGE); + + DO_CALLBACK(events, "c1"); + + return true; +} + +template +bool hard_fork_2_alias_update_using_old_tx::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + bool r = false, stub_bool = false; + + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX); + std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); + + CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(110), false, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE), false, ""); + + extra_alias_entry ai = AUTO_VAL_INIT(ai); + ai.m_alias = "alicealice"; + ai.m_address = m_accounts[ALICE_ACC_IDX].get_public_address(); + uint64_t alias_reward = get_alias_coast_from_fee(ai.m_alias, TESTS_DEFAULT_FEE); + transaction res_tx = AUTO_VAL_INIT(res_tx); + alice_wlt->request_alias_registration(ai, res_tx, TESTS_DEFAULT_FEE, alias_reward); + + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + + + // make sure the aliase registration is correct + extra_alias_entry_base eaeb = AUTO_VAL_INIT(eaeb); + r = c.get_blockchain_storage().get_alias_info("alicealice", eaeb); + CHECK_AND_ASSERT_MES(r && eaeb.m_address == m_accounts[ALICE_ACC_IDX].get_public_address(), false, "aliase check failed: alicealice"); + + extra_alias_entry ai_upd = ai; + + // update alias, change comment and address + ai_upd.m_text_comment = "Hello miner!"; + ai_upd.m_address = m_accounts[MINER_ACC_IDX].get_public_address(); + + + /* + // + // Send tx and print it's blob + // this code was used to generate old-style tx in develop branch, commit 36eabb916b95c7db06bdfb5d34d9820bd94b82df + // + transaction tx_upd = AUTO_VAL_INIT(tx_upd); + alice_wlt->request_alias_update(ai_upd, tx_upd, TESTS_DEFAULT_FEE, 0); + std::string tx_upd_hex = epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx_upd)); + LOG_PRINT_L0("tx upd: " << ENDL << tx_upd_hex); + */ + + + // use prepared tx blob + std::string tx_upd_hex("01010180988be49903011a0100000000000000ff593921b61d52e818058ef881764383fe9fb0cf4512da460daf477e3a216144000180d0dbc3f402037c2e68e9c60914d369dc53fcc91522dcec284e1b7c1604ccc3d8fcf67e2da0790003140a616c696365616c696365efdcf084d7af59e0d68e8bda3ff4514a02d812ccfd6a09f69811c5a6a1b035c9b1b2395fcd84283d02e2fc4f37395ac9d8f01ff3f1ad1b94a26aaf1c76bb39d00c48656c6c6f206d696e657221000118faf7b79730fd6c1ec5c918891e264e959749a0d8eebc7997b503bd185ef100fd9e0150c175e0f048ee729137ceed035e9145d7857eae9ab786dd319fe6520b16b0cc0d6a8766cd098fe5a42875243789cc3b4bf66ee0c12ff6ef2fc179d4cef50b0288360101f3012451b07e58e742c020d68e8ff6db2905fa3aad78806ba80b16f3c861ee09f79817ea1ec36b0e30c7be5412daf59bcbc34410461a0d126de4a2dd897ecf0200"); + std::string tx_upd_blob; + r = epee::string_tools::parse_hexstr_to_binbuff(tx_upd_hex, tx_upd_blob); + CHECK_AND_ASSERT_MES(r, false, "parse_hexstr_to_binbuff failed"); + //r = t_unserializable_object_from_blob(tx_upd, tx_upd_blob); + //CHECK_AND_ASSERT_MES(r, false, "t_unserializable_object_from_blob failed"); + tx_verification_context tvc = AUTO_VAL_INIT(tvc); + r = c.handle_incoming_tx(tx_upd_blob, tvc, false); + CHECK_AND_ASSERT_MES(r, false, "handle_incoming_tx failed"); + + + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + + // make sure the aliase registration is correct + eaeb = AUTO_VAL_INIT(eaeb); + r = c.get_blockchain_storage().get_alias_info("alicealice", eaeb); + CHECK_AND_ASSERT_MES(r && eaeb.m_address == m_accounts[MINER_ACC_IDX].get_public_address() && eaeb.m_text_comment == ai_upd.m_text_comment, false, "updated alias check failed: alicealice"); + + return true; +} + +template hard_fork_2_alias_update_using_old_tx::hard_fork_2_alias_update_using_old_tx(); +template bool hard_fork_2_alias_update_using_old_tx::generate(std::vector& events) const; +template hard_fork_2_alias_update_using_old_tx::hard_fork_2_alias_update_using_old_tx(); +template bool hard_fork_2_alias_update_using_old_tx::generate(std::vector& events) const; diff --git a/tests/core_tests/hard_fork_2.h b/tests/core_tests/hard_fork_2.h index 7b710603..ae9952f7 100644 --- a/tests/core_tests/hard_fork_2.h +++ b/tests/core_tests/hard_fork_2.h @@ -5,6 +5,7 @@ #include "chaingen.h" #include "wallet_tests_basic.h" +#include "random_helper.h" struct hard_fork_2_base_test : virtual public test_chain_unit_enchanced { @@ -60,9 +61,20 @@ struct hard_fork_2_no_new_structures_before_hf : public wallet_test, public hard template struct hard_fork_2_awo_wallets_basic_test : public wallet_test, public hard_fork_2_base_test { - //using hard_fork_2_base_test::check_block_verification_context; // this is necessary for correct work of do_check_block_verification_context, consider rafactoring - hard_fork_2_awo_wallets_basic_test(); bool generate(std::vector& events) const; bool c1(currency::core& c, size_t ev_index, const std::vector& events); }; + +template +struct hard_fork_2_alias_update_using_old_tx : public wallet_test, public hard_fork_2_base_test +{ + //using hard_fork_2_base_test::check_block_verification_context; // this is necessary for correct work of do_check_block_verification_context, consider rafactoring + + hard_fork_2_alias_update_using_old_tx(); + bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector& events); + + random_state_test_restorer m_random_state_restorer; +}; + From 02cd60e85d7641889f51b592bf7f67d0703fa6fb Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 10 Jun 2020 19:52:39 +0300 Subject: [PATCH 09/12] fix alias update signature buffer for upcoming auditable wallets and hf2 --- src/currency_core/currency_format_utils.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index d51b7821..d2e0d2e2 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -419,15 +419,10 @@ namespace currency //--------------------------------------------------------------- crypto::hash get_sign_buff_hash_for_alias_update(const extra_alias_entry& ai) { - const extra_alias_entry* pale = &ai; - extra_alias_entry eae_local = AUTO_VAL_INIT(eae_local); - if (ai.m_sign.size()) - { - eae_local = ai; - eae_local.m_sign.clear(); - pale = &eae_local; - } - return get_object_hash(*pale); + extra_alias_entry_old ai_old = ai.to_old(); + if (ai_old.m_sign.size()) + ai_old.m_sign.clear(); + return get_object_hash(ai_old); } //--------------------------------------------------------------- struct tx_extra_handler : public boost::static_visitor From 8b2e15b1b058740dded87623f7751c6ef7348c22 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 11 Jun 2020 13:25:58 +0300 Subject: [PATCH 10/12] === build number: 87 -> 88 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index a6b10969..1c7f58b7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "6" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 87 +#define PROJECT_VERSION_BUILD_NO 88 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 1fcaccf61b7bc649d89c3cd2fda60a8b94c6debb Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 11 Jun 2020 22:20:00 +0300 Subject: [PATCH 11/12] fix for #152 --- src/wallet/wallet2.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 93070875..cd7e22f4 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -556,7 +556,11 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i if (wti.remote_addresses.empty()) { handle_2_alternative_types_in_variant_container(decrypted_att, [&](const tx_receiver& p) { - std::string addr_str = currency::get_account_address_as_str(p.acc_addr); + std::string addr_str; + if (wti.payment_id.empty()) + addr_str = currency::get_account_address_as_str(p.acc_addr); + else + addr_str = currency::get_account_address_and_payment_id_as_str(p.acc_addr, wti.payment_id); // show integrated address if there's a payment id provided wti.remote_addresses.push_back(addr_str); LOG_PRINT_YELLOW("prepare_wti_decrypted_attachments, income=false, wti.amount = " << print_money_brief(wti.amount) << ", rem. addr = " << addr_str, LOG_LEVEL_0); return true; // continue iterating through the container @@ -3886,6 +3890,9 @@ void wallet2::add_sent_tx_detailed_info(const transaction& tx, const std::vector& destinations, const std::vector& selected_transfers) { + payment_id_t payment_id; + get_payment_id_from_tx(tx.attachment, payment_id); + std::vector recipients; std::unordered_set used_addresses; for (const auto& d : destinations) @@ -3893,13 +3900,13 @@ void wallet2::add_sent_tx_detailed_info(const transaction& tx, for (const auto& addr : d.addr) { if (used_addresses.insert(addr).second && addr != m_account.get_public_address()) - recipients.push_back(get_account_address_as_str(addr)); + recipients.push_back(payment_id.empty() ? get_account_address_as_str(addr) : get_account_address_and_payment_id_as_str(addr, payment_id)); } } if (!recipients.size()) { //transaction send to ourself - recipients.push_back(get_account_address_as_str(m_account.get_public_address())); + recipients.push_back(payment_id.empty() ? get_account_address_as_str(m_account.get_public_address()) : get_account_address_and_payment_id_as_str(m_account.get_public_address(), payment_id)); } add_sent_unconfirmed_tx(tx, recipients, selected_transfers, destinations); From e1ee3ffd1925114d589a2b196c782c58ef4f6510 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 12 Jun 2020 16:36:38 +0300 Subject: [PATCH 12/12] another attempt to fix #152 --- src/wallet/wallet2.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index cd7e22f4..7dd7a655 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -544,6 +544,12 @@ void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_i { PROFILE_FUNC("wallet2::prepare_wti_decrypted_attachments"); + if (!wti.payment_id.empty()) + { + LOG_ERROR("wti.payment_id is expected to be empty. Go ahead."); + } + get_payment_id_from_tx(decrypted_att, wti.payment_id); + if (wti.is_income) { account_public_address sender_address = AUTO_VAL_INIT(sender_address);