LedgerHQ / btchip-python

Ledger HW.1 Python API
http://www.ledger.co
Apache License 2.0
65 stars 51 forks source link

Invalid Status 6a80 when signing #25

Closed molecular closed 7 years ago

molecular commented 7 years ago

Hi, an electron-cash user has problems signing using his Ledger Blue (same with his ledger nano s).

Traceback (most recent call last):
File "/home/steffen/Desktop/Electron Cash-2.9.3/plugins/ledger/ledger.py", line 411, in sign_transaction
inputSignature = self.get_client().untrustedHashSign(inputsPaths[inputIndex], pin, lockTime=tx.locktime)
File "/usr/lib/python2.7/dist-packages/btchip/btchip.py", line 387, in untrustedHashSign
result = self.dongle.exchange(bytearray(apdu))
File "/usr/lib/python2.7/dist-packages/btchip/btchipComm.py", line 119, in exchange
raise BTChipException("Invalid status %04x" % sw, sw)
BTChipException: Exception : Invalid status 6a80
Exception : Invalid status 6a80
Traceback (most recent call last):
File "/home/steffen/Desktop/Electron Cash-2.9.3/gui/qt/util.py", line 582, in run
result = task.task()
File "/home/steffen/Desktop/Electron Cash-2.9.3/lib/wallet.py", line 1104, in sign_transaction
k.sign_transaction(tx, password)
File "/home/steffen/Desktop/Electron Cash-2.9.3/plugins/ledger/ledger.py", line 422, in sign_transaction
self.give_error(e, True)
File "/home/steffen/Desktop/Electron Cash-2.9.3/plugins/ledger/ledger.py", line 201, in give_error
raise Exception(message)
Exception: Exception : Invalid status 6a80

in reference to electron-cash issue fyookball/electrum#153, especially this comment by the user: https://github.com/fyookball/electrum/issues/153#issuecomment-333367668

This might not be a btchip issue, but I'm not familiar enough with this signing process to be able to figure out what's going on here.

Any help appreciated.

SteffenIvanhoe commented 7 years ago

It is not only related to Ledger Blue. I have the exact same problem with the Ledger Nano S.

molecular commented 7 years ago

accidentally closed the issue, sorry

corrected OP to include ledger nano s

btchip commented 7 years ago

You need to sign according to the Segwit flow (see Electrum support)

SteffenIvanhoe commented 7 years ago

Bitcoin Cash and Segwit???

btchip commented 7 years ago

Bitcoin Cash uses BIP 143 which is Segwit signature algorithm

SteffenIvanhoe commented 7 years ago

I'm a little bit surprised that the same software version in Electrum 2.9.3 works with Bitcoin on Ledger hardware but not in ElectronCash 2.9.3 with Bitcoin Cash? Does Bitcoin not use BIP 143 signature algorithm?

btchip commented 7 years ago

Bitcoin uses BIP 143 for Segwit transactions which are opt in. It is mandatory for Bitcoin Cash

SteffenIvanhoe commented 7 years ago

Interesting, thank you for the information!

Unfortunately it does not really help me because I'm not the developer of the ElectronCash software but only a user who is desperately looking for a method to get BCC transferred from the Ledger wallet address wise without linking addresses together. Unfortunately standard Ledger software is a privacy killer and allows zero control here.

What algorithm does the Ledger software use to come up with the next address(es) used for a send operation? Maybe knowing that makes it possible to manually set amounts such that addresses can be send on their own?

SteffenIvanhoe commented 7 years ago

An off-topic but related comment:

I just found out that even if a transaction including the fees does match the amount contained in one address to the last satoshi the Ledger software rather selects a different address for the send and prefers to create change. Makes no sense to me! You should at least have this little bit of optimization to find a perfectly matching address for a send if one exists, e.g. when send amount plus fees do match the content of an address in the wallet exactly. Isn't that an easy change for the Ledger software? Would help people who know about it to create precise transfers for one address.

Of course an optional address selection box or a "Send all from a given address" mechanism would also do but are "slightly" more complicated to add to the user interface.

molecular commented 7 years ago

Signing using ledger devices (at least the btchip usb device I have) works in electron-cash. What makes this case special? I don't get it.

btchip commented 7 years ago

if the signature has already been patched then I have no idea

molecular commented 7 years ago

Thanks for your info. I re-tested signing with my hw.1 and apparently it doesn't work. I thought I had tested this successfully a while ago, but apparently not ;-(. I don't think bip 143 signing has been implemented in electron-cash.

Sorry for the waves and thanks for your input, @btchip

btchip commented 7 years ago

ok, I'll close this as the library itself works fine with Electrum and should also work fine with Electrum Cash once called with the right flow

molecular commented 7 years ago

ok, thanks for you help