diff --git a/ethereum/rpc/backend/backend.go b/ethereum/rpc/backend/backend.go index b4025389..e83004d7 100644 --- a/ethereum/rpc/backend/backend.go +++ b/ethereum/rpc/backend/backend.go @@ -49,15 +49,21 @@ type EVMBackend struct { clientCtx client.Context queryClient *types.QueryClient // gRPC query client logger log.Logger + chainID *big.Int } // NewEVMBackend creates a new EVMBackend instance func NewEVMBackend(clientCtx client.Context) *EVMBackend { + chainID, err := ethermint.ParseChainID(clientCtx.ChainID) + if err != nil { + panic(err) + } return &EVMBackend{ ctx: context.Background(), clientCtx: clientCtx, queryClient: types.NewQueryClient(clientCtx), logger: log.WithField("module", "evm-backend"), + chainID: chainID, } } @@ -151,9 +157,13 @@ func (e *EVMBackend) EthBlockFromTendermint( hash := msg.AsTransaction().Hash() if fullTx { + from, err := msg.GetSender(e.chainID) + if err != nil { + from = common.HexToAddress(msg.From) + } ethTx, err := types.NewTransactionFromData( msg.Data, - common.HexToAddress(msg.From), + from, hash, common.BytesToHash(block.Hash()), uint64(block.Height), diff --git a/ethereum/rpc/namespaces/eth/api.go b/ethereum/rpc/namespaces/eth/api.go index b10f8788..77428a6f 100644 --- a/ethereum/rpc/namespaces/eth/api.go +++ b/ethereum/rpc/namespaces/eth/api.go @@ -723,9 +723,13 @@ func (e *PublicAPI) GetTransactionByHash(hash common.Hash) (*rpctypes.RPCTransac return nil, fmt.Errorf("invalid tx type: %T", tx) } + from, err := msg.GetSender(e.chainIDEpoch) + if err != nil { + return nil, err + } return rpctypes.NewTransactionFromData( msg.Data, - common.HexToAddress(msg.From), + from, hash, common.BytesToHash(resBlock.Block.Hash()), uint64(res.Height), @@ -880,7 +884,10 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac status = hexutil.Uint(ethtypes.ReceiptStatusFailed) } - from := common.HexToAddress(msg.From) + from, err := msg.GetSender(e.chainIDEpoch) + if err != nil { + return nil, err + } resLogs, err := e.queryClient.TxLogs(e.ctx, &evmtypes.QueryTxLogsRequest{Hash: hash.Hex()}) if err != nil { diff --git a/x/evm/types/msg.go b/x/evm/types/msg.go index 0e2f6cfa..b6264c7f 100644 --- a/x/evm/types/msg.go +++ b/x/evm/types/msg.go @@ -216,3 +216,14 @@ func (msg MsgEthereumTx) AsTransaction() *ethtypes.Transaction { func (msg MsgEthereumTx) AsMessage(signer ethtypes.Signer) (core.Message, error) { return msg.AsTransaction().AsMessage(signer) } + +// GetSender extracts the sender address from the signature values using the latest signer for the given chainID. +func (msg *MsgEthereumTx) GetSender(chainID *big.Int) (common.Address, error) { + signer := ethtypes.LatestSignerForChainID(chainID) + from, err := signer.Sender(msg.AsTransaction()) + if err != nil { + return common.Address{}, err + } + msg.From = from.Hex() + return from, nil +} diff --git a/x/evm/types/msg_test.go b/x/evm/types/msg_test.go index c42ab88e..413d7c4e 100644 --- a/x/evm/types/msg_test.go +++ b/x/evm/types/msg_test.go @@ -183,9 +183,7 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_Sign() { if tc.expectPass { suite.Require().NoError(err, "valid test %d failed: %s", i, tc.msg) - tx := tc.tx.AsTransaction() - - sender, err := ethtypes.Sender(tc.ethSigner, tx) + sender, err := tc.tx.GetSender(suite.chainID) suite.Require().NoError(err, tc.msg) suite.Require().Equal(tc.tx.From, sender.Hex(), tc.msg) } else {