1
0

wallet_db version 52: break non-homogeneous multisig wallets

- case 1: in version 4.4.1, 4.4.2, the qml GUI wizard allowed creating multisig wallets with an old_mpk as cosigner.
- case 2: in version 4.4.0, 4.4.1, 4.4.2, the qml GUI wizard allowed creating multisig wallets with mixed xpub/Ypub/Zpub.

The corresponding missing input validation was a bug in the wizard, it was unintended behaviour. Validation was added in d2cf21fc2b. Note however that there might be users who created such wallet files.

Re case 1 wallet files: there is no version of Electrum that allows spending from such a wallet. Coins received at addresses are not burned, however it is technically challenging to spend them. (unless the multisig can spend without needing the old_mpk cosigner in the quorum).

Re case 2 wallet files: it is possible to create a corresponding spending wallet for such a multisig, however it is a bit tricky. The script type for the addresses in such a heterogeneous xpub wallet is based on the xpub_type of the first keystore. So e.g. given a wallet file [Yprv1, Zpub2] it will have sh(wsh()) scripts, and the cosigner should create a wallet file [Ypub1, Zprv2] (same order).

Technically case 2 wallet files could be "fixed" automatically by converting the xpub types as part of a wallet_db upgrade. However if the wallet files also contain seeds, those cannot be converted ("standard" vs "segwit" electrum seed).
Case 1 wallet files are not possible to "fix" automatically as the cosigner using the old_mpk is not bip32 based.

It is unclear if there are *any* users out there affected by this. I suspect for case 1 it is very likely there are none (not many people have pre-2.0 electrum seeds which were never supported as part of a multisig who would also now try to create a multisig using them); for case 2 however there might be.

This commit breaks both case 1 and case 2 wallets: these wallet files can no longer be opened in new Electrum, an error message is shown and the crash reporter opens. If any potential users opt to send crash reports, at least we will know they exist and can help them recover.
This commit is contained in:
SomberNight
2023-05-11 13:48:54 +00:00
parent d2cf21fc2b
commit 68fb996d20
7 changed files with 111 additions and 34 deletions

View File

@@ -495,7 +495,7 @@ ApplicationWindow
}
function onWalletOpenError(error) {
console.log('wallet open error')
var dialog = app.messageDialog.createObject(app, {'text': error})
var dialog = app.messageDialog.createObject(app, { title: qsTr('Error'), 'text': error })
dialog.open()
}
function onAuthRequired(method, authMessage) {

View File

@@ -223,7 +223,7 @@ class QEDaemon(AuthMixin, QObject):
self._backendWalletLoaded.emit(local_password)
except WalletFileException as e:
self._logger.error(str(e))
self._logger.error(f"load_wallet_task errored opening wallet: {e!r}")
self.walletOpenError.emit(str(e))
finally:
self._loading = False

View File

@@ -8,7 +8,7 @@ from electrum.storage import WalletStorage, StorageEncryptionVersion
from electrum.wallet_db import WalletDB
from electrum.wallet import Wallet
from electrum.bip32 import normalize_bip32_derivation, xpub_type
from electrum.util import InvalidPassword, WalletFileException
from electrum.util import InvalidPassword, WalletFileException, send_exception_to_crash_reporter
from electrum import keystore
if TYPE_CHECKING:
@@ -120,9 +120,16 @@ class QEWalletDB(QObject):
@pyqtSlot()
def verify(self):
self.load_storage()
if self._storage:
self.load_db()
try:
self._load_storage()
if self._storage:
self._load_db()
except WalletFileException as e:
self._logger.error(f"verify errored: {repr(e)}")
self._storage = None
self.walletOpenProblem.emit(str(e))
if e.should_report_crash:
send_exception_to_crash_reporter(e)
@pyqtSlot()
def doSplit(self):
@@ -134,7 +141,8 @@ class QEWalletDB(QObject):
self.splitFinished.emit()
def load_storage(self):
def _load_storage(self):
"""can raise WalletFileException"""
self._storage = WalletStorage(self._path)
if not self._storage.file_exists():
self._logger.warning('file does not exist')
@@ -170,27 +178,23 @@ class QEWalletDB(QObject):
if not self._storage.is_past_initial_decryption():
self._storage = None
def load_db(self):
def _load_db(self):
"""can raise WalletFileException"""
# needs storage accessible
try:
self._db = WalletDB(self._storage.read(), manual_upgrades=True)
if self._db.requires_split():
self._logger.warning('wallet requires split')
self._requiresSplit = True
self.requiresSplitChanged.emit()
return
if self._db.get_action():
self._logger.warning('action pending. QML version doesn\'t support continuation of wizard')
return
self._db = WalletDB(self._storage.read(), manual_upgrades=True)
if self._db.requires_split():
self._logger.warning('wallet requires split')
self._requiresSplit = True
self.requiresSplitChanged.emit()
return
if self._db.get_action():
self._logger.warning('action pending. QML version doesn\'t support continuation of wizard')
return
if self._db.requires_upgrade():
self._logger.warning('wallet requires upgrade, upgrading')
self._db.upgrade()
self._db.write(self._storage)
if self._db.requires_upgrade():
self._logger.warning('wallet requires upgrade, upgrading')
self._db.upgrade()
self._db.write(self._storage)
self._ready = True
self.readyChanged.emit()
except WalletFileException as e:
self._logger.error(f'{repr(e)}')
self._storage = None
self.walletOpenProblem.emit(str(e))
self._ready = True
self.readyChanged.emit()

View File

@@ -342,10 +342,13 @@ class ElectrumGui(BaseElectrumGui, Logger):
wallet = self.daemon.load_wallet(path, None)
except Exception as e:
self.logger.exception('')
err_text = str(e) if isinstance(e, WalletFileException) else repr(e)
custom_message_box(icon=QMessageBox.Warning,
parent=None,
title=_('Error'),
text=_('Cannot load wallet') + ' (1):\n' + repr(e))
text=_('Cannot load wallet') + ' (1):\n' + err_text)
if isinstance(e, WalletFileException) and e.should_report_crash:
send_exception_to_crash_reporter(e)
# if app is starting, still let wizard appear
if not app_is_starting:
return
@@ -364,10 +367,13 @@ class ElectrumGui(BaseElectrumGui, Logger):
window = self._create_window_for_wallet(wallet)
except Exception as e:
self.logger.exception('')
err_text = str(e) if isinstance(e, WalletFileException) else repr(e)
custom_message_box(icon=QMessageBox.Warning,
parent=None,
title=_('Error'),
text=_('Cannot load wallet') + '(2) :\n' + repr(e))
text=_('Cannot load wallet') + '(2) :\n' + err_text)
if isinstance(e, WalletFileException) and e.should_report_crash:
send_exception_to_crash_reporter(e)
if app_is_starting:
# If we raise in this context, there are no more fallbacks, we will shut down.
# Worst case scenario, we might have gotten here without user interaction,