From aab53c5c1ba3abe6f84d1c9c9722127cb7707ca1 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 27 Feb 2023 08:21:45 -0800 Subject: [PATCH 1/2] fix: mitigate ledger app chunking issue --- accounts/usbwallet/ledger.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/accounts/usbwallet/ledger.go b/accounts/usbwallet/ledger.go index cda94280fdd2..41df42b54626 100644 --- a/accounts/usbwallet/ledger.go +++ b/accounts/usbwallet/ledger.go @@ -59,6 +59,8 @@ const ( ledgerP1InitTransactionData ledgerParam1 = 0x00 // First transaction data block for signing ledgerP1ContTransactionData ledgerParam1 = 0x80 // Subsequent transaction data block for signing ledgerP2DiscardAddressChainCode ledgerParam2 = 0x00 // Do not return the chain code along with the address + + ledgerEip155Size int = 3; // Size of the EIP-155 chain_id,r,s in unsigned transactions ) // errLedgerReplyInvalidHeader is the error message returned by a Ledger data exchange @@ -347,9 +349,14 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction op = ledgerP1InitTransactionData reply []byte ) + + // Chunk size selection to mitigate an underlying RLP deserialization issue on the ledger app. + // https://github.com/LedgerHQ/app-ethereum/issues/409 + chunk := 255 + for ; len(payload) % chunk <= ledgerEip155Size; chunk-- {} + for len(payload) > 0 { // Calculate the size of the next data chunk - chunk := 255 if chunk > len(payload) { chunk = len(payload) } From e61909b6213fba06b98df3afd7bacdfa3136deaa Mon Sep 17 00:00:00 2001 From: James Date: Tue, 28 Feb 2023 10:08:45 -0800 Subject: [PATCH 2/2] lint: run gofmt --- accounts/usbwallet/ledger.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/accounts/usbwallet/ledger.go b/accounts/usbwallet/ledger.go index 41df42b54626..723df0f2b352 100644 --- a/accounts/usbwallet/ledger.go +++ b/accounts/usbwallet/ledger.go @@ -60,7 +60,7 @@ const ( ledgerP1ContTransactionData ledgerParam1 = 0x80 // Subsequent transaction data block for signing ledgerP2DiscardAddressChainCode ledgerParam2 = 0x00 // Do not return the chain code along with the address - ledgerEip155Size int = 3; // Size of the EIP-155 chain_id,r,s in unsigned transactions + ledgerEip155Size int = 3 // Size of the EIP-155 chain_id,r,s in unsigned transactions ) // errLedgerReplyInvalidHeader is the error message returned by a Ledger data exchange @@ -353,7 +353,8 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction // Chunk size selection to mitigate an underlying RLP deserialization issue on the ledger app. // https://github.com/LedgerHQ/app-ethereum/issues/409 chunk := 255 - for ; len(payload) % chunk <= ledgerEip155Size; chunk-- {} + for ; len(payload)%chunk <= ledgerEip155Size; chunk-- { + } for len(payload) > 0 { // Calculate the size of the next data chunk