From 36520d8199a871a88f0d12db44ed729e1e4a3fb6 Mon Sep 17 00:00:00 2001 From: DeFi Junkie Date: Thu, 21 May 2026 16:31:26 +0300 Subject: [PATCH] accounts/usbwallet: add support for blob and setcode transactions (#33797) Adds Ledger signing support for BlobTxType (EIP-4844) and SetCodeTxType (EIP-7702) transactions. --------- Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com> --- accounts/usbwallet/ledger.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/accounts/usbwallet/ledger.go b/accounts/usbwallet/ledger.go index 80e63f1864..79ff5929ba 100644 --- a/accounts/usbwallet/ledger.go +++ b/accounts/usbwallet/ledger.go @@ -334,26 +334,41 @@ func (w *ledgerDriver) ledgerSign(derivationPath []uint32, tx *types.Transaction err error ) if chainID == nil { - if txrlp, err = rlp.EncodeToBytes([]interface{}{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}); err != nil { + if txrlp, err = rlp.EncodeToBytes([]any{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data()}); err != nil { return common.Address{}, nil, err } } else { - if tx.Type() == types.DynamicFeeTxType { - 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 { + switch tx.Type() { + case types.SetCodeTxType: + if txrlp, err = rlp.EncodeToBytes([]any{chainID, tx.Nonce(), tx.GasTipCap(), tx.GasFeeCap(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations()}); err != nil { return common.Address{}, nil, err } // append type to transaction txrlp = append([]byte{tx.Type()}, txrlp...) - } else if tx.Type() == types.AccessListTxType { - if txrlp, err = rlp.EncodeToBytes([]interface{}{chainID, tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList()}); err != nil { + case types.BlobTxType: + if txrlp, err = rlp.EncodeToBytes([]any{chainID, tx.Nonce(), tx.GasTipCap(), tx.GasFeeCap(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList(), tx.BlobGasFeeCap(), tx.BlobHashes()}); err != nil { return common.Address{}, nil, err } // append type to transaction txrlp = append([]byte{tx.Type()}, txrlp...) - } else if tx.Type() == types.LegacyTxType { - 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 { + case types.DynamicFeeTxType: + if txrlp, err = rlp.EncodeToBytes([]any{chainID, tx.Nonce(), tx.GasTipCap(), tx.GasFeeCap(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList()}); err != nil { return common.Address{}, nil, err } + // append type to transaction + txrlp = append([]byte{tx.Type()}, txrlp...) + case types.AccessListTxType: + if txrlp, err = rlp.EncodeToBytes([]any{chainID, tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), tx.AccessList()}); err != nil { + return common.Address{}, nil, err + } + // append type to transaction + txrlp = append([]byte{tx.Type()}, txrlp...) + case types.LegacyTxType: + if txrlp, err = rlp.EncodeToBytes([]any{tx.Nonce(), tx.GasPrice(), tx.Gas(), tx.To(), tx.Value(), tx.Data(), chainID, big.NewInt(0), big.NewInt(0)}); err != nil { + return common.Address{}, nil, err + } + default: + return common.Address{}, nil, fmt.Errorf("unsupported transaction type: %d", tx.Type()) } } payload := append(path, txrlp...)