Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
d1f6a9f5
Unverified
Commit
d1f6a9f5
authored
3 years ago
by
Justus
Committed by
GitHub
3 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/types: improve error for too short transaction / receipt encoding (#24256)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
19c2c60b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
32 deletions
+16
-32
exp3.json
cmd/evm/testdata/15/exp3.json
+5
-5
receipt.go
core/types/receipt.go
+5
-19
receipt_test.go
core/types/receipt_test.go
+1
-1
transaction.go
core/types/transaction.go
+4
-6
transaction_test.go
core/types/transaction_test.go
+1
-1
No files found.
cmd/evm/testdata/15/exp3.json
View file @
d1f6a9f5
...
...
@@ -21,19 +21,19 @@
"error"
:
"transaction type not supported"
},
{
"error"
:
"
rlp: expected Lis
t"
"error"
:
"
typed transaction too shor
t"
},
{
"error"
:
"
rlp: expected Lis
t"
"error"
:
"
typed transaction too shor
t"
},
{
"error"
:
"
rlp: expected Lis
t"
"error"
:
"
typed transaction too shor
t"
},
{
"error"
:
"
rlp: expected Lis
t"
"error"
:
"
typed transaction too shor
t"
},
{
"error"
:
"
rlp: expected Lis
t"
"error"
:
"
typed transaction too shor
t"
},
{
"error"
:
"rlp: expected input list for types.AccessListTx"
...
...
This diff is collapsed.
Click to expand it.
core/types/receipt.go
View file @
d1f6a9f5
...
...
@@ -38,8 +38,7 @@ var (
receiptStatusSuccessfulRLP
=
[]
byte
{
0x01
}
)
// This error is returned when a typed receipt is decoded, but the string is empty.
var
errEmptyTypedReceipt
=
errors
.
New
(
"empty typed receipt bytes"
)
var
errShortTypedReceipt
=
errors
.
New
(
"typed receipt too short"
)
const
(
// ReceiptStatusFailed is the status code of a transaction if execution failed.
...
...
@@ -182,26 +181,13 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
}
r
.
Type
=
LegacyTxType
return
r
.
setFromRLP
(
dec
)
case
kind
==
rlp
.
String
:
default
:
// It's an EIP-2718 typed tx receipt.
b
,
err
:=
s
.
Bytes
()
if
err
!=
nil
{
return
err
}
if
len
(
b
)
==
0
{
return
errEmptyTypedReceipt
}
r
.
Type
=
b
[
0
]
if
r
.
Type
==
AccessListTxType
||
r
.
Type
==
DynamicFeeTxType
{
var
dec
receiptRLP
if
err
:=
rlp
.
DecodeBytes
(
b
[
1
:
],
&
dec
);
err
!=
nil
{
return
err
}
return
r
.
setFromRLP
(
dec
)
}
return
ErrTxTypeNotSupported
default
:
return
rlp
.
ErrExpectedList
return
r
.
decodeTyped
(
b
)
}
}
...
...
@@ -224,8 +210,8 @@ func (r *Receipt) UnmarshalBinary(b []byte) error {
// decodeTyped decodes a typed receipt from the canonical format.
func
(
r
*
Receipt
)
decodeTyped
(
b
[]
byte
)
error
{
if
len
(
b
)
==
0
{
return
err
Empty
TypedReceipt
if
len
(
b
)
<=
1
{
return
err
Short
TypedReceipt
}
switch
b
[
0
]
{
case
DynamicFeeTxType
,
AccessListTxType
:
...
...
This diff is collapsed.
Click to expand it.
core/types/receipt_test.go
View file @
d1f6a9f5
...
...
@@ -86,7 +86,7 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
input
:=
[]
byte
{
0x80
}
var
r
Receipt
err
:=
rlp
.
DecodeBytes
(
input
,
&
r
)
if
err
!=
err
Empty
TypedReceipt
{
if
err
!=
err
Short
TypedReceipt
{
t
.
Fatal
(
"wrong error:"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
core/types/transaction.go
View file @
d1f6a9f5
...
...
@@ -37,7 +37,7 @@ var (
ErrInvalidTxType
=
errors
.
New
(
"transaction type not valid in this context"
)
ErrTxTypeNotSupported
=
errors
.
New
(
"transaction type not supported"
)
ErrGasFeeCapTooLow
=
errors
.
New
(
"fee cap less than base fee"
)
err
EmptyTypedTx
=
errors
.
New
(
"empty typed transaction bytes
"
)
err
ShortTypedTx
=
errors
.
New
(
"typed transaction too short
"
)
)
// Transaction types.
...
...
@@ -134,7 +134,7 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
tx
.
setDecoded
(
&
inner
,
int
(
rlp
.
ListSize
(
size
)))
}
return
err
case
kind
==
rlp
.
String
:
default
:
// It's an EIP-2718 typed TX envelope.
var
b
[]
byte
if
b
,
err
=
s
.
Bytes
();
err
!=
nil
{
...
...
@@ -145,8 +145,6 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
tx
.
setDecoded
(
inner
,
len
(
b
))
}
return
err
default
:
return
rlp
.
ErrExpectedList
}
}
...
...
@@ -174,8 +172,8 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
// decodeTyped decodes a typed transaction from the canonical format.
func
(
tx
*
Transaction
)
decodeTyped
(
b
[]
byte
)
(
TxData
,
error
)
{
if
len
(
b
)
==
0
{
return
nil
,
err
Empty
TypedTx
if
len
(
b
)
<=
1
{
return
nil
,
err
Short
TypedTx
}
switch
b
[
0
]
{
case
AccessListTxType
:
...
...
This diff is collapsed.
Click to expand it.
core/types/transaction_test.go
View file @
d1f6a9f5
...
...
@@ -76,7 +76,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
input
:=
[]
byte
{
0x80
}
var
tx
Transaction
err
:=
rlp
.
DecodeBytes
(
input
,
&
tx
)
if
err
!=
err
Empty
TypedTx
{
if
err
!=
err
Short
TypedTx
{
t
.
Fatal
(
"wrong error:"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment