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

[R4R] refactor: depositWithNonce && remove duplicate signer #89

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/types/transaction_marshalling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,27 @@ func TestTransactionUnmarshalJSON(t *testing.T) {
}
})
}

tests = []struct {
name string
json string
expectedError string
}{
{
name: "Valid deposit sender",
json: `{"type":"0x7e","nonce":"0x1","gas": "0x1234", "gasPrice":null,"maxPriorityFeePerGas":null,"maxFeePerGas":null,"value":"0x1","input":"0x616263646566","v":null,"r":null,"s":null,"to":null,"sourceHash":"0x0000000000000000000000000000000000000000000000000000000000000000","from":"0x0000000000000000000000000000000000000001","hash":"0xa4341f3db4363b7ca269a8538bd027b2f8784f84454ca917668642d5f6dffdf9"}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var parsedTx = &Transaction{}
err := json.Unmarshal([]byte(test.json), &parsedTx)
require.NoError(t, err)

signer := NewLondonSigner(big.NewInt(123))
sender, err := signer.Sender(parsedTx)
require.NoError(t, err)
require.Equal(t, common.HexToAddress("0x1"), sender)
})
}
}
23 changes: 8 additions & 15 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ func NewLondonSigner(chainId *big.Int) Signer {

func (s londonSigner) Sender(tx *Transaction) (common.Address, error) {
if tx.Type() == DepositTxType {
return tx.inner.(*DepositTx).From, nil
switch tx.inner.(type) {
case *DepositTx:
return tx.inner.(*DepositTx).From, nil
case *depositTxWithNonce:
return tx.inner.(*depositTxWithNonce).From, nil
}
}
if tx.Type() != DynamicFeeTxType {
return s.eip2930Signer.Sender(tx)
Expand Down Expand Up @@ -335,11 +340,7 @@ func (s eip2930Signer) Sender(tx *Transaction) (common.Address, error) {
V, R, S := tx.RawSignatureValues()
switch tx.Type() {
case LegacyTxType:
if !tx.Protected() {
return HomesteadSigner{}.Sender(tx)
}
V = new(big.Int).Sub(V, s.chainIdMul)
V.Sub(V, big8)
return s.EIP155Signer.Sender(tx)
case AccessListTxType:
// AL txs are defined to use 0 and 1 as their recovery
// id, add 27 to become equivalent to unprotected Homestead signatures.
Expand Down Expand Up @@ -376,15 +377,7 @@ func (s eip2930Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *bi
func (s eip2930Signer) Hash(tx *Transaction) common.Hash {
switch tx.Type() {
case LegacyTxType:
return rlpHash([]interface{}{
tx.Nonce(),
tx.GasPrice(),
tx.Gas(),
tx.To(),
tx.Value(),
tx.Data(),
s.chainId, uint(0), uint(0),
})
return s.EIP155Signer.Hash(tx)
case AccessListTxType:
return prefixedRlpHash(
tx.Type(),
Expand Down