trezor / python-shamir-mnemonic

MIT License
166 stars 59 forks source link

release 0.3.0 broke backwards compat. old versions cannot recover new seeds. `ERROR: Invalid mnemonic checksum for ...` #48

Open SomberNight opened 1 month ago

SomberNight commented 1 month ago

Shares generated by version 0.3.0 are rejected during recovery in old versions. In particular, shares I generate with 0.3.0 cannot be used to restore with in Electrum.

user@user-VirtualBox:~/wspace/tmp$ python3 -m venv env30
user@user-VirtualBox:~/wspace/tmp$ source env30/bin/activate
(env30) user@user-VirtualBox:~/wspace/tmp$ pip install shamir-mnemonic[cli]==0.3.0
Collecting shamir-mnemonic[cli]==0.3.0
  Downloading shamir_mnemonic-0.3.0-py3-none-any.whl (23 kB)
Collecting click<9,>=7
  Using cached click-8.1.7-py3-none-any.whl (97 kB)
Installing collected packages: shamir-mnemonic, click
Successfully installed click-8.1.7 shamir-mnemonic-0.3.0
(env30) user@user-VirtualBox:~/wspace/tmp$ shamir create 2of3 --master-secret="5be935613b67a9d53bfafe03fab5e92ea5bcacc6449cf151714730cdf366b0a7e0a644d571aa2559f201f193231e9dab7a4eb9b2854a19536d2e0fc9bc3d7cc8"
Using master secret: 5be935613b67a9d53bfafe03fab5e92ea5bcacc6449cf151714730cdf366b0a7e0a644d571aa2559f201f193231e9dab7a4eb9b2854a19536d2e0fc9bc3d7cc8
Group 1 of 1 - 2 of 3 shares required:
species biology academic acid acne depart vintage object aluminum grumpy friar season therapy dynamic ivory tracks large spark leaf pleasure dragon dish junction capture render founder marathon tackle float step maiden loud should trust permit decrease total enemy that privacy midst maximum armed mandate carve have symbolic armed payroll news seafood density segment frequent perfect spelling year deadline gesture
species biology academic agency acquire reunion unfair darkness prayer cubic guest glad energy database video patrol smell laden literary sled amount review crucial national river hush lawsuit square inmate training trouble wavy garlic express royal guard mason lend source diminish custody fitness flip rainbow miracle guitar listen course render industry satisfy soldier crucial machine snapshot sheriff bracelet yield mandate
species biology academic always acid critical greatest iris findings vintage listen sidewalk relate carve idle priest aide main document chubby fused fumes steady armed prospect aluminum sunlight smear adjust relate express dryer listen patent hormone organize depart smell learn omit velvet extend physics provide cards already slap round mild elevator slap python agree visual exhaust tracks mild race tension
(env30) user@user-VirtualBox:~/wspace/tmp$ 
user@user-VirtualBox:~/wspace/tmp$ python3 -m venv env22
user@user-VirtualBox:~/wspace/tmp$ source env22/bin/activate
(env22) user@user-VirtualBox:~/wspace/tmp$ pip install shamir-mnemonic==0.2.2
Collecting shamir-mnemonic==0.2.2
  Using cached shamir_mnemonic-0.2.2-py3-none-any.whl (22 kB)
Collecting colorama
  Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting attrs
  Using cached attrs-23.2.0-py3-none-any.whl (60 kB)
Collecting click<9,>=7
  Using cached click-8.1.7-py3-none-any.whl (97 kB)
Installing collected packages: colorama, click, attrs, shamir-mnemonic
Successfully installed attrs-23.2.0 click-8.1.7 colorama-0.4.6 shamir-mnemonic-0.2.2
(env22) user@user-VirtualBox:~/wspace/tmp$ shamir recover
Enter a recovery share: species biology academic acid acne depart vintage object aluminum grumpy friar season therapy dynamic ivory tracks large spark leaf pleasure dragon dish junction capture render founder marathon tackle float step maiden loud should trust permit decrease total enemy that privacy midst maximum armed mandate carve have symbolic armed payroll news seafood density segment frequent perfect spelling year deadline gesture
ERROR: Invalid mnemonic checksum for "species biology academic acid ...".
Enter a recovery share: 

Note that the other direction works: shares generated by old versions are accepted by 0.3.0.

prusnak commented 1 month ago

Yes. This is intended. You need to bump the version of dependency to 0.3.0.

SomberNight commented 1 month ago

I see. Thanks. Perhaps this is something that should be mentioned in the changelog then. :)

prusnak commented 1 month ago

Perhaps this is something that should be mentioned in the changelog then. :)

I agree - cc @matejcik

matejcik commented 1 month ago

you can pass -X to shamir create to get shares compatible with the old version. I suppose an entry in "incompatible" is in order, I will add it but probably won't be re-releasing for it :woman_shrugging:

A PR that fixes the problem in Electrum is being worked on. I intended to send a PR that adds shamir-mnemonic as a dependency directly but ran into problem with i18n for the error messages, because they're hardcoded on the library side so more work would be needed. I fully intend to resolve that (in 0.3.1 perhaps?) but not in the short term.