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 2121 "error" : " transaction type not supported"
2222 },
2323 {
24- "error" : " rlp: expected List "
24+ "error" : " typed transaction too short "
2525 },
2626 {
27- "error" : " rlp: expected List "
27+ "error" : " typed transaction too short "
2828 },
2929 {
30- "error" : " rlp: expected List "
30+ "error" : " typed transaction too short "
3131 },
3232 {
33- "error" : " rlp: expected List "
33+ "error" : " typed transaction too short "
3434 },
3535 {
36- "error" : " rlp: expected List "
36+ "error" : " typed transaction too short "
3737 },
3838 {
3939 "error" : " rlp: expected input list for types.AccessListTx"
Original file line number Diff line number Diff line change 3838 receiptStatusSuccessfulRLP = []byte {0x01 }
3939)
4040
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" )
4342
4443const (
4544 // ReceiptStatusFailed is the status code of a transaction if execution failed.
@@ -182,26 +181,13 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
182181 }
183182 r .Type = LegacyTxType
184183 return r .setFromRLP (dec )
185- case kind == rlp . String :
184+ default :
186185 // It's an EIP-2718 typed tx receipt.
187186 b , err := s .Bytes ()
188187 if err != nil {
189188 return err
190189 }
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 )
205191 }
206192}
207193
@@ -224,8 +210,8 @@ func (r *Receipt) UnmarshalBinary(b []byte) error {
224210
225211// decodeTyped decodes a typed receipt from the canonical format.
226212func (r * Receipt ) decodeTyped (b []byte ) error {
227- if len (b ) == 0 {
228- return errEmptyTypedReceipt
213+ if len (b ) <= 1 {
214+ return errShortTypedReceipt
229215 }
230216 switch b [0 ] {
231217 case DynamicFeeTxType , AccessListTxType :
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
8686 input := []byte {0x80 }
8787 var r Receipt
8888 err := rlp .DecodeBytes (input , & r )
89- if err != errEmptyTypedReceipt {
89+ if err != errShortTypedReceipt {
9090 t .Fatal ("wrong error:" , err )
9191 }
9292}
Original file line number Diff line number Diff line change 3737 ErrInvalidTxType = errors .New ("transaction type not valid in this context" )
3838 ErrTxTypeNotSupported = errors .New ("transaction type not supported" )
3939 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 " )
4141)
4242
4343// Transaction types.
@@ -134,7 +134,7 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
134134 tx .setDecoded (& inner , int (rlp .ListSize (size )))
135135 }
136136 return err
137- case kind == rlp . String :
137+ default :
138138 // It's an EIP-2718 typed TX envelope.
139139 var b []byte
140140 if b , err = s .Bytes (); err != nil {
@@ -145,8 +145,6 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
145145 tx .setDecoded (inner , len (b ))
146146 }
147147 return err
148- default :
149- return rlp .ErrExpectedList
150148 }
151149}
152150
@@ -174,8 +172,8 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
174172
175173// decodeTyped decodes a typed transaction from the canonical format.
176174func (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
179177 }
180178 switch b [0 ] {
181179 case AccessListTxType :
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
7676 input := []byte {0x80 }
7777 var tx Transaction
7878 err := rlp .DecodeBytes (input , & tx )
79- if err != errEmptyTypedTx {
79+ if err != errShortTypedTx {
8080 t .Fatal ("wrong error:" , err )
8181 }
8282}
You can’t perform that action at this time.
0 commit comments