Skip to content

Commit d8909d8

Browse files
yihuangmmsqe
authored andcommitted
fix: non-eip-155 tx panic when get signer (cosmos#282)
1 parent 84e26c6 commit d8909d8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

api/cosmos/evm/vm/v1/msg.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ var supportedTxs = map[string]func() TxDataV2{
2121

2222
// getSender extracts the sender address from the signature values using the latest signer for the given chainID.
2323
func getSender(txData TxDataV2) (common.Address, error) {
24-
signer := ethtypes.LatestSignerForChainID(txData.GetChainID())
24+
chainID := txData.GetChainID()
25+
// legacy tx returns `0` as chainID when EIP-155 is not used
26+
// see: DeriveChainID
27+
if chainID != nil && chainID.Sign() == 0 {
28+
chainID = nil
29+
}
30+
signer := ethtypes.LatestSignerForChainID(chainID)
2531
from, err := signer.Sender(ethtypes.NewTx(txData.AsEthereumData()))
2632
if err != nil {
2733
return common.Address{}, err

utils/eth/eth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import "math/big"
99
// - {0,1} + CHAIN_ID * 2 + 35, if EIP155 is used
1010
// - {0,1} + 27, otherwise
1111
//
12+
// when EIP155 is not used, chain id `0` is returned.
13+
//
1214
// Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
1315
func DeriveChainID(v *big.Int) *big.Int {
1416
if v == nil || v.Sign() < 1 {

0 commit comments

Comments
 (0)