Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/types: rlp decode unsigned transactions #25124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type AccessListTx struct {
Value *big.Int // wei amount
Data []byte // contract invocation input data
AccessList AccessList // EIP-2930 access list
V, R, S *big.Int // signature values
V, R, S *big.Int `rlp:"optional"` // signature values
}

// copy creates a deep copy of the transaction data and initializes all fields.
Expand Down
6 changes: 3 additions & 3 deletions core/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type DynamicFeeTx struct {
AccessList AccessList

// Signature values
V *big.Int `json:"v" gencodec:"required"`
R *big.Int `json:"r" gencodec:"required"`
S *big.Int `json:"s" gencodec:"required"`
V *big.Int `json:"v" gencodec:"required" rlp:"optional"`
R *big.Int `json:"r" gencodec:"required" rlp:"optional"`
S *big.Int `json:"s" gencodec:"required" rlp:"optional"`
}

// copy creates a deep copy of the transaction data and initializes all fields.
Expand Down
2 changes: 1 addition & 1 deletion core/types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type LegacyTx struct {
To *common.Address `rlp:"nil"` // nil means contract creation
Value *big.Int // wei amount
Data []byte // contract invocation input data
V, R, S *big.Int // signature values
V, R, S *big.Int `rlp:"optional"` // signature values
}

// NewTransaction creates an unsigned legacy transaction.
Expand Down
39 changes: 39 additions & 0 deletions core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package types
import (
"bytes"
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
Expand Down Expand Up @@ -531,3 +532,41 @@ func assertEqual(orig *Transaction, cpy *Transaction) error {
}
return nil
}

func decodeRLP(txData string) (*Transaction, error) {
txDataBytes, err := hex.DecodeString(txData)
if err != nil {
return nil, err
}

tx := new(Transaction)
err = tx.UnmarshalBinary(txDataBytes)
if err != nil {
return nil, err
}

return tx, nil
}

func TestUnsignedTxDecode(t *testing.T) {
// rlp encoded transactions sending 0.001 ETH to vitalik
// each RLP payload is missing the signature data fields

txDatas := []string{
// dynamic fee tx
"02ee03808459682f008459682f0a82520894d8da6bf26964af9d7eed9e03e53415d37aa9604587038d7ea4c6800080c0",

// access list tx
"01f86501800a8301e24194d8da6bf26964af9d7eed9e03e53415d37aa9604587038d7ea4c6800086616263646566f838f7940000000000000000000000000000000000000001e1a00000000000000000000000000000000000000000000000000000000000000000",

// legacy tx
"e780020194d8da6bf26964af9d7eed9e03e53415d37aa9604587038d7ea4c6800086616263646566",
}

for _, data := range txDatas {
_, err := decodeRLP(data)
if err != nil {
t.Fatal(err)
}
}
}