fix name handling during migration

This commit is contained in:
scgbckbone 2025-10-31 02:46:21 +01:00
parent 203c288de8
commit fa6a36140c
4 changed files with 78 additions and 11 deletions

View File

@ -829,7 +829,9 @@ async def done_signing(psbt, tx_req, input_method=None, filename=None,
data_sha2 = psram.checksum.digest()
# BBQR is at TMP_OUTPUT_OFFSET + 1MB - allowing it in this case would overwrite txn
allow_qr = data_len < (1024*1024)
# allow_qr = data_len < (1024*1024)
# actual more reasonable limit - as BBQR has some overhead and only 1Mbit of space
allow_qr = data_len < (671*1024)
if input_method == "usb":
# return result over USB before going to all options

View File

@ -24,7 +24,7 @@ TRUST_OFFER = const(1)
TRUST_PSBT = const(2)
MAX_BIP32_IDX = (2 ** 31) - 1
MAX_NAME_LEN = 20
MAX_NAME_LEN = 30 # use (almost) full potential of Q screen
class WalletOutOfSpace(RuntimeError):
pass
@ -1344,7 +1344,8 @@ def miniscript_640_migrate(old_serialization):
if ct != "BTC":
new_opts['ct'] = ct
return name, desc_tmplt, keys_info, new_opts
# previous version had unbounded names, cut it
return name[:MAX_NAME_LEN], desc_tmplt, keys_info, new_opts
async def multisig_640_migration(multisig_wallets):
@ -1357,7 +1358,8 @@ async def multisig_640_migration(multisig_wallets):
migrated_multi = []
# first element is always name, whether migrated or not
taken_names = [tup[0] for tup in settings.get("miniscript", [])]
# shorten to MAX_NAME_LEN that will be done to miniscript names upon migration
taken_names = [tup[0][:MAX_NAME_LEN] for tup in settings.get("miniscript", [])]
for i, ms in enumerate(multisig_wallets):
bip67 = 1 # default enabled, requires 5-element serialization to disable
if len(ms) == 5:
@ -1408,12 +1410,17 @@ async def multisig_640_migration(multisig_wallets):
if ct != "BTC":
new_opts['ct'] = ct
# this should not happen as multisg names were limited to 20 chars max
name = name[:MAX_NAME_LEN]
if name in taken_names:
# name collision with miniscript
name = name + "1"
if len(name) > MAX_NAME_LEN:
# issue
name = name[:15] + "mig1"
while name in taken_names:
suffix = str(ngu.random.uniform(100))
if (len(name) + len(suffix)) > MAX_NAME_LEN:
# issue
name = name[:MAX_NAME_LEN-len(suffix)]
name = name + suffix
migrated_multi.append((name, desc_tmplt, keys_info, new_opts))
dis.progress_sofar(i+1, total)

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
import pytest, time, base64, shutil
msc0 = ('msc0', 'XTN', 14, None,
['[0f056943/84h/1h/0h]tpubDC7jGaaSE66Pn4dgtbAAstde4bCyhSUs4r3P8WhMVvPByvcRrzrwqSvpF9Ghx83Z1LfVugGRrSBko5UEKELCz9HoMv5qKmGq3fqnnbS5E9r/<0;1>/*',
'[0f056943/84h/1h/0h]tpubDC7jGaaSE66Pn4dgtbAAstde4bCyhSUs4r3P8WhMVvPByvcRrzrwqSvpF9Ghx83Z1LfVugGRrSBko5UEKELCz9HoMv5qKmGq3fqnnbS5E9r/<2;3>/*'],
@ -458,6 +459,33 @@ def test_big_guys(microsd_path, src_root_dir, goto_home, pick_menu_item, need_ke
assert len(msc[0]) == 4 # new format
press_cancel()
def test_anchor_bug(goto_home, pick_menu_item, microsd_path, src_root_dir, press_select,
unit_test, cap_menu):
fname = "bonus101.txt"
shutil.copy(f"{src_root_dir}/testing/data/migration_640/{fname}", microsd_path(""))
# unit_test('devtest/clear_seed.py')
goto_home()
pick_menu_item("Advanced/Tools")
pick_menu_item("Danger Zone")
pick_menu_item("I Am Developer.")
pick_menu_item("Restore Bkup")
pick_menu_item(fname)
time.sleep(.1)
press_select()
time.sleep(.1)
press_select()
goto_home()
pick_menu_item("Settings")
pick_menu_item("Miniscript")
time.sleep(2)
m = cap_menu()
assert len(m) == 17
assert all(len(name) <= 30 for name in m)
def test_multisig_miniscript_migration(settings_append, clear_miniscript, settings_get,
settings_remove, settings_set, goto_home, pick_menu_item):
@ -496,10 +524,10 @@ def test_name_clash(settings_set, clear_miniscript, settings_remove, goto_home,
# length issue, name cannot be longer than 20 chars
# but adding '1' would cause length failure - need some replacing
new_ms2 = list(ms2)
new_ms2[0] = 20*"a"
new_ms2[0] = 35*"a"
new_msc16 = list(msc16)
new_msc16[0] = 20*"a"
new_msc16[0] = 31*"a"
settings_set("miniscript", [new_msc6, msc11, new_msc16])
settings_set("multisig", [ms0, ms1, new_ms2, ms3])
@ -511,6 +539,7 @@ def test_name_clash(settings_set, clear_miniscript, settings_remove, goto_home,
assert settings_get("multisig", None) is None
miniscripts = settings_get("miniscript")
assert [m[0] for m in miniscripts] == ["ms0", "msc11", 20*"a", "ms01", "ms1", 15*"a"+"mig1", "ms3"]
assert all([len(m[0]) <= 30 for m in miniscripts])
assert len(set([m[0] for m in miniscripts])) == 7
# EOF