File tree Expand file tree Collapse file tree 5 files changed +16
-32
lines changed Expand file tree Collapse file tree 5 files changed +16
-32
lines changed Original file line number Diff line number Diff line change 21
21
"error" : " transaction type not supported"
22
22
},
23
23
{
24
- "error" : " rlp: expected List "
24
+ "error" : " typed transaction too short "
25
25
},
26
26
{
27
- "error" : " rlp: expected List "
27
+ "error" : " typed transaction too short "
28
28
},
29
29
{
30
- "error" : " rlp: expected List "
30
+ "error" : " typed transaction too short "
31
31
},
32
32
{
33
- "error" : " rlp: expected List "
33
+ "error" : " typed transaction too short "
34
34
},
35
35
{
36
- "error" : " rlp: expected List "
36
+ "error" : " typed transaction too short "
37
37
},
38
38
{
39
39
"error" : " rlp: expected input list for types.AccessListTx"
Original file line number Diff line number Diff line change 38
38
receiptStatusSuccessfulRLP = []byte {0x01 }
39
39
)
40
40
41
- // This error is returned when a typed receipt is decoded, but the string is empty.
42
- var errEmptyTypedReceipt = errors .New ("empty typed receipt bytes" )
41
+ var errShortTypedReceipt = errors .New ("typed receipt too short" )
43
42
44
43
const (
45
44
// ReceiptStatusFailed is the status code of a transaction if execution failed.
@@ -182,26 +181,13 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
182
181
}
183
182
r .Type = LegacyTxType
184
183
return r .setFromRLP (dec )
185
- case kind == rlp . String :
184
+ default :
186
185
// It's an EIP-2718 typed tx receipt.
187
186
b , err := s .Bytes ()
188
187
if err != nil {
189
188
return err
190
189
}
191
- if len (b ) == 0 {
192
- return errEmptyTypedReceipt
193
- }
194
- r .Type = b [0 ]
195
- if r .Type == AccessListTxType || r .Type == DynamicFeeTxType {
196
- var dec receiptRLP
197
- if err := rlp .DecodeBytes (b [1 :], & dec ); err != nil {
198
- return err
199
- }
200
- return r .setFromRLP (dec )
201
- }
202
- return ErrTxTypeNotSupported
203
- default :
204
- return rlp .ErrExpectedList
190
+ return r .decodeTyped (b )
205
191
}
206
192
}
207
193
@@ -224,8 +210,8 @@ func (r *Receipt) UnmarshalBinary(b []byte) error {
224
210
225
211
// decodeTyped decodes a typed receipt from the canonical format.
226
212
func (r * Receipt ) decodeTyped (b []byte ) error {
227
- if len (b ) == 0 {
228
- return errEmptyTypedReceipt
213
+ if len (b ) <= 1 {
214
+ return errShortTypedReceipt
229
215
}
230
216
switch b [0 ] {
231
217
case DynamicFeeTxType , AccessListTxType :
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
86
86
input := []byte {0x80 }
87
87
var r Receipt
88
88
err := rlp .DecodeBytes (input , & r )
89
- if err != errEmptyTypedReceipt {
89
+ if err != errShortTypedReceipt {
90
90
t .Fatal ("wrong error:" , err )
91
91
}
92
92
}
Original file line number Diff line number Diff line change 37
37
ErrInvalidTxType = errors .New ("transaction type not valid in this context" )
38
38
ErrTxTypeNotSupported = errors .New ("transaction type not supported" )
39
39
ErrGasFeeCapTooLow = errors .New ("fee cap less than base fee" )
40
- errEmptyTypedTx = errors .New ("empty typed transaction bytes " )
40
+ errShortTypedTx = errors .New ("typed transaction too short " )
41
41
)
42
42
43
43
// Transaction types.
@@ -134,7 +134,7 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
134
134
tx .setDecoded (& inner , int (rlp .ListSize (size )))
135
135
}
136
136
return err
137
- case kind == rlp . String :
137
+ default :
138
138
// It's an EIP-2718 typed TX envelope.
139
139
var b []byte
140
140
if b , err = s .Bytes (); err != nil {
@@ -145,8 +145,6 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
145
145
tx .setDecoded (inner , len (b ))
146
146
}
147
147
return err
148
- default :
149
- return rlp .ErrExpectedList
150
148
}
151
149
}
152
150
@@ -174,8 +172,8 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
174
172
175
173
// decodeTyped decodes a typed transaction from the canonical format.
176
174
func (tx * Transaction ) decodeTyped (b []byte ) (TxData , error ) {
177
- if len (b ) == 0 {
178
- return nil , errEmptyTypedTx
175
+ if len (b ) <= 1 {
176
+ return nil , errShortTypedTx
179
177
}
180
178
switch b [0 ] {
181
179
case AccessListTxType :
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
76
76
input := []byte {0x80 }
77
77
var tx Transaction
78
78
err := rlp .DecodeBytes (input , & tx )
79
- if err != errEmptyTypedTx {
79
+ if err != errShortTypedTx {
80
80
t .Fatal ("wrong error:" , err )
81
81
}
82
82
}
You can’t perform that action at this time.
0 commit comments