@@ -338,8 +338,22 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction
338
338
return common.Address {}, nil , err
339
339
}
340
340
} else {
341
- if txrlp , err = rlp .EncodeToBytes ([]interface {}{tx .Nonce (), tx .GasPrice (), tx .Gas (), tx .To (), tx .Value (), tx .Data (), chainID , big .NewInt (0 ), big .NewInt (0 )}); err != nil {
342
- return common.Address {}, nil , err
341
+ if tx .Type () == types .DynamicFeeTxType {
342
+ if txrlp , err = rlp .EncodeToBytes ([]interface {}{chainID , tx .Nonce (), tx .GasTipCap (), tx .GasFeeCap (), tx .Gas (), tx .To (), tx .Value (), tx .Data (), tx .AccessList ()}); err != nil {
343
+ return common.Address {}, nil , err
344
+ }
345
+ // append type to transaction
346
+ txrlp = append ([]byte {tx .Type ()}, txrlp ... )
347
+ } else if tx .Type () == types .AccessListTxType {
348
+ if txrlp , err = rlp .EncodeToBytes ([]interface {}{chainID , tx .Nonce (), tx .GasPrice (), tx .Gas (), tx .To (), tx .Value (), tx .Data (), tx .AccessList ()}); err != nil {
349
+ return common.Address {}, nil , err
350
+ }
351
+ // append type to transaction
352
+ txrlp = append ([]byte {tx .Type ()}, txrlp ... )
353
+ } else if tx .Type () == types .LegacyTxType {
354
+ if txrlp , err = rlp .EncodeToBytes ([]interface {}{tx .Nonce (), tx .GasPrice (), tx .Gas (), tx .To (), tx .Value (), tx .Data (), chainID , big .NewInt (0 ), big .NewInt (0 )}); err != nil {
355
+ return common.Address {}, nil , err
356
+ }
343
357
}
344
358
}
345
359
payload := append (path , txrlp ... )
@@ -353,7 +367,9 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction
353
367
// Chunk size selection to mitigate an underlying RLP deserialization issue on the ledger app.
354
368
// https://github.com/LedgerHQ/app-ethereum/issues/409
355
369
chunk := 255
356
- for ; len (payload )% chunk <= ledgerEip155Size ; chunk -- {
370
+ if tx .Type () == types .LegacyTxType {
371
+ for ; len (payload )% chunk <= ledgerEip155Size ; chunk -- {
372
+ }
357
373
}
358
374
359
375
for len (payload ) > 0 {
@@ -381,8 +397,11 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction
381
397
if chainID == nil {
382
398
signer = new (types.HomesteadSigner )
383
399
} else {
384
- signer = types .NewEIP155Signer (chainID )
385
- signature [64 ] -= byte (chainID .Uint64 ()* 2 + 35 )
400
+ signer = types .LatestSignerForChainID (chainID )
401
+ // For non-legacy transactions, V is 0 or 1, no need to subtract here.
402
+ if tx .Type () == types .LegacyTxType {
403
+ signature [64 ] -= byte (chainID .Uint64 ()* 2 + 35 )
404
+ }
386
405
}
387
406
signed , err := tx .WithSignature (signer , signature )
388
407
if err != nil {
0 commit comments