From 1e3c0cd396a3b54f2822bcc1a3a59b743ad1c9c0 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 3 Jun 2020 13:05:49 +0300 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 36eabb916b95c7db06bdfb5d34d9820bd94b82df Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 9 Jun 2020 15:15:48 +0300 Subject: [PATCH 5/5] 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