simplewallet: fix restore-date parameter when using generate-from-device
What changed, and why it matters
This commit fixes a bug in Monero's command-line wallet (simplewallet) when creating a wallet from a hardware device. Previously, if the user provided a restore date but no restore block height, the wallet ignored the date and started scanning from the current blockchain tip. This could cause the wallet to miss older transactions and make the user think funds were lost. The fix makes the wallet correctly convert the restore date into a block height and scan from there.
No immediate security action required. This is a reliability/UX fix. Users who created hardware-device wallets with --restore-date before this fix should rescan from the correct restore height if they suspect missing transactions.
Security signals we found
Functional bug that could cause missed transactions during wallet restore
No input validation bypass or memory corruption introduced
No cryptographic weakness identified
Fix adds explicit date parsing and error handling
Evidence from the diff
In simplewallet::init(), the generate-from-device path only checked whether arg_restore_height was defaulted to decide whether to start scanning from the current height. Because arg_restore_date was not considered, supplying –restore-date without –restore-height was silently ignored. The patch adds an else-if branch that, when only arg_restore_date is provided, parses the date string via datestr_to_int(), resolves it to a block height with get_blockchain_height_by_date(), and sets the wallet’s explicit refresh-from-block-height flag. This aligns the hardware-wallet restore path with the normal wallet restore behavior.
Changed components
src/simplewallet/simplewallet.cppsimplewallet::init()generate-from-device wallet creation flowInspect captured patch +19 / −2
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 69c66d0..5674656 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -4288,8 +4288,8 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
password = *r;
welcome = true;
- // if no block_height is specified, assume its a new account and start it "now"
- if (command_line::is_arg_defaulted(vm, arg_restore_height)) {
+ // if no block_height or date is specified, assume it's a new account and start it "now"
+ if (command_line::is_arg_defaulted(vm, arg_restore_height) && command_line::is_arg_defaulted(vm, arg_restore_date)) {
{
tools::scoped_message_writer wrt = tools::msg_writer();
wrt << tr("No restore height is specified.") << " ";
@@ -4304,6 +4304,23 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
m_wallet->explicit_refresh_from_block_height(true);
m_restore_height = m_wallet->get_refresh_from_block_height();
}
+ else if (command_line::is_arg_defaulted(vm, arg_restore_height) && !command_line::is_arg_defaulted(vm, arg_restore_date))
+ {
+ uint16_t year;
+ uint8_t month, day;
+ if (!datestr_to_int(m_restore_date, year, month, day)) return false;
+ try
+ {
+ m_restore_height = m_wallet->get_blockchain_height_by_date(year, month, day);
+ success_msg_writer() << tr("Restore height is: ") << m_restore_height;
+ }
+ catch (const std::runtime_error& e)
+ {
+ fail_msg_writer() << e.what();
+ return false;
+ }
+ m_wallet->explicit_refresh_from_block_height(true);
+ }
}
else
{
Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.