Skip to content

Commit 7a73ffe

Browse files
RekCuy63gballet
andauthored
accounts/usbwallet: check ledger versions for typed txs (#35044)
Checks the Ledger Ethereum app version before sending typed transactions that require newer app support. EIP-2930/EIP-1559 transactions now require Ledger app v1.9.0 or newer, and EIP-7702 transactions require v1.17.0 or newer. Older apps now return the same kind of local update error already used for earlier Ledger feature gates instead of sending an unsupported transaction to the device. --------- Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
1 parent 0ef867b commit 7a73ffe

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

accounts/usbwallet/ledger.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ func (w *ledgerDriver) offline() bool {
110110
return w.version == [3]byte{0, 0, 0}
111111
}
112112

113+
func ledgerVersionLessThan(version [3]byte, major, minor, patch byte) bool {
114+
if version[0] != major {
115+
return version[0] < major
116+
}
117+
if version[1] != minor {
118+
return version[1] < minor
119+
}
120+
return version[2] < patch
121+
}
122+
113123
// Open implements usbwallet.driver, attempting to initialize the connection to the
114124
// Ledger hardware wallet. The Ledger does not require a user passphrase, so that
115125
// parameter is silently discarded.
@@ -166,7 +176,19 @@ func (w *ledgerDriver) SignTx(path accounts.DerivationPath, tx *types.Transactio
166176
return common.Address{}, nil, accounts.ErrWalletClosed
167177
}
168178
// Ensure the wallet is capable of signing the given transaction
169-
if chainID != nil && (w.version[0] < 1 || (w.version[0] == 1 && w.version[1] == 0 && w.version[2] < 3)) {
179+
switch tx.Type() {
180+
case types.AccessListTxType, types.DynamicFeeTxType:
181+
if ledgerVersionLessThan(w.version, 1, 9, 0) {
182+
//lint:ignore ST1005 brand name displayed on the console
183+
return common.Address{}, nil, fmt.Errorf("Ledger version >= 1.9.0 required for EIP-2930/EIP-1559 signing (found version v%d.%d.%d)", w.version[0], w.version[1], w.version[2])
184+
}
185+
case types.SetCodeTxType:
186+
if ledgerVersionLessThan(w.version, 1, 17, 0) {
187+
//lint:ignore ST1005 brand name displayed on the console
188+
return common.Address{}, nil, fmt.Errorf("Ledger version >= 1.17.0 required for EIP-7702 signing (found version v%d.%d.%d)", w.version[0], w.version[1], w.version[2])
189+
}
190+
}
191+
if chainID != nil && ledgerVersionLessThan(w.version, 1, 0, 3) {
170192
//lint:ignore ST1005 brand name displayed on the console
171193
return common.Address{}, nil, fmt.Errorf("Ledger v%d.%d.%d doesn't support signing this transaction, please update to v1.0.3 at least", w.version[0], w.version[1], w.version[2])
172194
}
@@ -184,7 +206,7 @@ func (w *ledgerDriver) SignTypedMessage(path accounts.DerivationPath, domainHash
184206
return nil, accounts.ErrWalletClosed
185207
}
186208
// Ensure the wallet is capable of signing the given transaction
187-
if w.version[0] < 1 || (w.version[0] == 1 && w.version[1] < 5) {
209+
if ledgerVersionLessThan(w.version, 1, 5, 0) {
188210
//lint:ignore ST1005 brand name displayed on the console
189211
return nil, fmt.Errorf("Ledger version >= 1.5.0 required for EIP-712 signing (found version v%d.%d.%d)", w.version[0], w.version[1], w.version[2])
190212
}

0 commit comments

Comments
 (0)