Skip to content

Commit c996220

Browse files
author
Vinod Damle
committed
Check for invalid signer
Signed-off-by: Vinod Damle <[email protected]>
1 parent a2f3444 commit c996220

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/ethsigner/transaction.go

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package ethsigner
1818

1919
import (
2020
"encoding/json"
21+
"fmt"
2122
"math/big"
2223

2324
"github.com/hyperledger/firefly-signer/pkg/ethtypes"
@@ -97,6 +98,9 @@ func (t *Transaction) Build1559(chainID int64) rlp.List {
9798
// - By default use EIP-155 signing
9899
// Never picks legacy-legacy (non EIP-155), or EIP-2930
99100
func (t *Transaction) Sign(signer secp256k1.Signer, chainID int64) ([]byte, error) {
101+
if signer == nil {
102+
return nil, fmt.Errorf("invalid signer")
103+
}
100104
if t.MaxPriorityFeePerGas.BigInt().Sign() > 0 || t.MaxFeePerGas.BigInt().Sign() > 0 {
101105
return t.SignEIP1559(signer, chainID)
102106
}
@@ -125,6 +129,9 @@ func (t *Transaction) SignaturePayloadLegacyOriginal() *TransactionSignaturePayl
125129

126130
// SignLegacyOriginal uses legacy transaction structure, with legacy V value (27/28)
127131
func (t *Transaction) SignLegacyOriginal(signer secp256k1.Signer) ([]byte, error) {
132+
if signer == nil {
133+
return nil, fmt.Errorf("invalid signer")
134+
}
128135
signatureData := t.SignaturePayloadLegacyOriginal()
129136
sig, err := signer.Sign(signatureData.data)
130137
if err != nil {
@@ -149,6 +156,9 @@ func (t *Transaction) SignaturePayloadLegacyEIP155(chainID int64) *TransactionSi
149156

150157
// SignLegacyEIP155 uses legacy transaction structure, with EIP-155 signing V value (2*ChainID + 35 + Y-parity)
151158
func (t *Transaction) SignLegacyEIP155(signer secp256k1.Signer, chainID int64) ([]byte, error) {
159+
if signer == nil {
160+
return nil, fmt.Errorf("invalid signer")
161+
}
152162

153163
signaturePayload := t.SignaturePayloadLegacyEIP155(chainID)
154164

@@ -179,6 +189,9 @@ func (t *Transaction) SignaturePayloadEIP1559(chainID int64) *TransactionSignatu
179189

180190
// SignEIP1559 uses EIP-1559 transaction structure (with EIP-2718 transaction type byte), with EIP-2930 V value (0 / 1 - direct parity-Y)
181191
func (t *Transaction) SignEIP1559(signer secp256k1.Signer, chainID int64) ([]byte, error) {
192+
if signer == nil {
193+
return nil, fmt.Errorf("invalid signer")
194+
}
182195

183196
signaturePayload := t.SignaturePayloadEIP1559(chainID)
184197
sig, err := signer.Sign(signaturePayload.data)

0 commit comments

Comments
 (0)