Skip to content

Commit

Permalink
Merge pull request ethereum#101 from yzhou61/deposit-sender-fix
Browse files Browse the repository at this point in the history
Fix sender of deposit transactions
  • Loading branch information
ajsutton authored Jun 9, 2023
2 parents 09ade3d + 1ee4f9f commit 474eda1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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)
})
}
}
7 changes: 6 additions & 1 deletion core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,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

0 comments on commit 474eda1

Please sign in to comment.