Skip to content

Commit

Permalink
Rebase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Feb 23, 2024
1 parent cf4e6c9 commit 749dbe7
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 33 deletions.
17 changes: 10 additions & 7 deletions crypto/txsigner_berlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/0xPolygon/polygon-edge/helper/keccak"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/fastrlp"
)

// BerlinSigner may be used for signing legacy (pre-EIP-155 and EIP-155) and EIP-2930 transactions
Expand All @@ -31,7 +32,7 @@ func NewBerlinSigner(chainID uint64) *BerlinSigner {
//
// Specification: https://eips.ethereum.org/EIPS/eip-2930#specification
func (signer *BerlinSigner) Hash(tx *types.Transaction) types.Hash {
if tx.Type() != types.AccessListTx {
if tx.Type() != types.AccessListTxType {
return signer.EIP155Signer.Hash(tx)
}

Expand Down Expand Up @@ -70,11 +71,13 @@ func (signer *BerlinSigner) Hash(tx *types.Transaction) types.Hash {

// Serialization format of the access list:
// [[{20-bytes address}, [{32-bytes key}, ...]], ...] where `...` denotes zero or more items
rlpAccessList := RLP.NewArray()
var rlpAccessList *fastrlp.Value

accessList := tx.AccessList()
if accessList != nil {
rlpAccessList = accessList.MarshalRLPWith(RLP)
rlpAccessList = accessList.MarshallRLPWith(RLP)
} else {
rlpAccessList = RLP.NewArray()
}

// RLP(chainId, nonce, gasPrice, gas, to, value, input, accessList)
Expand All @@ -88,11 +91,11 @@ func (signer *BerlinSigner) Hash(tx *types.Transaction) types.Hash {

// Sender returns the sender of the transaction
func (signer *BerlinSigner) Sender(tx *types.Transaction) (types.Address, error) {
if tx.Type() == types.DynamicFeeTx {
if tx.Type() == types.DynamicFeeTxType {
return types.ZeroAddress, types.ErrTxTypeNotSupported
}

if tx.Type() != types.AccessListTx {
if tx.Type() != types.AccessListTxType {
return signer.EIP155Signer.Sender(tx)
}

Expand All @@ -108,11 +111,11 @@ func (signer *BerlinSigner) Sender(tx *types.Transaction) (types.Address, error)

// SingTx takes the original transaction as input and returns its signed version
func (signer *BerlinSigner) SignTx(tx *types.Transaction, privateKey *ecdsa.PrivateKey) (*types.Transaction, error) {
if tx.Type() == types.DynamicFeeTx {
if tx.Type() == types.DynamicFeeTxType {
return nil, types.ErrTxTypeNotSupported
}

if tx.Type() != types.AccessListTx {
if tx.Type() != types.AccessListTxType {
return signer.EIP155Signer.SignTx(tx, privateKey)
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/txsigner_eip155.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (signer *EIP155Signer) Hash(tx *types.Transaction) types.Hash {

// Sender returns the sender of the transaction
func (signer *EIP155Signer) Sender(tx *types.Transaction) (types.Address, error) {
if tx.Type() != types.LegacyTx && tx.Type() != types.StateTx {
if tx.Type() != types.LegacyTxType && tx.Type() != types.StateTxType {
return types.ZeroAddress, types.ErrTxTypeNotSupported
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func (signer *EIP155Signer) Sender(tx *types.Transaction) (types.Address, error)

// SingTx takes the original transaction as input and returns its signed version
func (signer *EIP155Signer) SignTx(tx *types.Transaction, privateKey *ecdsa.PrivateKey) (*types.Transaction, error) {

Check failure on line 128 in crypto/txsigner_eip155.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

128-154 lines are duplicate of `crypto/txsigner_homestead.go:65-94` (dupl)
if tx.Type() != types.LegacyTx && tx.Type() != types.StateTx {
if tx.Type() != types.LegacyTxType && tx.Type() != types.StateTxType {
return nil, types.ErrTxTypeNotSupported
}

Expand Down
2 changes: 0 additions & 2 deletions crypto/txsigner_eip155_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func TestEIP155Signer_Sender(t *testing.T) {
To: &toAddress,
Value: big.NewInt(1),
GasPrice: big.NewInt(0),
ChainID: testCase.chainID,
})

signer := NewEIP155Signer(
Expand Down Expand Up @@ -111,7 +110,6 @@ func TestEIP155Signer_ChainIDMismatch(t *testing.T) {
To: &toAddress,
Value: big.NewInt(1),
GasPrice: big.NewInt(0),
ChainID: big.NewInt(int64(chainIDTop)),
})

//signer := NewEIP155Signer(chainIDTop, true)
Expand Down
4 changes: 2 additions & 2 deletions crypto/txsigner_frontier.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (signer *FrontierSigner) Hash(tx *types.Transaction) types.Hash {

// Sender returns the sender of the transaction
func (signer *FrontierSigner) Sender(tx *types.Transaction) (types.Address, error) {
if tx.Type() != types.LegacyTx && tx.Type() != types.StateTx {
if tx.Type() != types.LegacyTxType && tx.Type() != types.StateTxType {
return types.ZeroAddress, types.ErrTxTypeNotSupported
}

Expand All @@ -86,7 +86,7 @@ func (signer *FrontierSigner) Sender(tx *types.Transaction) (types.Address, erro

// SingTx takes the original transaction as input and returns its signed version
func (signer *FrontierSigner) SignTx(tx *types.Transaction, privateKey *ecdsa.PrivateKey) (*types.Transaction, error) {
if tx.Type() != types.LegacyTx && tx.Type() != types.StateTx {
if tx.Type() != types.LegacyTxType && tx.Type() != types.StateTxType {
return nil, types.ErrTxTypeNotSupported
}

Expand Down
6 changes: 3 additions & 3 deletions crypto/txsigner_homestead.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func (signer *HomesteadSigner) Hash(tx *types.Transaction) types.Hash {

// Sender returns the sender of the transaction
func (signer *HomesteadSigner) Sender(tx *types.Transaction) (types.Address, error) {
if tx.Type() != types.LegacyTx && tx.Type() != types.StateTx {
if tx.Type() != types.LegacyTxType && tx.Type() != types.StateTxType {
return types.ZeroAddress, types.ErrTxTypeNotSupported
}

if tx.Type() != types.LegacyTx {
if tx.Type() != types.LegacyTxType {
return types.ZeroAddress, types.ErrTxTypeNotSupported
}

Expand All @@ -63,7 +63,7 @@ func (signer *HomesteadSigner) Sender(tx *types.Transaction) (types.Address, err

// SingTx takes the original transaction as input and returns its signed version
func (signer *HomesteadSigner) SignTx(tx *types.Transaction, privateKey *ecdsa.PrivateKey) (*types.Transaction, error) {

Check failure on line 65 in crypto/txsigner_homestead.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

65-94 lines are duplicate of `crypto/txsigner_eip155.go:128-154` (dupl)
if tx.Type() != types.LegacyTx && tx.Type() != types.StateTx {
if tx.Type() != types.LegacyTxType && tx.Type() != types.StateTxType {
return nil, types.ErrTxTypeNotSupported
}

Expand Down
13 changes: 8 additions & 5 deletions crypto/txsigner_london.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/0xPolygon/polygon-edge/helper/keccak"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/fastrlp"
)

// LondonSigner may be used for signing legacy (pre-EIP-155 and EIP-155), EIP-2930 and EIP-1559 transactions
Expand Down Expand Up @@ -34,7 +35,7 @@ func NewLondonSigner(chainID uint64) *LondonSigner {
//
// Specification: https://eips.ethereum.org/EIPS/eip-1559#specification
func (signer *LondonSigner) Hash(tx *types.Transaction) types.Hash {
if tx.Type() != types.DynamicFeeTx {
if tx.Type() != types.DynamicFeeTxType {
return signer.BerlinSigner.Hash(tx)
}

Expand Down Expand Up @@ -76,11 +77,13 @@ func (signer *LondonSigner) Hash(tx *types.Transaction) types.Hash {

// Serialization format of the access list:
// [[{20-bytes address}, [{32-bytes key}, ...]], ...] where `...` denotes zero or more items
rlpAccessList := RLP.NewArray()
var rlpAccessList *fastrlp.Value

accessList := tx.AccessList()
if accessList != nil {
rlpAccessList = accessList.MarshalRLPWith(RLP)
rlpAccessList = accessList.MarshallRLPWith(RLP)
} else {
rlpAccessList = RLP.NewArray()
}

// RLP(chainId, nonce, gasTipCap, gasFeeCap, gas, to, value, input,accessList)
Expand All @@ -94,7 +97,7 @@ func (signer *LondonSigner) Hash(tx *types.Transaction) types.Hash {

// Sender returns the sender of the transaction
func (signer *LondonSigner) Sender(tx *types.Transaction) (types.Address, error) {
if tx.Type() != types.DynamicFeeTx {
if tx.Type() != types.DynamicFeeTxType {
return signer.BerlinSigner.Sender(tx)
}

Expand All @@ -110,7 +113,7 @@ func (signer *LondonSigner) Sender(tx *types.Transaction) (types.Address, error)

// SingTx takes the original transaction as input and returns its signed version
func (signer *LondonSigner) SignTx(tx *types.Transaction, privateKey *ecdsa.PrivateKey) (*types.Transaction, error) {
if tx.Type() != types.DynamicFeeTx {
if tx.Type() != types.DynamicFeeTxType {
return signer.BerlinSigner.SignTx(tx, privateKey)
}

Expand Down
6 changes: 3 additions & 3 deletions crypto/txsigner_london_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func TestLondonSignerSender(t *testing.T) {
To: &recipient,
Value: big.NewInt(1),
GasPrice: big.NewInt(5),
ChainID: tc.chainID,
})
case types.StateTxType:
txn = types.NewTx(&types.StateTx{
Expand All @@ -95,8 +94,9 @@ func TestLondonSignerSender(t *testing.T) {
})
case types.DynamicFeeTxType:
txn = types.NewTx(&types.DynamicFeeTx{
To: &recipient,
Value: big.NewInt(1),
To: &recipient,
Value: big.NewInt(1),
ChainID: tc.chainID,
})
}

Expand Down
3 changes: 0 additions & 3 deletions e2e/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ func TestTxPool_RecoverableError(t *testing.T) {
Gas: 22000,
To: &receiverAddress,
Value: oneEth,
ChainID: big.NewInt(0),
V: big.NewInt(27),
From: senderAddress,
}),
Expand All @@ -257,7 +256,6 @@ func TestTxPool_RecoverableError(t *testing.T) {
Gas: 22000,
To: &receiverAddress,
Value: oneEth,
ChainID: big.NewInt(0),
V: big.NewInt(27),
}),
types.NewTx(&types.DynamicFeeTx{
Expand Down Expand Up @@ -357,7 +355,6 @@ func TestTxPool_GetPendingTx(t *testing.T) {
Gas: framework.DefaultGasLimit - 1,
To: &receiverAddress,
Value: oneEth,
ChainID: big.NewInt(0),
V: big.NewInt(1),
From: types.ZeroAddress,
}), senderKey)
Expand Down
8 changes: 4 additions & 4 deletions types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (al TxAccessList) Copy() TxAccessList {
return newAccessList
}

func (al TxAccessList) unmarshallRLPFrom(p *fastrlp.Parser, accessListVV []*fastrlp.Value) error {
func (al TxAccessList) UnmarshallRLPFrom(p *fastrlp.Parser, accessListVV []*fastrlp.Value) error {
for i, accessTupleVV := range accessListVV {
accessTupleElems, err := accessTupleVV.GetElems()
if err != nil {
Expand Down Expand Up @@ -85,7 +85,7 @@ func (al TxAccessList) unmarshallRLPFrom(p *fastrlp.Parser, accessListVV []*fast
return nil
}

func (al TxAccessList) marshallRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
func (al TxAccessList) MarshallRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
accessListVV := arena.NewArray()

for _, accessTuple := range al {
Expand Down Expand Up @@ -290,7 +290,7 @@ func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) e
txAccessList = make(TxAccessList, len(accessListVV))
}

if err = txAccessList.unmarshallRLPFrom(p, accessListVV); err != nil {
if err = txAccessList.UnmarshallRLPFrom(p, accessListVV); err != nil {
return err
}

Expand Down Expand Up @@ -341,7 +341,7 @@ func (tx *AccessListTxn) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
vv.Set(arena.NewCopyBytes(tx.input()))

// Convert TxAccessList to RLP format and add it to the vv array.
vv.Set(tx.accessList().marshallRLPWith(arena))
vv.Set(tx.accessList().MarshallRLPWith(arena))

v, r, s := tx.rawSignatureValues()
vv.Set(arena.NewBigInt(v))
Expand Down
4 changes: 2 additions & 2 deletions types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (tx *DynamicFeeTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) er
txAccessList = make(TxAccessList, len(accessListVV))
}

if err = txAccessList.unmarshallRLPFrom(p, accessListVV); err != nil {
if err = txAccessList.UnmarshallRLPFrom(p, accessListVV); err != nil {
return err
}

Expand Down Expand Up @@ -243,7 +243,7 @@ func (tx *DynamicFeeTx) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
vv.Set(arena.NewCopyBytes(tx.input()))

// Convert TxAccessList to RLP format and add it to the vv array.
vv.Set(tx.accessList().marshallRLPWith(arena))
vv.Set(tx.accessList().MarshallRLPWith(arena))

// signature values
v, r, s := tx.rawSignatureValues()
Expand Down

0 comments on commit 749dbe7

Please sign in to comment.