diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-04-24 17:06:25 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-04-25 14:27:24 +0100 |
commit | efcecb42f3b7380a239c09aac5d57d4f93671463 (patch) | |
tree | d3450d2df2f1313e071c0c449d7f0cf3c2c250f8 /src/mnemonics | |
parent | Merge pull request #3670 (diff) | |
download | monero-efcecb42f3b7380a239c09aac5d57d4f93671463.tar.xz |
mnemonics: add some logs to help debug failures
Diffstat (limited to 'src/mnemonics')
-rw-r--r-- | src/mnemonics/electrum-words.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp index 6a2a3e0c4..7dd09ecb9 100644 --- a/src/mnemonics/electrum-words.cpp +++ b/src/mnemonics/electrum-words.cpp @@ -67,6 +67,9 @@ #include "language_base.h" #include "singleton.h" +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "mnemonic" + namespace { uint32_t create_checksum_index(const std::vector<std::string> &word_list, @@ -152,6 +155,7 @@ namespace if (full_match) { *language = *it1; + MINFO("Full match for language " << (*language)->get_english_language_name()); return true; } // Some didn't match. Clear the index array. @@ -164,9 +168,11 @@ namespace if (fallback) { *language = fallback; + MINFO("Fallback match for language " << (*language)->get_english_language_name()); return true; } + MINFO("No match found"); return false; } @@ -217,7 +223,9 @@ namespace checksum; std::string trimmed_last_word = last_word.length() > unique_prefix_length ? Language::utf8prefix(last_word, unique_prefix_length) : last_word; - return trimmed_checksum == trimmed_last_word; + bool ret = trimmed_checksum == trimmed_last_word; + MINFO("Checksum is %s" << (ret ? "valid" : "invalid")); + return ret; } } @@ -253,7 +261,10 @@ namespace crypto boost::split(seed, words, boost::is_any_of(" "), boost::token_compress_on); if (len % 4) + { + MERROR("Invalid seed: not a multiple of 4"); return false; + } bool has_checksum = true; if (len) @@ -263,6 +274,7 @@ namespace crypto if (seed.size() != expected/2 && seed.size() != expected && seed.size() != expected + 1) { + MERROR("Invalid seed: unexpected number of words"); return false; } @@ -274,6 +286,7 @@ namespace crypto Language::Base *language; if (!find_seed_language(seed, has_checksum, matched_indices, &language)) { + MERROR("Invalid seed: language not found"); return false; } language_name = language->get_language_name(); @@ -284,6 +297,7 @@ namespace crypto if (!checksum_test(seed, language->get_unique_prefix_length())) { // Checksum fail + MERROR("Invalid seed: invalid checksum"); return false; } seed.pop_back(); @@ -300,7 +314,11 @@ namespace crypto val = w1 + word_list_length * (((word_list_length - w1) + w2) % word_list_length) + word_list_length * word_list_length * (((word_list_length - w2) + w3) % word_list_length); - if (!(val % word_list_length == w1)) return false; + if (!(val % word_list_length == w1)) + { + MERROR("Invalid seed: mumble mumble"); + return false; + } dst.append((const char*)&val, 4); // copy 4 bytes to position } @@ -332,9 +350,15 @@ namespace crypto { std::string s; if (!words_to_bytes(words, s, sizeof(dst), true, language_name)) + { + MERROR("Invalid seed: failed to convert words to bytes"); return false; + } if (s.size() != sizeof(dst)) + { + MERROR("Invalid seed: wrong output size"); return false; + } dst = *(const crypto::secret_key*)s.data(); return true; } |