mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 18:47:36 -07:00
Merge pull request #3700
efcecb4
mnemonics: add some logs to help debug failures (moneromooo-monero)
This commit is contained in:
commit
a915d49307
@ -67,6 +67,9 @@
|
|||||||
#include "language_base.h"
|
#include "language_base.h"
|
||||||
#include "singleton.h"
|
#include "singleton.h"
|
||||||
|
|
||||||
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
|
#define MONERO_DEFAULT_LOG_CATEGORY "mnemonic"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
uint32_t create_checksum_index(const std::vector<std::string> &word_list,
|
uint32_t create_checksum_index(const std::vector<std::string> &word_list,
|
||||||
@ -152,6 +155,7 @@ namespace
|
|||||||
if (full_match)
|
if (full_match)
|
||||||
{
|
{
|
||||||
*language = *it1;
|
*language = *it1;
|
||||||
|
MINFO("Full match for language " << (*language)->get_english_language_name());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Some didn't match. Clear the index array.
|
// Some didn't match. Clear the index array.
|
||||||
@ -164,9 +168,11 @@ namespace
|
|||||||
if (fallback)
|
if (fallback)
|
||||||
{
|
{
|
||||||
*language = fallback;
|
*language = fallback;
|
||||||
|
MINFO("Fallback match for language " << (*language)->get_english_language_name());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MINFO("No match found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +223,9 @@ namespace
|
|||||||
checksum;
|
checksum;
|
||||||
std::string trimmed_last_word = last_word.length() > unique_prefix_length ? Language::utf8prefix(last_word, unique_prefix_length) :
|
std::string trimmed_last_word = last_word.length() > unique_prefix_length ? Language::utf8prefix(last_word, unique_prefix_length) :
|
||||||
last_word;
|
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);
|
boost::split(seed, words, boost::is_any_of(" "), boost::token_compress_on);
|
||||||
|
|
||||||
if (len % 4)
|
if (len % 4)
|
||||||
|
{
|
||||||
|
MERROR("Invalid seed: not a multiple of 4");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool has_checksum = true;
|
bool has_checksum = true;
|
||||||
if (len)
|
if (len)
|
||||||
@ -263,6 +274,7 @@ namespace crypto
|
|||||||
if (seed.size() != expected/2 && seed.size() != expected &&
|
if (seed.size() != expected/2 && seed.size() != expected &&
|
||||||
seed.size() != expected + 1)
|
seed.size() != expected + 1)
|
||||||
{
|
{
|
||||||
|
MERROR("Invalid seed: unexpected number of words");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +286,7 @@ namespace crypto
|
|||||||
Language::Base *language;
|
Language::Base *language;
|
||||||
if (!find_seed_language(seed, has_checksum, matched_indices, &language))
|
if (!find_seed_language(seed, has_checksum, matched_indices, &language))
|
||||||
{
|
{
|
||||||
|
MERROR("Invalid seed: language not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
language_name = language->get_language_name();
|
language_name = language->get_language_name();
|
||||||
@ -284,6 +297,7 @@ namespace crypto
|
|||||||
if (!checksum_test(seed, language->get_unique_prefix_length()))
|
if (!checksum_test(seed, language->get_unique_prefix_length()))
|
||||||
{
|
{
|
||||||
// Checksum fail
|
// Checksum fail
|
||||||
|
MERROR("Invalid seed: invalid checksum");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
seed.pop_back();
|
seed.pop_back();
|
||||||
@ -300,7 +314,11 @@ namespace crypto
|
|||||||
val = w1 + word_list_length * (((word_list_length - w1) + w2) % word_list_length) +
|
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);
|
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
|
dst.append((const char*)&val, 4); // copy 4 bytes to position
|
||||||
}
|
}
|
||||||
@ -332,9 +350,15 @@ namespace crypto
|
|||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
if (!words_to_bytes(words, s, sizeof(dst), true, language_name))
|
if (!words_to_bytes(words, s, sizeof(dst), true, language_name))
|
||||||
|
{
|
||||||
|
MERROR("Invalid seed: failed to convert words to bytes");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (s.size() != sizeof(dst))
|
if (s.size() != sizeof(dst))
|
||||||
|
{
|
||||||
|
MERROR("Invalid seed: wrong output size");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
dst = *(const crypto::secret_key*)s.data();
|
dst = *(const crypto::secret_key*)s.data();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user