@@ -18,11 +18,13 @@ package types
18
18
19
19
import (
20
20
"errors"
21
+ "fmt"
21
22
"math/big"
22
23
"testing"
23
24
24
25
"github.com/ethereum/go-ethereum/common"
25
26
"github.com/ethereum/go-ethereum/crypto"
27
+ "github.com/ethereum/go-ethereum/params"
26
28
"github.com/ethereum/go-ethereum/rlp"
27
29
)
28
30
@@ -136,3 +138,53 @@ func TestChainId(t *testing.T) {
136
138
t .Error ("expected no error" )
137
139
}
138
140
}
141
+
142
+ type nilSigner struct {
143
+ v , r , s * big.Int
144
+ Signer
145
+ }
146
+
147
+ func (ns * nilSigner ) SignatureValues (tx * Transaction , sig []byte ) (r , s , v * big.Int , err error ) {
148
+ return ns .v , ns .r , ns .s , nil
149
+ }
150
+
151
+ // TestNilSigner ensures a faulty Signer implementation does not result in nil signature values or panics.
152
+ func TestNilSigner (t * testing.T ) {
153
+ key , _ := crypto .GenerateKey ()
154
+ innerSigner := LatestSignerForChainID (big .NewInt (1 ))
155
+ for i , signer := range []Signer {
156
+ & nilSigner {v : nil , r : nil , s : nil , Signer : innerSigner },
157
+ & nilSigner {v : big .NewInt (1 ), r : big .NewInt (1 ), s : nil , Signer : innerSigner },
158
+ & nilSigner {v : big .NewInt (1 ), r : nil , s : big .NewInt (1 ), Signer : innerSigner },
159
+ & nilSigner {v : nil , r : big .NewInt (1 ), s : big .NewInt (1 ), Signer : innerSigner },
160
+ } {
161
+ t .Run (fmt .Sprintf ("signer_%d" , i ), func (t * testing.T ) {
162
+ t .Run ("legacy" , func (t * testing.T ) {
163
+ legacyTx := createTestLegacyTxInner ()
164
+ _ , err := SignNewTx (key , signer , legacyTx )
165
+ if ! errors .Is (err , ErrInvalidSig ) {
166
+ t .Fatal ("expected signature values error, no nil result or panic" )
167
+ }
168
+ })
169
+ // test Blob tx specifically, since the signature value types changed
170
+ t .Run ("blobtx" , func (t * testing.T ) {
171
+ blobtx := createEmptyBlobTxInner (false )
172
+ _ , err := SignNewTx (key , signer , blobtx )
173
+ if ! errors .Is (err , ErrInvalidSig ) {
174
+ t .Fatal ("expected signature values error, no nil result or panic" )
175
+ }
176
+ })
177
+ })
178
+ }
179
+ }
180
+
181
+ func createTestLegacyTxInner () * LegacyTx {
182
+ return & LegacyTx {
183
+ Nonce : uint64 (0 ),
184
+ To : nil ,
185
+ Value : big .NewInt (0 ),
186
+ Gas : params .TxGas ,
187
+ GasPrice : big .NewInt (params .GWei ),
188
+ Data : nil ,
189
+ }
190
+ }
0 commit comments