-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Ledger plugin is currently broken for old Ledgers HW1 (can get account addresses, but Electrum hanging when signing a Tx) #7022
Comments
I've just tested on git master with an old Ledger HW.1 on testnet and I could spend coins from Note that the HW.1 (1) cannot spend from Re (1) one could already not create such a wallet, the wizard gives an error.
Yes, electrum/electrum/plugins/ledger/ledger.py Line 571 in b56fe23
Note that if you will be using the Console tab in the Qt GUI, depending on how you log, you should monitor both the Console tab itself and stdout/stderr. I recommend you start Electrum from the terminal, with the |
Ok, thanks, maybe that was the issue. I just received a report from another user, but I don't yet have a HW.1 device to test myself. So, it should work only when sending from a legacy address to either a legacy address (starts with 1) or a p2wpkh address (starts with 2 or 3), right? The user sent me a screenshot that says "read error" after they entered their PIN to get the Tx signed. I will run some tests after I receive my HW.1 device. Thanks again for all the advice! |
So the HW.1 can spend from
I did not manage to get a "read error" in any of the scenarios. |
I can confirm that Electrum does not work with the Ledger 1 (i.e. according to the Ledger company, same hardware as the ledger HW.1 with a different packaging. It has no screen and no buttons). It was tested on Mac, Win10 and Linux. Test was a transfer to a legacy address. I have attached the log file obtained using the -v option on Linux. |
We did some mode debugging and we found out the one particular call causes the ledger to disconnect (and Electrum to stay hanging). The call is line 503 of the ledger.py plugin: 503: outputData = client_ledger.finalizeInput(b'', 0, 0, changePath, bfh(rawTx)) The parameters are: rawTx = 0200000001c16dae699593c713bd04709fad1474d9ed1e140ef3fb43af9815da948711e89500000000230021022a5c4bdac8788757528feef374a16370ce9fffeb685ea7337c6d8eb514055c35fdffffff02a0860100000000001976a914f814983680610d9833cb00581c6aefb4a7c066de88ace4117800000000001976a914d732eccc8898cd964d033e23e7432ed298de29d688accc3c0a00 I could not find any Python code for finalizeInput, so I imagine that this is defined in a library from Ledger? Let me know what you think. Below is the decoded rawTx: (using https://live.blockcypher.com/btc/decodetx/) |
Yes, it is here: Maybe the reason I cannot reproduce is due to firmware version differences? You can get the firmware version using the "Console" tab (
|
Ok, I'll try, thanks! |
here is the version: {'compressedKeys': True, 'version': '1.0.0', 'specialVersion': 32} Here is more info, from https://www.reddit.com/r/ledgerwallet/comments/lf8bf9/are_the_discontinued_ledger_nano_1_and_ledger_hw1/gntl5ez/?utm_source=reddit&utm_medium=web2x&context=3 The issue occurs when this function is called: outputData = client_ledger.finalizeInput(b'', 0, 0, changePath, bfh(rawTx)) => b'e04aff0015058000002c80000000800000000000000100000000' <= b''6985 => b'e0460200260000000000000000000000000000000000058000002c80000000800000000000000100000000' at that point device disconnects... Not sure exactly if it disconnects just after returning the error, or after receiving the next call (that does not get any answer)... I see somewhere that error code 6985 means: Wrong Device Status - correct? What would be the correct way to put it in the correct "status" before calling finalizeInput ? Maybe that's what is missing, somehow? The call causing the 6985 error is this block:
with changePath = "44'/0'/0'/1/0" and donglePath derived from changePath: donglePath = parse_bip32_path(changePath) The parameter seems just correct in the call to the ledger, as you can see. because of the error code returned, an Exception is raised by dongle.exchange, which is ignored in ledger.py (i checked that we pass in the Exception block):
Maybe this Ledger needs to be put it in the correct "status" before calling finalizeInput (or before setting the donglePath, which returns an error)? Maybe that's what is missing, somehow? Maybe the PIN needs to be sent again to set the ledger in the correct mode? |
That is a very old version. It is almost certainly the cause of the issue. Your best bet would be to upgrade the firmware somehow. Barring that, you could look at the git blame and patch the code to make the library (btchip-python) method calls more similar to what the old code was doing. Maybe try this patch: diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py
index c6797e9231..f2a3210990 100644
--- a/electrum/plugins/ledger/ledger.py
+++ b/electrum/plugins/ledger/ledger.py
@@ -480,9 +480,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
if segwitTransaction:
client_ledger.startUntrustedTransaction(True, inputIndex,
chipInputs, redeemScripts[inputIndex], version=tx.version)
- # we don't set meaningful outputAddress, amount and fees
- # as we only care about the alternateEncoding==True branch
- outputData = client_ledger.finalizeInput(b'', 0, 0, changePath, bfh(rawTx))
+ outputData = client_ledger.finalizeInputFull(txOutput)
outputData['outputData'] = txOutput
if outputData['confirmationNeeded']:
outputData['address'] = output
@@ -507,9 +505,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
while inputIndex < len(inputs):
client_ledger.startUntrustedTransaction(firstTransaction, inputIndex,
chipInputs, redeemScripts[inputIndex], version=tx.version)
- # we don't set meaningful outputAddress, amount and fees
- # as we only care about the alternateEncoding==True branch
- outputData = client_ledger.finalizeInput(b'', 0, 0, changePath, bfh(rawTx))
+ outputData = client_ledger.finalizeInputFull(txOutput)
outputData['outputData'] = txOutput
if outputData['confirmationNeeded']:
outputData['address'] = output Why are you still using a Ledger HW.1 anyway? |
Thanks! So maybe we could even test the HW1 firmware version and use the old API conditionally?
I am working on a recovery for a client who lost their seed, and have a large sum in BTC still controlled by this very old ledger device, for which they still have the PIN. Upgrading the firmware is not possible on this device. I'll try your suggestion. But in that case, since the "change" path is not specified, will the "change" always be sent to one of the input address? |
Maybe... if we fully understood what is going on. It would be better if someone who does suggested a patch.
Given your firmware is very old, this patch might only work if there is just a single output (no change). I don't know. I cannot test. Again, feel free to look around using git blame. |
Thanks! I will definitely look at the Tx before sending it to the network. I may be able to test using an old HW1 ledger that I should receive in a few days. I asked btchip to confirm whether they think it could work. Based on comments in btchip.py, it looks like the old API must be used "before firmware 1.0.2", i.e. 1.0.0 and 1.0.1 presumably... |
So we did the test using exactly the modified code according to
We still get an error: Due to the error an exception is thrown by self.dongle.exchange(...), and since the block finalizeInputFull has no "try", the exception get caught higher by Electrum. |
Try using an old version of Electrum. E.g. 2.7.x, just to create and sign the tx, and then broadcast it elsewhere (or using new version). |
Yeah, but I would have to hard-code a lot of things, like the account balances etc, so it would probably not be fun. Maybe recovering the ledger.py and the btchip.py (and its dependencies) from may 2015 could still work in the current Electrum, if the Electrum plugin API has not changed too much? |
@loupiote Did you solve this problem? I have an old Ledger HW1 with an almost as old firmware:
I have tried using several versions of Electrum and I get the |
See https://www.reddit.com/r/ledgerwallet/comments/m4pk7q/successful_recovery_of_btc_from_a_hw1_ledger/ |
FYI We are able to recover from those old ledger (older than 1.0.2), that are unsupported by Electrum. |
@loupiote |
Maybe consider contributing code to the project to fix the issue... |
Hi,
i would like to, but I have no solution...
I'm asking loupiote who succeded...
Eric
…------ Message d'origine ------
De: "ghost43" ***@***.***>
À: "spesmilo/electrum" ***@***.***>
Cc : "ericlau792" ***@***.***>; "Comment"
***@***.***>
Envoyé : 21/07/2021 15:39:36
Objet : Re: [spesmilo/electrum] The Ledger plugin is currently broken
for old Ledgers HW1 (can get account addresses, but Electrum hanging
when signing a Tx) (#7022)
Maybe consider contributing code to the project to fix the issue...
But I guess that might not help your business model of helping users
privately :)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7022 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALDGMBAAFHV6N2GEKQQCQ3DTY3EZRANCNFSM4XPXCEFA>.
|
Right, my comment was aimed at them :) |
Not only it would not help our business model, but our recovery code is very unsafe for public consumption since it is a hack that is very poorly tested, and almost impossible to test due to the scarcity of those antiquated ledger devices with the very early firmware. The raw transactions that we generate for the recovery must be decompiled and manually checked, before being manually sent to the Bitcoin network. If people were using this code, many would likely lose large amount of BTC, and may turn against the author of the code. @ericlau792 contact us privately via loupiote [at] gmail |
Please advice , what is the resolution for this issue? I am not a developer, rather an end user and struggling to send BTC out of my Electrum wallet. The electrum wallet is configured to use the Ledger X BTC app. I am trying to send BTC to an address starting with "3" |
@raghavkashi If you are using a Ledger Nano X, your issue does not have anything to do with the issue discussed in this thread., which is about Ledger HW-1. In addition, you can also use Ledger Live to get access to your segwit account (address starting with "3"). You don't need to use Electrum. Also, Electrum does not have any issue communicating with ledger Nano X and S (but in some cases you may have to run Electrum in Administrator mode). Feel free to contact us privately via loupiote [at] gmail. |
The Ledger plugin is currently broken for old Ledgers HW1 (the type of ledger hardware wallets that have no display). Electrum displays a "read error" pop-up when attempting to send (i.e. to sign a Tx). Electrum is capable of getting the account addresses and display the balances, so communication with the WD1 ledger is working, but not possible to sign the Tx and send BTC (using Electrum 4.0.9).
I could maybe try to find the problem myself. What would you recommend to debug an Electrum Plugin?
I.e. if I need to print things from within the ledger.py plugin, should I use the regular Python print() or is there a way to print in the Electrum console? (I'll be using Linux)
The text was updated successfully, but these errors were encountered: