From 95dea60f414796d53f36244d82b08932735ba5fc Mon Sep 17 00:00:00 2001 From: cslashm Date: Tue, 22 May 2018 16:02:00 +0200 Subject: [PATCH 01/25] Fix PCSC discovery under Windows/MSYS Fix PCSC compilation under windows --- CMakeLists.txt | 3 +++ cmake/FindPCSC.cmake | 6 ++++++ src/device/device_ledger.cpp | 9 +++++++++ src/device/device_ledger.hpp | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1297e716..287f93bd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -452,9 +452,12 @@ link_directories(${LIBUNWIND_LIBRARY_DIRS}) # Final setup for libpcsc if (PCSC_FOUND) + message(STATUS "Using PCSC include dir at ${PCSC_INCLUDE_DIR}") add_definitions(-DHAVE_PCSC) include_directories(${PCSC_INCLUDE_DIR}) link_directories(${LIBPCSC_LIBRARY_DIRS}) +else (PCSC_FOUND) + message(STATUS "Could not find PCSC") endif() if(MSVC) diff --git a/cmake/FindPCSC.cmake b/cmake/FindPCSC.cmake index 8dd9d0e76..8332abc49 100644 --- a/cmake/FindPCSC.cmake +++ b/cmake/FindPCSC.cmake @@ -18,6 +18,9 @@ ENDIF (NOT WIN32) FIND_PATH(PCSC_INCLUDE_DIR winscard.h HINTS + IF (WIN32) + ${MSYS2_FOLDER}/mingw64/x86_64-w64-mingw32/include + ENDIF (WIN32) /usr/include/PCSC ${PC_PCSC_INCLUDEDIR} ${PC_PCSC_INCLUDE_DIRS} @@ -26,6 +29,9 @@ FIND_PATH(PCSC_INCLUDE_DIR winscard.h FIND_LIBRARY(PCSC_LIBRARY NAMES pcsclite libpcsclite WinSCard PCSC HINTS + IF (WIN32) + ${MSYS2_FOLDER}/mingw64/x86_64-w64-mingw32/lib + ENDIF (WIN32) ${PC_PCSC_LIBDIR} ${PC_PCSC_LIBRARY_DIRS} ) diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index 3b9ab6744..aedaf8382 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -48,6 +48,15 @@ namespace hw { /* ===================================================================== */ /* === Debug ==== */ /* ===================================================================== */ + #ifdef WIN32 + static char *pcsc_stringify_error(LONG rv) { + static __thread char out[20]; + sprintf_s(out, sizeof(out), "0x%08lX", rv); + + return out; + } + #endif + void set_apdu_verbose(bool verbose) { apdu_verbose = verbose; } diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp index f1fcaab87..b62bdf959 100644 --- a/src/device/device_ledger.hpp +++ b/src/device/device_ledger.hpp @@ -33,8 +33,13 @@ #include #include #include "device.hpp" +#ifdef WIN32 +#include +#define MAX_ATR_SIZE 33 +#else #include #include +#endif #include #include From 0aa0b8347e4580da5a2701ffb58d57bdd0e39f3c Mon Sep 17 00:00:00 2001 From: stoffu Date: Sun, 20 May 2018 09:40:32 +0900 Subject: [PATCH 02/25] Fix output shuffling for multisig --- src/cryptonote_core/cryptonote_tx_utils.cpp | 16 +++++++++------- src/cryptonote_core/cryptonote_tx_utils.h | 4 ++-- src/wallet/wallet2.cpp | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index c2252fcc7..071ce591e 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -195,7 +195,7 @@ namespace cryptonote return addr.m_view_public_key; } //--------------------------------------------------------------- - bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, const std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector &additional_tx_keys, bool rct, bool bulletproof, rct::multisig_out *msout) + bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector &additional_tx_keys, bool rct, bool bulletproof, rct::multisig_out *msout, bool shuffle_outs) { hw::device &hwdev = sender_account_keys.get_device(); @@ -315,9 +315,10 @@ namespace cryptonote tx.vin.push_back(input_to_key); } - // "Shuffle" outs - std::vector shuffled_dsts(destinations); - std::shuffle(shuffled_dsts.begin(), shuffled_dsts.end(), std::default_random_engine(crypto::rand())); + if (shuffle_outs) + { + std::shuffle(destinations.begin(), destinations.end(), std::default_random_engine(crypto::rand())); + } // sort ins by their key image std::vector ins_order(sources.size()); @@ -364,7 +365,7 @@ namespace cryptonote uint64_t summary_outs_money = 0; //fill outputs size_t output_index = 0; - for(const tx_destination_entry& dst_entr: shuffled_dsts) + for(const tx_destination_entry& dst_entr: destinations) { CHECK_AND_ASSERT_MES(dst_entr.amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.amount); crypto::key_derivation derivation; @@ -600,7 +601,7 @@ namespace cryptonote return true; } //--------------------------------------------------------------- - bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, const std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector &additional_tx_keys, bool rct, bool bulletproof, rct::multisig_out *msout) + bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector &additional_tx_keys, bool rct, bool bulletproof, rct::multisig_out *msout) { hw::device &hwdev = sender_account_keys.get_device(); hwdev.open_tx(tx_key); @@ -629,7 +630,8 @@ namespace cryptonote subaddresses[sender_account_keys.m_account_address.m_spend_public_key] = {0,0}; crypto::secret_key tx_key; std::vector additional_tx_keys; - return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, false, false, NULL); + std::vector destinations_copy = destinations; + return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, false, false, NULL); } //--------------------------------------------------------------- bool generate_genesis_block( diff --git a/src/cryptonote_core/cryptonote_tx_utils.h b/src/cryptonote_core/cryptonote_tx_utils.h index 1c390078d..a5d149fca 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.h +++ b/src/cryptonote_core/cryptonote_tx_utils.h @@ -90,8 +90,8 @@ namespace cryptonote //--------------------------------------------------------------- crypto::public_key get_destination_view_key_pub(const std::vector &destinations, const boost::optional& change_addr); bool construct_tx(const account_keys& sender_account_keys, std::vector &sources, const std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time); - bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, const std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector &additional_tx_keys, bool rct = false, bool bulletproof = false, rct::multisig_out *msout = NULL); - bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, const std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector &additional_tx_keys, bool rct = false, bool bulletproof = false, rct::multisig_out *msout = NULL); + bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector &additional_tx_keys, bool rct = false, bool bulletproof = false, rct::multisig_out *msout = NULL, bool shuffle_outs = true); + bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map& subaddresses, std::vector& sources, std::vector& destinations, const boost::optional& change_addr, std::vector extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector &additional_tx_keys, bool rct = false, bool bulletproof = false, rct::multisig_out *msout = NULL); bool generate_genesis_block( block& bl diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9d10809e8..722822966 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5141,7 +5141,7 @@ bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector Date: Tue, 15 May 2018 18:40:16 +0100 Subject: [PATCH 04/25] version.cmake: fix configuring version.cpp without git --- cmake/Version.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 439c4c5ae..3677e80d7 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -28,7 +28,7 @@ function (write_static_version_header hash) set(VERSIONTAG "${hash}") - configure_file("src/version.cpp.in" "version.cpp") + configure_file("${CMAKE_SOURCE_DIR}/src/version.cpp.in" "${CMAKE_BINARY_DIR}/version.cpp") endfunction () find_package(Git QUIET) From 7572b3578f9128f49a21ef575940264028b60e45 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sun, 13 May 2018 18:12:11 +0100 Subject: [PATCH 05/25] crypto: more places needing fixing for GCC 8.1 --- src/crypto/crypto.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index 494027560..ba0149240 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -124,9 +124,9 @@ namespace crypto { random_scalar(rng); } sec = rng; - sc_reduce32(&sec); // reduce in case second round of keys (sendkeys) + sc_reduce32(&unwrap(sec)); // reduce in case second round of keys (sendkeys) - ge_scalarmult_base(&point, &sec); + ge_scalarmult_base(&point, &unwrap(sec)); ge_p3_tobytes(&pub, &point); return rng; @@ -139,10 +139,10 @@ namespace crypto { bool crypto_ops::secret_key_to_public_key(const secret_key &sec, public_key &pub) { ge_p3 point; - if (sc_check(&sec) != 0) { + if (sc_check(&unwrap(sec)) != 0) { return false; } - ge_scalarmult_base(&point, &sec); + ge_scalarmult_base(&point, &unwrap(sec)); ge_p3_tobytes(&pub, &point); return true; } @@ -155,7 +155,7 @@ namespace crypto { if (ge_frombytes_vartime(&point, &key1) != 0) { return false; } - ge_scalarmult(&point2, &key2, &point); + ge_scalarmult(&point2, &unwrap(key2), &point); ge_mul8(&point3, &point2); ge_p1p1_to_p2(&point2, &point3); ge_tobytes(&derivation, &point2); @@ -199,7 +199,7 @@ namespace crypto { ec_scalar scalar; assert(sc_check(&base) == 0); derivation_to_scalar(derivation, output_index, scalar); - sc_add(&derived_key, &base, &scalar); + sc_add(&unwrap(derived_key), &unwrap(base), &scalar); } bool crypto_ops::derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, std::size_t output_index, public_key &derived_key) { @@ -254,7 +254,7 @@ namespace crypto { ge_scalarmult_base(&tmp3, &k); ge_p3_tobytes(&buf.comm, &tmp3); hash_to_scalar(&buf, sizeof(s_comm), sig.c); - sc_mulsub(&sig.r, &sig.c, &sec, &k); + sc_mulsub(&sig.r, &sig.c, &unwrap(sec), &k); } bool crypto_ops::check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig) { @@ -347,7 +347,7 @@ namespace crypto { hash_to_scalar(&buf, sizeof(buf), sig.c); // sig.r = k - sig.c*r - sc_mulsub(&sig.r, &sig.c, &r, &k); + sc_mulsub(&sig.r, &sig.c, &unwrap(r), &k); } bool crypto_ops::check_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional &B, const public_key &D, const signature &sig) { @@ -451,7 +451,7 @@ namespace crypto { ge_p2 point2; assert(sc_check(&sec) == 0); hash_to_ec(pub, point); - ge_scalarmult(&point2, &sec, &point); + ge_scalarmult(&point2, &unwrap(sec), &point); ge_tobytes(&image, &point2); } @@ -530,7 +530,7 @@ POP_WARNINGS } hash_to_scalar(buf.get(), rs_comm_size(pubs_count), h); sc_sub(&sig[sec_index].c, &h, &sum); - sc_mulsub(&sig[sec_index].r, &sig[sec_index].c, &sec, &k); + sc_mulsub(&sig[sec_index].r, &sig[sec_index].c, &unwrap(sec), &k); } bool crypto_ops::check_ring_signature(const hash &prefix_hash, const key_image &image, From e303fd1e1d05bb7b079ff6df7ed987a20a7f6760 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 12 May 2018 10:32:21 +0100 Subject: [PATCH 06/25] chacha: fix build with GCC 8.1 --- src/crypto/chacha.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/chacha.h b/src/crypto/chacha.h index 7a120931a..2b3ed8043 100644 --- a/src/crypto/chacha.h +++ b/src/crypto/chacha.h @@ -73,14 +73,14 @@ namespace crypto { static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key"); tools::scrubbed_arr pwd_hash; crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*variant*/, 0/*prehashed*/); - memcpy(&key, pwd_hash.data(), sizeof(key)); + memcpy(&unwrap(key), pwd_hash.data(), sizeof(key)); } inline void generate_chacha_key_prehashed(const void *data, size_t size, chacha_key& key) { static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key"); tools::scrubbed_arr pwd_hash; crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*variant*/, 1/*prehashed*/); - memcpy(&key, pwd_hash.data(), sizeof(key)); + memcpy(&unwrap(key), pwd_hash.data(), sizeof(key)); } inline void generate_chacha_key(std::string password, chacha_key& key) { From cefad3cea8d452278510cb887c2f80e2b8999153 Mon Sep 17 00:00:00 2001 From: stoffu Date: Wed, 2 May 2018 11:46:46 +0900 Subject: [PATCH 07/25] Wallet API: allow log path to be non-default & console output to be configurable --- src/wallet/api/wallet.cpp | 4 ++-- src/wallet/api/wallet2_api.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index fc78f0475..6be898295 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -305,14 +305,14 @@ uint64_t Wallet::maximumAllowedAmount() return std::numeric_limits::max(); } -void Wallet::init(const char *argv0, const char *default_log_base_name) { +void Wallet::init(const char *argv0, const char *default_log_base_name, const std::string &log_path, bool console) { #ifdef WIN32 // Activate UTF-8 support for Boost filesystem classes on Windows std::locale::global(boost::locale::generator().generate("")); boost::filesystem::path::imbue(std::locale()); #endif epee::string_tools::set_module_name_and_folder(argv0); - mlog_configure(mlog_get_default_log_path(default_log_base_name), true); + mlog_configure(log_path.empty() ? mlog_get_default_log_path(default_log_base_name) : log_path.c_str(), console); } void Wallet::debug(const std::string &category, const std::string &str) { diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 617b6035a..4fbc7298a 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -556,7 +556,8 @@ struct Wallet } static uint64_t maximumAllowedAmount(); // Easylogger wrapper - static void init(const char *argv0, const char *default_log_base_name); + static void init(const char *argv0, const char *default_log_base_name) { init(argv0, default_log_base_name, "", true); } + static void init(const char *argv0, const char *default_log_base_name, const std::string &log_path, bool console); static void debug(const std::string &category, const std::string &str); static void info(const std::string &category, const std::string &str); static void warning(const std::string &category, const std::string &str); From 9f3925902909b1dbc27936370c5e32f22661dc2b Mon Sep 17 00:00:00 2001 From: stoffu Date: Fri, 4 May 2018 02:04:47 +0900 Subject: [PATCH 08/25] blockchain: pop top if block version disagrees with the ideal fork version --- src/cryptonote_core/blockchain.cpp | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index feea259cb..b73a90c0f 100755 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -415,6 +415,53 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline MINFO("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block()); m_db->block_txn_stop(); + uint64_t num_popped_blocks = 0; + while (true) + { + const uint64_t top_height = m_db->height() - 1; + const crypto::hash top_id = m_db->top_block_hash(); + const block top_block = m_db->get_top_block(); + const uint8_t ideal_hf_version = get_ideal_hard_fork_version(top_height); + if (ideal_hf_version <= 1 || ideal_hf_version == top_block.major_version) + { + if (num_popped_blocks > 0) + MGINFO("Initial popping done, top block: " << top_id << ", top height: " << top_height << ", block version: " << (uint64_t)top_block.major_version); + break; + } + else + { + if (num_popped_blocks == 0) + MGINFO("Current top block " << top_id << " at height " << top_height << " has version " << (uint64_t)top_block.major_version << " which disagrees with the ideal version " << (uint64_t)ideal_hf_version); + if (num_popped_blocks % 100 == 0) + MGINFO("Popping blocks... " << top_height); + ++num_popped_blocks; + block popped_block; + std::vector popped_txs; + try + { + m_db->pop_block(popped_block, popped_txs); + } + // anything that could cause this to throw is likely catastrophic, + // so we re-throw + catch (const std::exception& e) + { + MERROR("Error popping block from blockchain: " << e.what()); + throw; + } + catch (...) + { + MERROR("Error popping block from blockchain, throwing!"); + throw; + } + } + } + if (num_popped_blocks > 0) + { + m_timestamps_and_difficulties_height = 0; + m_hardfork->reorganize_from_chain_height(get_current_blockchain_height()); + m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id()); + } + update_next_cumulative_size_limit(); return true; } From d5c86e1abe2e7231cafd00ea91a9b427568395ed Mon Sep 17 00:00:00 2001 From: anonimal Date: Thu, 19 Apr 2018 08:47:10 +0000 Subject: [PATCH 09/25] CMake: update new location of in-tree miniupnpc --- external/CMakeLists.txt | 26 ++++++++++++++++++++------ src/p2p/net_node.inl | 13 ++++++++++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 1fc4d64c1..4aa2c0ebf 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -39,13 +39,27 @@ find_package(Miniupnpc REQUIRED) message(STATUS "Using in-tree miniupnpc") -add_subdirectory(miniupnp/miniupnpc) + set(UPNP_STATIC false PARENT_SCOPE) + set(UPNP_INCLUDE ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE) + set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE) +else() + if(STATIC) + message(STATUS "Using miniupnpc from local source tree for static build") + else() + message(STATUS "Using miniupnpc from local source tree (/external/miniupnp/miniupnpc)") + endif() + + add_subdirectory(miniupnp/miniupnpc) + + set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") + if(MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") + elseif(NOT MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") + endif() -set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") -if(MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") -elseif(NOT MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") + set(UPNP_STATIC true PARENT_SCOPE) + set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) endif() set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 17dcd8ef1..672850b36 100755 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -49,9 +49,16 @@ #include "storages/levin_abstract_invoke2.h" #include "cryptonote_core/cryptonote_core.h" -#include -#include -#include +// We have to look for miniupnpc headers in different places, dependent on if its compiled or external +#ifdef UPNP_STATIC + #include + #include + #include +#else + #include "miniupnpc.h" + #include "upnpcommands.h" + #include "upnperrors.h" +#endif #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" From 17ae192dbfb62cac6eeb179daad562e8c630f96c Mon Sep 17 00:00:00 2001 From: anonimal Date: Sat, 21 Apr 2018 09:30:55 +0000 Subject: [PATCH 10/25] Build: update CMake and p2p for in-tree miniupnp (cherry picked from commit a7366b5feeffaeb65b217b2d6f138e0ab1c90192) --- external/CMakeLists.txt | 26 ++++++-------------------- src/p2p/net_node.inl | 13 +++---------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 4aa2c0ebf..1fc4d64c1 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -39,27 +39,13 @@ find_package(Miniupnpc REQUIRED) message(STATUS "Using in-tree miniupnpc") - set(UPNP_STATIC false PARENT_SCOPE) - set(UPNP_INCLUDE ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE) - set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE) -else() - if(STATIC) - message(STATUS "Using miniupnpc from local source tree for static build") - else() - message(STATUS "Using miniupnpc from local source tree (/external/miniupnp/miniupnpc)") - endif() - - add_subdirectory(miniupnp/miniupnpc) - - set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") - if(MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") - elseif(NOT MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") - endif() +add_subdirectory(miniupnp/miniupnpc) - set(UPNP_STATIC true PARENT_SCOPE) - set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) +set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") +if(MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") +elseif(NOT MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") endif() set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 672850b36..17dcd8ef1 100755 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -49,16 +49,9 @@ #include "storages/levin_abstract_invoke2.h" #include "cryptonote_core/cryptonote_core.h" -// We have to look for miniupnpc headers in different places, dependent on if its compiled or external -#ifdef UPNP_STATIC - #include - #include - #include -#else - #include "miniupnpc.h" - #include "upnpcommands.h" - #include "upnperrors.h" -#endif +#include +#include +#include #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" From 140cf4bfd48ef39e2b99f82a30c70d38fcbd199c Mon Sep 17 00:00:00 2001 From: anonimal Date: Thu, 19 Apr 2018 08:47:10 +0000 Subject: [PATCH 11/25] CMake: update new location of in-tree miniupnpc (cherry picked from commit b16a282f97d8f6c967e8a0b1ecfd75110f095182) --- external/CMakeLists.txt | 26 ++++++++++++++++++++------ src/p2p/net_node.inl | 13 ++++++++++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 1fc4d64c1..4aa2c0ebf 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -39,13 +39,27 @@ find_package(Miniupnpc REQUIRED) message(STATUS "Using in-tree miniupnpc") -add_subdirectory(miniupnp/miniupnpc) + set(UPNP_STATIC false PARENT_SCOPE) + set(UPNP_INCLUDE ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE) + set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE) +else() + if(STATIC) + message(STATUS "Using miniupnpc from local source tree for static build") + else() + message(STATUS "Using miniupnpc from local source tree (/external/miniupnp/miniupnpc)") + endif() + + add_subdirectory(miniupnp/miniupnpc) + + set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") + if(MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") + elseif(NOT MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") + endif() -set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") -if(MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") -elseif(NOT MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") + set(UPNP_STATIC true PARENT_SCOPE) + set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) endif() set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 17dcd8ef1..672850b36 100755 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -49,9 +49,16 @@ #include "storages/levin_abstract_invoke2.h" #include "cryptonote_core/cryptonote_core.h" -#include -#include -#include +// We have to look for miniupnpc headers in different places, dependent on if its compiled or external +#ifdef UPNP_STATIC + #include + #include + #include +#else + #include "miniupnpc.h" + #include "upnpcommands.h" + #include "upnperrors.h" +#endif #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" From c0234f903168a95543c9cd9bc6b04765eef34550 Mon Sep 17 00:00:00 2001 From: anonimal Date: Thu, 19 Apr 2018 06:31:11 +0000 Subject: [PATCH 12/25] Build: add miniupnp submodule Though we only need miniupnpc, rebasing and maintaining a miniupnpc-only repo is unrealistic. (cherry picked from commit 3c40eb768c292a4dec79d7dffd6685fd37940a2a) --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 00a81e58b..9703c596a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,5 +5,5 @@ branch = monero [submodule "external/miniupnp"] path = external/miniupnp - url = https://github.com/monero-project/miniupnp + url = https://github.com/anonimal/miniupnp branch = monero From 0fc422b684b183d6b61af77e9363cb47a60fa795 Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 9 Apr 2018 16:07:11 +0200 Subject: [PATCH 13/25] Fix sub-address tx scan. When additional keys was needed, the TX scan failed because the derivation data was always recomputed with the main tx_key and not the corresponding additional one. Moreover this patch avoid perf decreasing when not using HW device. --- src/device/device_default.hpp | 2 +- src/device/device_ledger.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device/device_default.hpp b/src/device/device_default.hpp index 771fbba72..649fed862 100644 --- a/src/device/device_default.hpp +++ b/src/device/device_default.hpp @@ -93,7 +93,7 @@ namespace hw { bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override; crypto::secret_key generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false) override; bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override; - bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations) override; + bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations); bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override; bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override; bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override; diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp index b62bdf959..a979b187d 100644 --- a/src/device/device_ledger.hpp +++ b/src/device/device_ledger.hpp @@ -174,7 +174,7 @@ namespace hw { bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override; crypto::secret_key generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false) override; bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override; - bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations) override; + bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations); bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override; bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override; bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override; From a89545dacf0360c28766386785c4eb22ea56f38c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 4 Apr 2018 10:03:16 +0100 Subject: [PATCH 14/25] rpc: allow getting pruned blocks from gettransactions and get them pruned in find_and_save_rings, since it does not need the pruned data in the first place. Also set decode_to_json to false where missing, we don't need this either. --- src/wallet/wallet2.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 722822966..1d5626059 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5610,7 +5610,24 @@ bool wallet2::find_and_save_rings(bool force) txs_hashes.push_back(txid); } - MDEBUG("Found " << std::to_string(txs_hashes.size()) << " transactions"); + MDEBUG("Found " << std::to_string(req.txs_hashes.size()) << " transactions"); + + // get those transactions from the daemon + req.decode_as_json = false; + req.prune = true; + bool r; + { + const boost::lock_guard lock{m_daemon_rpc_mutex}; + r = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client, rpc_timeout); + } + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "gettransactions"); + THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "gettransactions"); + THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::wallet_internal_error, "gettransactions"); + THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error, + "daemon returned wrong response for gettransactions, wrong txs count = " + + std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size())); + + MDEBUG("Scanning " << res.txs.size() << " transactions"); crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); From 234296d3769ad91be50fbe6a4a2d7e7d14a73d57 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 4 Apr 2018 11:40:31 +0100 Subject: [PATCH 15/25] wallet2: request transactions in slices when scanning for known rings This avoid massive memory consumption for huge wallets --- src/wallet/wallet2.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 1d5626059..722822966 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5610,24 +5610,7 @@ bool wallet2::find_and_save_rings(bool force) txs_hashes.push_back(txid); } - MDEBUG("Found " << std::to_string(req.txs_hashes.size()) << " transactions"); - - // get those transactions from the daemon - req.decode_as_json = false; - req.prune = true; - bool r; - { - const boost::lock_guard lock{m_daemon_rpc_mutex}; - r = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client, rpc_timeout); - } - THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "gettransactions"); - THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "gettransactions"); - THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::wallet_internal_error, "gettransactions"); - THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error, - "daemon returned wrong response for gettransactions, wrong txs count = " + - std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size())); - - MDEBUG("Scanning " << res.txs.size() << " transactions"); + MDEBUG("Found " << std::to_string(txs_hashes.size()) << " transactions"); crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); From 00b0f8dce4f99b032e0a8fc038547af9deaa9a74 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 4 Apr 2018 10:03:16 +0100 Subject: [PATCH 16/25] rpc: allow getting pruned blocks from gettransactions and get them pruned in find_and_save_rings, since it does not need the pruned data in the first place. Also set decode_to_json to false where missing, we don't need this either. --- src/wallet/wallet2.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 722822966..1d5626059 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5610,7 +5610,24 @@ bool wallet2::find_and_save_rings(bool force) txs_hashes.push_back(txid); } - MDEBUG("Found " << std::to_string(txs_hashes.size()) << " transactions"); + MDEBUG("Found " << std::to_string(req.txs_hashes.size()) << " transactions"); + + // get those transactions from the daemon + req.decode_as_json = false; + req.prune = true; + bool r; + { + const boost::lock_guard lock{m_daemon_rpc_mutex}; + r = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client, rpc_timeout); + } + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "gettransactions"); + THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "gettransactions"); + THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::wallet_internal_error, "gettransactions"); + THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error, + "daemon returned wrong response for gettransactions, wrong txs count = " + + std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size())); + + MDEBUG("Scanning " << res.txs.size() << " transactions"); crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); From f2cd4a45a790ea2889af06c94a6830377e762310 Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 26 Mar 2018 12:55:48 +0200 Subject: [PATCH 17/25] Add the possibility to export private view key for fast scan. On client startup the device asks for authorization to export the private view key. If user agree, the client hold the private view key allowing a fast blockchain scan. If the user does not agree, the blockchain scan is fully done via the device. --- src/device/device_ledger.cpp | 4 ---- src/wallet/wallet2.cpp | 14 +++++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index aedaf8382..373f4a282 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -135,10 +135,6 @@ namespace hw { return sec == crypto::null_skey; } - bool operator==(const crypto::key_derivation &d0, const crypto::key_derivation &d1) { - return !memcmp(&d0, &d1, sizeof(d0)); - } - /* ===================================================================== */ /* === Device ==== */ /* ===================================================================== */ diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 1d5626059..b8d6bec01 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1007,7 +1007,7 @@ void wallet2::set_unspent(size_t idx) void wallet2::check_acc_out_precomp(const tx_out &o, const crypto::key_derivation &derivation, const std::vector &additional_derivations, size_t i, tx_scan_info_t &tx_scan_info) const { hw::device &hwdev = m_account.get_device(); - boost::unique_lock hwdev_lock (hwdev); + std::unique_lock hwdev_lock (hwdev); hwdev.set_mode(hw::device::TRANSACTION_PARSE); if (o.target.type() != typeid(txout_to_key)) { @@ -1085,7 +1085,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote //ensure device is let in NONE mode in any case hw::device &hwdev = m_account.get_device(); - boost::unique_lock hwdev_lock (hwdev); + std::unique_lock hwdev_lock (hwdev); hw::reset_mode rst(hwdev); hwdev_lock.unlock(); @@ -1180,7 +1180,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote THROW_WALLET_EXCEPTION_IF(tx_scan_info[i].error, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys()); if (tx_scan_info[i].received) { - hwdev.conceal_derivation(tx_scan_info[i].received->derivation, tx_pub_key, additional_tx_pub_keys, derivation, additional_derivations); + hwdev.generate_key_derivation(tx_pub_key, keys.m_view_secret_key, tx_scan_info[i].received->derivation); scan_output(tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs); } } @@ -1203,7 +1203,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote THROW_WALLET_EXCEPTION_IF(tx_scan_info[i].error, error::acc_outs_lookup_error, tx, tx_pub_key, m_account.get_keys()); if (tx_scan_info[i].received) { - hwdev.conceal_derivation(tx_scan_info[i].received->derivation, tx_pub_key, additional_tx_pub_keys, derivation, additional_derivations); + hwdev.generate_key_derivation(tx_pub_key, keys.m_view_secret_key, tx_scan_info[i].received->derivation); scan_output(tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs); } } @@ -1219,7 +1219,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote { hwdev_lock.lock(); hwdev.set_mode(hw::device::NONE); - hwdev.conceal_derivation(tx_scan_info[i].received->derivation, tx_pub_key, additional_tx_pub_keys, derivation, additional_derivations); + hwdev.generate_key_derivation(tx_pub_key, keys.m_view_secret_key, tx_scan_info[i].received->derivation); scan_output(tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs); hwdev_lock.unlock(); } @@ -7302,7 +7302,7 @@ std::vector wallet2::create_transactions_2(std::vector hwdev_lock (hwdev); + std::unique_lock hwdev_lock (hwdev); hw::reset_mode rst(hwdev); if(m_light_wallet) { @@ -7885,7 +7885,7 @@ std::vector wallet2::create_transactions_from(const crypton { //ensure device is let in NONE mode in any case hw::device &hwdev = m_account.get_device(); - boost::unique_lock hwdev_lock (hwdev); + std::unique_lock hwdev_lock (hwdev); hw::reset_mode rst(hwdev); uint64_t accumulated_fee, accumulated_outputs, accumulated_change; From 9f57f092649be589e67db4960d97669294d43d9c Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 26 Mar 2018 12:38:38 +0200 Subject: [PATCH 18/25] Change mutex lock model to avoid dead lock and ensure locks are always released. Additional cosmetic fixes: move 'name' as protected remove unnecessary local var Fix debug log --- src/device/device.hpp | 14 ++---- src/device/device_default.cpp | 3 -- src/device/device_ledger.cpp | 87 ++++++++++++++++++----------------- src/device/device_ledger.hpp | 2 - 4 files changed, 49 insertions(+), 57 deletions(-) diff --git a/src/device/device.hpp b/src/device/device.hpp index 9df0cb39d..91bc30c53 100644 --- a/src/device/device.hpp +++ b/src/device/device.hpp @@ -78,7 +78,6 @@ namespace hw { return false; } - class device { protected: std::string name; @@ -90,12 +89,10 @@ namespace hw { virtual ~device() {} explicit virtual operator bool() const = 0; - enum device_mode { - NONE, - TRANSACTION_CREATE_REAL, - TRANSACTION_CREATE_FAKE, - TRANSACTION_PARSE - }; + + static const int SIGNATURE_REAL = 0; + static const int SIGNATURE_FAKE = 1; + /* ======================================================================= */ /* SETUP/TEARDOWN */ @@ -109,9 +106,6 @@ namespace hw { virtual bool connect(void) = 0; virtual bool disconnect(void) = 0; - virtual bool set_mode(device_mode mode) = 0; - - /* ======================================================================= */ /* LOCKER */ /* ======================================================================= */ diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp index 0071f7d4f..3f7b8078d 100644 --- a/src/device/device_default.cpp +++ b/src/device/device_default.cpp @@ -82,9 +82,6 @@ namespace hw { dfns(); } - bool device_default::set_mode(device_mode mode) { - return true; - } /* ======================================================================= */ /* LOCKER */ diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index 373f4a282..c919c4ac1 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -511,13 +511,12 @@ namespace hw { return true; } - bool device_ledger::get_secret_keys(crypto::secret_key &vkey , crypto::secret_key &skey) { + bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) { AUTO_LOCK_CMD(); + memset(viewkey.data, 0x00, 32); + memset(spendkey.data, 0xFF, 32); - //secret key are represented as fake key on the wallet side - memset(vkey.data, 0x00, 32); - memset(skey.data, 0xFF, 32); - + #ifdef DEBUG_HWDEVICE //spcialkey, normal conf handled in decrypt int offset; reset_buffer(); @@ -536,22 +535,12 @@ namespace hw { this->length_send = offset; this->exchange(); - //View key is retrievied, if allowed, to speed up blockchain parsing - memmove(this->viewkey.data, this->buffer_recv+0, 32); - if (is_fake_view_key(this->viewkey)) { - MDEBUG("Have Not view key"); - this->has_view_key = false; - } else { - MDEBUG("Have view key"); - this->has_view_key = true; - } - - #ifdef DEBUG_HWDEVICE - memmove(dbg_viewkey.data, this->buffer_recv+0, 32); - memmove(dbg_spendkey.data, this->buffer_recv+32, 32); - #endif + //clear key + memmove(ledger::viewkey.data, this->buffer_recv+64, 32); + memmove(ledger::spendkey.data, this->buffer_recv+96, 32); - return true; + #endif + return true; } bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) { @@ -596,6 +585,8 @@ namespace hw { bool device_ledger::derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub){ AUTO_LOCK_CMD(); + int offset; + #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; crypto::key_derivation derivation_x; @@ -652,10 +643,10 @@ namespace hw { //pub key memmove(derived_pub.data, &this->buffer_recv[0], 32); - } - #ifdef DEBUG_HWDEVICE - hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); - #endif + + #ifdef DEBUG_HWDEVICE + hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); + #endif return true; } @@ -1042,7 +1033,7 @@ namespace hw { bool device_ledger::generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) { AUTO_LOCK_CMD(); - bool r = false; + int offset; #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; @@ -1104,23 +1095,9 @@ namespace hw { return r; } - bool device_ledger::conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations) { - const crypto::public_key *pkey=NULL; - if (derivation == main_derivation) { - pkey = &tx_pub_key; - MDEBUG("conceal derivation with main tx pub key"); - } else { - for(size_t n=0; n < additional_derivations.size();++n) { - if(derivation == additional_derivations[n]) { - pkey = &additional_tx_pub_keys[n]; - MDEBUG("conceal derivation with additionnal tx pub key"); - break; - } - } - } - ASSERT_X(pkey, "Mismatched derivation on scan info"); - return this->generate_key_derivation(*pkey, crypto::null_skey, derivation); - } + + return true; + } bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) { AUTO_LOCK_CMD(); @@ -1407,6 +1384,32 @@ namespace hw { return true; } + bool device_ledger::set_signature_mode(unsigned int sig_mode) { + AUTO_LOCK_CMD(); + int offset ; + + reset_buffer(); + + this->buffer_send[0] = 0x00; + this->buffer_send[1] = INS_SET_SIGNATURE_MODE; + this->buffer_send[2] = 0x01; + this->buffer_send[3] = 0x00; + this->buffer_send[4] = 0x00; + offset = 5; + //options + this->buffer_send[offset] = 0x00; + offset += 1; + //account + this->buffer_send[offset] = sig_mode; + offset += 1; + + this->buffer_send[4] = offset-5; + this->length_send = offset; + this->exchange(); + + return true; + } + bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) { AUTO_LOCK_CMD(); int offset; diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp index a979b187d..90907616f 100644 --- a/src/device/device_ledger.hpp +++ b/src/device/device_ledger.hpp @@ -39,7 +39,6 @@ #else #include #include -#endif #include #include @@ -139,7 +138,6 @@ namespace hw { bool connect(void) override; bool disconnect() override; - bool set_mode(device_mode mode) override; /* ======================================================================= */ /* LOCKER */ From ebbf84900d09e1b604dc0cd29bcd05f8d3c34a95 Mon Sep 17 00:00:00 2001 From: stoffu Date: Sat, 31 Mar 2018 16:19:14 +0900 Subject: [PATCH 19/25] cryptonote_tx_util: make destinations properly shuffled --- src/cryptonote_core/cryptonote_tx_utils.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index 071ce591e..04a10044f 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -315,10 +315,9 @@ namespace cryptonote tx.vin.push_back(input_to_key); } - if (shuffle_outs) - { - std::shuffle(destinations.begin(), destinations.end(), std::default_random_engine(crypto::rand())); - } + // "Shuffle" outs + std::vector shuffled_dsts(destinations); + std::shuffle(shuffled_dsts.begin(), shuffled_dsts.end(), std::default_random_engine(crypto::rand())); // sort ins by their key image std::vector ins_order(sources.size()); @@ -365,7 +364,7 @@ namespace cryptonote uint64_t summary_outs_money = 0; //fill outputs size_t output_index = 0; - for(const tx_destination_entry& dst_entr: destinations) + for(const tx_destination_entry& dst_entr: shuffled_dsts) { CHECK_AND_ASSERT_MES(dst_entr.amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.amount); crypto::key_derivation derivation; From 709a0557d212c93b1ba1037bf4d73736dbbfb504 Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 26 Mar 2018 12:55:48 +0200 Subject: [PATCH 20/25] Add the possibility to export private view key for fast scan. On client startup the device asks for authorization to export the private view key. If user agree, the client hold the private view key allowing a fast blockchain scan. If the user does not agree, the blockchain scan is fully done via the device. --- src/device/device.hpp | 14 +++++-- src/device/device_default.cpp | 3 ++ src/device/device_ledger.cpp | 71 ++++++++++++----------------------- src/device/device_ledger.hpp | 1 + 4 files changed, 39 insertions(+), 50 deletions(-) diff --git a/src/device/device.hpp b/src/device/device.hpp index 91bc30c53..9df0cb39d 100644 --- a/src/device/device.hpp +++ b/src/device/device.hpp @@ -78,6 +78,7 @@ namespace hw { return false; } + class device { protected: std::string name; @@ -89,10 +90,12 @@ namespace hw { virtual ~device() {} explicit virtual operator bool() const = 0; - - static const int SIGNATURE_REAL = 0; - static const int SIGNATURE_FAKE = 1; - + enum device_mode { + NONE, + TRANSACTION_CREATE_REAL, + TRANSACTION_CREATE_FAKE, + TRANSACTION_PARSE + }; /* ======================================================================= */ /* SETUP/TEARDOWN */ @@ -106,6 +109,9 @@ namespace hw { virtual bool connect(void) = 0; virtual bool disconnect(void) = 0; + virtual bool set_mode(device_mode mode) = 0; + + /* ======================================================================= */ /* LOCKER */ /* ======================================================================= */ diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp index 3f7b8078d..0071f7d4f 100644 --- a/src/device/device_default.cpp +++ b/src/device/device_default.cpp @@ -82,6 +82,9 @@ namespace hw { dfns(); } + bool device_default::set_mode(device_mode mode) { + return true; + } /* ======================================================================= */ /* LOCKER */ diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index c919c4ac1..6fdb6bb1c 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -511,12 +511,13 @@ namespace hw { return true; } - bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) { + bool device_ledger::get_secret_keys(crypto::secret_key &vkey , crypto::secret_key &skey) { AUTO_LOCK_CMD(); - memset(viewkey.data, 0x00, 32); - memset(spendkey.data, 0xFF, 32); - #ifdef DEBUG_HWDEVICE + //secret key are represented as fake key on the wallet side + memset(vkey.data, 0x00, 32); + memset(skey.data, 0xFF, 32); + //spcialkey, normal conf handled in decrypt int offset; reset_buffer(); @@ -535,12 +536,22 @@ namespace hw { this->length_send = offset; this->exchange(); - //clear key - memmove(ledger::viewkey.data, this->buffer_recv+64, 32); - memmove(ledger::spendkey.data, this->buffer_recv+96, 32); + //View key is retrievied, if allowed, to speed up blockchain parsing + memmove(this->viewkey.data, this->buffer_recv+0, 32); + if (is_fake_view_key(this->viewkey)) { + MDEBUG("Have Not view key"); + this->has_view_key = false; + } else { + MDEBUG("Have view key"); + this->has_view_key = true; + } + + #ifdef DEBUG_HWDEVICE + memmove(dbg_viewkey.data, this->buffer_recv+0, 32); + memmove(dbg_spendkey.data, this->buffer_recv+32, 32); + #endif - #endif - return true; + return true; } bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) { @@ -585,8 +596,6 @@ namespace hw { bool device_ledger::derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub){ AUTO_LOCK_CMD(); - int offset; - #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; crypto::key_derivation derivation_x; @@ -643,10 +652,10 @@ namespace hw { //pub key memmove(derived_pub.data, &this->buffer_recv[0], 32); - - #ifdef DEBUG_HWDEVICE - hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); - #endif + } + #ifdef DEBUG_HWDEVICE + hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); + #endif return true; } @@ -1033,7 +1042,7 @@ namespace hw { bool device_ledger::generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) { AUTO_LOCK_CMD(); - int offset; + bool r = false; #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; @@ -1095,10 +1104,6 @@ namespace hw { return r; } - - return true; - } - bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) { AUTO_LOCK_CMD(); int offset; @@ -1384,32 +1389,6 @@ namespace hw { return true; } - bool device_ledger::set_signature_mode(unsigned int sig_mode) { - AUTO_LOCK_CMD(); - int offset ; - - reset_buffer(); - - this->buffer_send[0] = 0x00; - this->buffer_send[1] = INS_SET_SIGNATURE_MODE; - this->buffer_send[2] = 0x01; - this->buffer_send[3] = 0x00; - this->buffer_send[4] = 0x00; - offset = 5; - //options - this->buffer_send[offset] = 0x00; - offset += 1; - //account - this->buffer_send[offset] = sig_mode; - offset += 1; - - this->buffer_send[4] = offset-5; - this->length_send = offset; - this->exchange(); - - return true; - } - bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) { AUTO_LOCK_CMD(); int offset; diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp index 90907616f..e29fa7cce 100644 --- a/src/device/device_ledger.hpp +++ b/src/device/device_ledger.hpp @@ -138,6 +138,7 @@ namespace hw { bool connect(void) override; bool disconnect() override; + bool set_mode(device_mode mode) override; /* ======================================================================= */ /* LOCKER */ From f602fb82602eae34ef1c1b63368054cea4023da2 Mon Sep 17 00:00:00 2001 From: cslashm Date: Mon, 26 Mar 2018 12:38:38 +0200 Subject: [PATCH 21/25] Change mutex lock model to avoid dead lock and ensure locks are always released. Additional cosmetic fixes: move 'name' as protected remove unnecessary local var Fix debug log --- src/device/device.hpp | 14 ++---- src/device/device_default.cpp | 3 -- src/device/device_ledger.cpp | 86 ++++++++++++++++++++--------------- src/device/device_ledger.hpp | 1 - 4 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/device/device.hpp b/src/device/device.hpp index 9df0cb39d..91bc30c53 100644 --- a/src/device/device.hpp +++ b/src/device/device.hpp @@ -78,7 +78,6 @@ namespace hw { return false; } - class device { protected: std::string name; @@ -90,12 +89,10 @@ namespace hw { virtual ~device() {} explicit virtual operator bool() const = 0; - enum device_mode { - NONE, - TRANSACTION_CREATE_REAL, - TRANSACTION_CREATE_FAKE, - TRANSACTION_PARSE - }; + + static const int SIGNATURE_REAL = 0; + static const int SIGNATURE_FAKE = 1; + /* ======================================================================= */ /* SETUP/TEARDOWN */ @@ -109,9 +106,6 @@ namespace hw { virtual bool connect(void) = 0; virtual bool disconnect(void) = 0; - virtual bool set_mode(device_mode mode) = 0; - - /* ======================================================================= */ /* LOCKER */ /* ======================================================================= */ diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp index 0071f7d4f..3f7b8078d 100644 --- a/src/device/device_default.cpp +++ b/src/device/device_default.cpp @@ -82,9 +82,6 @@ namespace hw { dfns(); } - bool device_default::set_mode(device_mode mode) { - return true; - } /* ======================================================================= */ /* LOCKER */ diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index 6fdb6bb1c..c3a7938d6 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -511,13 +511,12 @@ namespace hw { return true; } - bool device_ledger::get_secret_keys(crypto::secret_key &vkey , crypto::secret_key &skey) { + bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) { AUTO_LOCK_CMD(); + memset(viewkey.data, 0x00, 32); + memset(spendkey.data, 0xFF, 32); - //secret key are represented as fake key on the wallet side - memset(vkey.data, 0x00, 32); - memset(skey.data, 0xFF, 32); - + #ifdef DEBUG_HWDEVICE //spcialkey, normal conf handled in decrypt int offset; reset_buffer(); @@ -536,22 +535,12 @@ namespace hw { this->length_send = offset; this->exchange(); - //View key is retrievied, if allowed, to speed up blockchain parsing - memmove(this->viewkey.data, this->buffer_recv+0, 32); - if (is_fake_view_key(this->viewkey)) { - MDEBUG("Have Not view key"); - this->has_view_key = false; - } else { - MDEBUG("Have view key"); - this->has_view_key = true; - } - - #ifdef DEBUG_HWDEVICE - memmove(dbg_viewkey.data, this->buffer_recv+0, 32); - memmove(dbg_spendkey.data, this->buffer_recv+32, 32); - #endif + //clear key + memmove(ledger::viewkey.data, this->buffer_recv+64, 32); + memmove(ledger::spendkey.data, this->buffer_recv+96, 32); - return true; + #endif + return true; } bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) { @@ -596,6 +585,8 @@ namespace hw { bool device_ledger::derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub){ AUTO_LOCK_CMD(); + int offset; + #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; crypto::key_derivation derivation_x; @@ -652,10 +643,10 @@ namespace hw { //pub key memmove(derived_pub.data, &this->buffer_recv[0], 32); - } - #ifdef DEBUG_HWDEVICE - hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); - #endif + + #ifdef DEBUG_HWDEVICE + hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); + #endif return true; } @@ -1042,7 +1033,7 @@ namespace hw { bool device_ledger::generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) { AUTO_LOCK_CMD(); - bool r = false; + int offset; #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; @@ -1089,19 +1080,14 @@ namespace hw { //derivattion data memmove(derivation.data, &this->buffer_recv[0], 32); - r = true; - } - #ifdef DEBUG_HWDEVICE - crypto::key_derivation derivation_clear ; - if ((this->mode == TRANSACTION_PARSE) && has_view_key) { - derivation_clear = derivation; - }else { - derivation_clear = hw::ledger::decrypt(derivation); - } - hw::ledger::check32("generate_key_derivation", "derivation", derivation_x.data, derivation_clear.data); - #endif - return r; + #ifdef DEBUG_HWDEVICE + crypto::key_derivation derivation_clear = hw::ledger::decrypt(derivation); + hw::ledger::check32("generate_key_derivation", "derivation", derivation_x.data, derivation_clear.data); + #endif + + + return true; } bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) { @@ -1389,6 +1375,32 @@ namespace hw { return true; } + bool device_ledger::set_signature_mode(unsigned int sig_mode) { + AUTO_LOCK_CMD(); + int offset ; + + reset_buffer(); + + this->buffer_send[0] = 0x00; + this->buffer_send[1] = INS_SET_SIGNATURE_MODE; + this->buffer_send[2] = 0x01; + this->buffer_send[3] = 0x00; + this->buffer_send[4] = 0x00; + offset = 5; + //options + this->buffer_send[offset] = 0x00; + offset += 1; + //account + this->buffer_send[offset] = sig_mode; + offset += 1; + + this->buffer_send[4] = offset-5; + this->length_send = offset; + this->exchange(); + + return true; + } + bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) { AUTO_LOCK_CMD(); int offset; diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp index e29fa7cce..90907616f 100644 --- a/src/device/device_ledger.hpp +++ b/src/device/device_ledger.hpp @@ -138,7 +138,6 @@ namespace hw { bool connect(void) override; bool disconnect() override; - bool set_mode(device_mode mode) override; /* ======================================================================= */ /* LOCKER */ From da5dfaa1b67fc36626649a703e7af6beb423cb81 Mon Sep 17 00:00:00 2001 From: stoffu Date: Thu, 22 Mar 2018 18:03:57 +0900 Subject: [PATCH 22/25] wallet2: set from_height of GET_OUTPUT_DISTRIBUTION correctly The previous expression req_t.from_height = X ? Y >= Z : 0; forces the parameter to take the value of either 0 or 1. --- src/wallet/wallet2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b8d6bec01..4ecde2242 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5889,7 +5889,6 @@ void wallet2::get_outs(std::vector> auto end = std::unique(req_t.amounts.begin(), req_t.amounts.end()); req_t.amounts.resize(std::distance(req_t.amounts.begin(), end)); req_t.from_height = std::max(segregation_fork_height, RECENT_OUTPUT_BLOCKS) - RECENT_OUTPUT_BLOCKS; - req_t.to_height = segregation_fork_height + 1; req_t.cumulative = true; m_daemon_rpc_mutex.lock(); bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_output_distribution", req_t, resp_t, m_http_client, rpc_timeout * 1000); From b964e723ddb87e5bc772e497f22ee1b6082cb2c0 Mon Sep 17 00:00:00 2001 From: stoffu Date: Thu, 22 Mar 2018 11:44:08 +0900 Subject: [PATCH 23/25] wallet2: fix for loading settings of key reuse mitigation --- src/wallet/wallet2.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 4ecde2242..0df17925e 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2698,8 +2698,6 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_ m_segregate_pre_fork_outputs = true; m_key_reuse_mitigation2 = true; m_segregation_height = 0; - m_subaddress_lookahead_major = SUBADDRESS_LOOKAHEAD_MAJOR; - m_subaddress_lookahead_minor = SUBADDRESS_LOOKAHEAD_MINOR; m_key_on_device = false; } else if(json.IsObject()) @@ -2820,10 +2818,6 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_ m_key_reuse_mitigation2 = field_key_reuse_mitigation2; GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, segregation_height, int, Uint, false, 0); m_segregation_height = field_segregation_height; - GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, subaddress_lookahead_major, uint32_t, Uint, false, SUBADDRESS_LOOKAHEAD_MAJOR); - m_subaddress_lookahead_major = field_subaddress_lookahead_major; - GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, subaddress_lookahead_minor, uint32_t, Uint, false, SUBADDRESS_LOOKAHEAD_MINOR); - m_subaddress_lookahead_minor = field_subaddress_lookahead_minor; } else { From f2e6a11703a903a096b847a7a372f7c48d113d27 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 21 Mar 2018 14:29:49 +0000 Subject: [PATCH 24/25] wallet: catch exceptions dealing with ringdb and warn --- src/simplewallet/simplewallet.cpp | 3 +++ src/wallet/wallet2.cpp | 44 +++++++++++++++++++++---------- src/wallet/wallet2.h | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 11fd5cc5f..45e9058c9 100755 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3063,6 +3063,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (!m_trusted_daemon) message_writer() << (boost::format(tr("Warning: using an untrusted daemon at %s, privacy will be lessened")) % m_wallet->get_daemon_address()).str(); + if (m_wallet->get_ring_database().empty()) + fail_msg_writer() << tr("Failed to initialize ring database: privacy enhancing features will be inactive"); + m_wallet->callback(this); return true; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0df17925e..b28539c18 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5497,21 +5497,33 @@ std::vector wallet2::create_transactions(std::vectoradd_rings(key, tx); } catch (const std::exception &e) { return false; } } @@ -5520,7 +5532,8 @@ bool wallet2::add_rings(const cryptonote::transaction_prefix &tx) { crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); - return add_rings(key, tx); + try { return add_rings(key, tx); } + catch (const std::exception &e) { return false; } } bool wallet2::remove_rings(const cryptonote::transaction_prefix &tx) @@ -5529,13 +5542,14 @@ bool wallet2::remove_rings(const cryptonote::transaction_prefix &tx) return false; crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); - return m_ringdb->remove_rings(key, tx); + try { return m_ringdb->remove_rings(key, tx); } + catch (const std::exception &e) { return false; } } bool wallet2::get_ring(const crypto::chacha_key &key, const crypto::key_image &key_image, std::vector &outs) { if (!m_ringdb) - return false; + return true; try { return m_ringdb->get_ring(key, key_image, outs); } catch (const std::exception &e) { return false; } } @@ -5568,7 +5582,8 @@ bool wallet2::get_ring(const crypto::key_image &key_image, std::vector crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); - return get_ring(key, key_image, outs); + try { return get_ring(key, key_image, outs); } + catch (const std::exception &e) { return false; } } bool wallet2::set_ring(const crypto::key_image &key_image, const std::vector &outs, bool relative) @@ -5579,7 +5594,8 @@ bool wallet2::set_ring(const crypto::key_image &key_image, const std::vectorset_ring(key, key_image, outs, relative); + try { return m_ringdb->set_ring(key, key_image, outs, relative); } + catch (const std::exception &e) { return false; } } bool wallet2::find_and_save_rings(bool force) @@ -5674,7 +5690,7 @@ bool wallet2::find_and_save_rings(bool force) bool wallet2::blackball_output(const crypto::public_key &output) { if (!m_ringdb) - return false; + return true; try { return m_ringdb->blackball(output); } catch (const std::exception &e) { return false; } } @@ -5682,7 +5698,7 @@ bool wallet2::blackball_output(const crypto::public_key &output) bool wallet2::set_blackballed_outputs(const std::vector &outputs, bool add) { if (!m_ringdb) - return false; + return true; try { bool ret = true; @@ -5698,7 +5714,7 @@ bool wallet2::set_blackballed_outputs(const std::vector &out bool wallet2::unblackball_output(const crypto::public_key &output) { if (!m_ringdb) - return false; + return true; try { return m_ringdb->unblackball(output); } catch (const std::exception &e) { return false; } } @@ -5706,7 +5722,7 @@ bool wallet2::unblackball_output(const crypto::public_key &output) bool wallet2::is_output_blackballed(const crypto::public_key &output) const { if (!m_ringdb) - return false; + return true; try { return m_ringdb->blackballed(output); } catch (const std::exception &e) { return false; } } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 275d06ed8..b9f124e32 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1059,7 +1059,7 @@ namespace tools return epee::net_utils::invoke_http_json_rpc(uri, method_name, req, res, m_http_client, timeout, http_method, req_id); } - void set_ring_database(const std::string &filename); + bool set_ring_database(const std::string &filename); const std::string get_ring_database() const { return m_ring_database; } bool get_ring(const crypto::key_image &key_image, std::vector &outs); bool get_rings(const crypto::hash &txid, std::vector>> &outs); From 269bfca62216cc05a87cd43bfdadf49b77df6ca1 Mon Sep 17 00:00:00 2001 From: wowario Date: Thu, 24 May 2018 13:42:33 +0300 Subject: [PATCH 25/25] Build: resolve merge conflicts --- .gitmodules | 2 +- external/CMakeLists.txt | 26 ++------ src/device/device.hpp | 15 +++-- src/device/device_default.cpp | 3 + src/device/device_default.hpp | 2 +- src/device/device_ledger.cpp | 108 +++++++++++++++++++--------------- src/device/device_ledger.hpp | 4 +- src/device/log.cpp | 1 + src/p2p/net_node.inl | 13 +--- 9 files changed, 87 insertions(+), 87 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9703c596a..00a81e58b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,5 +5,5 @@ branch = monero [submodule "external/miniupnp"] path = external/miniupnp - url = https://github.com/anonimal/miniupnp + url = https://github.com/monero-project/miniupnp branch = monero diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 4aa2c0ebf..1fc4d64c1 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -39,27 +39,13 @@ find_package(Miniupnpc REQUIRED) message(STATUS "Using in-tree miniupnpc") - set(UPNP_STATIC false PARENT_SCOPE) - set(UPNP_INCLUDE ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE) - set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE) -else() - if(STATIC) - message(STATUS "Using miniupnpc from local source tree for static build") - else() - message(STATUS "Using miniupnpc from local source tree (/external/miniupnp/miniupnpc)") - endif() - - add_subdirectory(miniupnp/miniupnpc) - - set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") - if(MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") - elseif(NOT MSVC) - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") - endif() +add_subdirectory(miniupnp/miniupnpc) - set(UPNP_STATIC true PARENT_SCOPE) - set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) +set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") +if(MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267") +elseif(NOT MSVC) + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value") endif() set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) diff --git a/src/device/device.hpp b/src/device/device.hpp index 91bc30c53..ce20c9165 100644 --- a/src/device/device.hpp +++ b/src/device/device.hpp @@ -78,6 +78,7 @@ namespace hw { return false; } + class device { protected: std::string name; @@ -89,10 +90,12 @@ namespace hw { virtual ~device() {} explicit virtual operator bool() const = 0; - - static const int SIGNATURE_REAL = 0; - static const int SIGNATURE_FAKE = 1; - + enum device_mode { + NONE, + TRANSACTION_CREATE_REAL, + TRANSACTION_CREATE_FAKE, + TRANSACTION_PARSE + }; /* ======================================================================= */ /* SETUP/TEARDOWN */ @@ -106,6 +109,9 @@ namespace hw { virtual bool connect(void) = 0; virtual bool disconnect(void) = 0; + virtual bool set_mode(device_mode mode) = 0; + + /* ======================================================================= */ /* LOCKER */ /* ======================================================================= */ @@ -198,4 +204,3 @@ namespace hw { device& get_device(const std::string device_descriptor) ; } - diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp index 3f7b8078d..0071f7d4f 100644 --- a/src/device/device_default.cpp +++ b/src/device/device_default.cpp @@ -82,6 +82,9 @@ namespace hw { dfns(); } + bool device_default::set_mode(device_mode mode) { + return true; + } /* ======================================================================= */ /* LOCKER */ diff --git a/src/device/device_default.hpp b/src/device/device_default.hpp index 649fed862..771fbba72 100644 --- a/src/device/device_default.hpp +++ b/src/device/device_default.hpp @@ -93,7 +93,7 @@ namespace hw { bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override; crypto::secret_key generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false) override; bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override; - bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations); + bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations) override; bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override; bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override; bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override; diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index c3a7938d6..aedaf8382 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -135,6 +135,10 @@ namespace hw { return sec == crypto::null_skey; } + bool operator==(const crypto::key_derivation &d0, const crypto::key_derivation &d1) { + return !memcmp(&d0, &d1, sizeof(d0)); + } + /* ===================================================================== */ /* === Device ==== */ /* ===================================================================== */ @@ -511,12 +515,13 @@ namespace hw { return true; } - bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) { + bool device_ledger::get_secret_keys(crypto::secret_key &vkey , crypto::secret_key &skey) { AUTO_LOCK_CMD(); - memset(viewkey.data, 0x00, 32); - memset(spendkey.data, 0xFF, 32); - #ifdef DEBUG_HWDEVICE + //secret key are represented as fake key on the wallet side + memset(vkey.data, 0x00, 32); + memset(skey.data, 0xFF, 32); + //spcialkey, normal conf handled in decrypt int offset; reset_buffer(); @@ -535,12 +540,22 @@ namespace hw { this->length_send = offset; this->exchange(); - //clear key - memmove(ledger::viewkey.data, this->buffer_recv+64, 32); - memmove(ledger::spendkey.data, this->buffer_recv+96, 32); + //View key is retrievied, if allowed, to speed up blockchain parsing + memmove(this->viewkey.data, this->buffer_recv+0, 32); + if (is_fake_view_key(this->viewkey)) { + MDEBUG("Have Not view key"); + this->has_view_key = false; + } else { + MDEBUG("Have view key"); + this->has_view_key = true; + } + + #ifdef DEBUG_HWDEVICE + memmove(dbg_viewkey.data, this->buffer_recv+0, 32); + memmove(dbg_spendkey.data, this->buffer_recv+32, 32); + #endif - #endif - return true; + return true; } bool device_ledger::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) { @@ -585,8 +600,6 @@ namespace hw { bool device_ledger::derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub){ AUTO_LOCK_CMD(); - int offset; - #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; crypto::key_derivation derivation_x; @@ -643,10 +656,10 @@ namespace hw { //pub key memmove(derived_pub.data, &this->buffer_recv[0], 32); - - #ifdef DEBUG_HWDEVICE - hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); - #endif + } + #ifdef DEBUG_HWDEVICE + hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data); + #endif return true; } @@ -1033,7 +1046,7 @@ namespace hw { bool device_ledger::generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) { AUTO_LOCK_CMD(); - int offset; + bool r = false; #ifdef DEBUG_HWDEVICE const crypto::public_key pub_x = pub; @@ -1080,16 +1093,39 @@ namespace hw { //derivattion data memmove(derivation.data, &this->buffer_recv[0], 32); + r = true; + } + #ifdef DEBUG_HWDEVICE + crypto::key_derivation derivation_clear ; + if ((this->mode == TRANSACTION_PARSE) && has_view_key) { + derivation_clear = derivation; + }else { + derivation_clear = hw::ledger::decrypt(derivation); + } + hw::ledger::check32("generate_key_derivation", "derivation", derivation_x.data, derivation_clear.data); + #endif - #ifdef DEBUG_HWDEVICE - crypto::key_derivation derivation_clear = hw::ledger::decrypt(derivation); - hw::ledger::check32("generate_key_derivation", "derivation", derivation_x.data, derivation_clear.data); - #endif - - - return true; + return r; } + bool device_ledger::conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations) { + const crypto::public_key *pkey=NULL; + if (derivation == main_derivation) { + pkey = &tx_pub_key; + MDEBUG("conceal derivation with main tx pub key"); + } else { + for(size_t n=0; n < additional_derivations.size();++n) { + if(derivation == additional_derivations[n]) { + pkey = &additional_tx_pub_keys[n]; + MDEBUG("conceal derivation with additionnal tx pub key"); + break; + } + } + } + ASSERT_X(pkey, "Mismatched derivation on scan info"); + return this->generate_key_derivation(*pkey, crypto::null_skey, derivation); + } + bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) { AUTO_LOCK_CMD(); int offset; @@ -1375,32 +1411,6 @@ namespace hw { return true; } - bool device_ledger::set_signature_mode(unsigned int sig_mode) { - AUTO_LOCK_CMD(); - int offset ; - - reset_buffer(); - - this->buffer_send[0] = 0x00; - this->buffer_send[1] = INS_SET_SIGNATURE_MODE; - this->buffer_send[2] = 0x01; - this->buffer_send[3] = 0x00; - this->buffer_send[4] = 0x00; - offset = 5; - //options - this->buffer_send[offset] = 0x00; - offset += 1; - //account - this->buffer_send[offset] = sig_mode; - offset += 1; - - this->buffer_send[4] = offset-5; - this->length_send = offset; - this->exchange(); - - return true; - } - bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) { AUTO_LOCK_CMD(); int offset; diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp index 90907616f..b62bdf959 100644 --- a/src/device/device_ledger.hpp +++ b/src/device/device_ledger.hpp @@ -39,6 +39,7 @@ #else #include #include +#endif #include #include @@ -138,6 +139,7 @@ namespace hw { bool connect(void) override; bool disconnect() override; + bool set_mode(device_mode mode) override; /* ======================================================================= */ /* LOCKER */ @@ -172,7 +174,7 @@ namespace hw { bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override; crypto::secret_key generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false) override; bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override; - bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations); + bool conceal_derivation(crypto::key_derivation &derivation, const crypto::public_key &tx_pub_key, const std::vector &additional_tx_pub_keys, const crypto::key_derivation &main_derivation, const std::vector &additional_derivations) override; bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override; bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override; bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override; diff --git a/src/device/log.cpp b/src/device/log.cpp index cbbcfc953..e581cb4cd 100644 --- a/src/device/log.cpp +++ b/src/device/log.cpp @@ -1,3 +1,4 @@ + // Copyright (c) 2017-2018, The Monero Project // // All rights reserved. diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 672850b36..17dcd8ef1 100755 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -49,16 +49,9 @@ #include "storages/levin_abstract_invoke2.h" #include "cryptonote_core/cryptonote_core.h" -// We have to look for miniupnpc headers in different places, dependent on if its compiled or external -#ifdef UPNP_STATIC - #include - #include - #include -#else - #include "miniupnpc.h" - #include "upnpcommands.h" - #include "upnperrors.h" -#endif +#include +#include +#include #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"