fix address recovery from pubkey.
This commit is contained in:
parent
9017e5de52
commit
6d5ec6aff8
@ -22,6 +22,8 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Eip1559TxType = 2
|
||||||
|
|
||||||
type EthTx struct {
|
type EthTx struct {
|
||||||
ChainID EthUint64 `json:"chainId"`
|
ChainID EthUint64 `json:"chainId"`
|
||||||
Nonce EthUint64 `json:"nonce"`
|
Nonce EthUint64 `json:"nonce"`
|
||||||
@ -279,12 +281,18 @@ func (tx *EthTxArgs) Sender() (address.Address, error) {
|
|||||||
return address.Undef, err
|
return address.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we get an uncompressed public key (that's what we get from the library,
|
||||||
|
// but putting this check here for defensiveness), strip the prefix
|
||||||
|
if pubk[0] == 0x04 {
|
||||||
|
pubk = pubk[1:]
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the f4 address based on the keccak hash of the pubkey.
|
// Calculate the f4 address based on the keccak hash of the pubkey.
|
||||||
hasher.Reset()
|
hasher.Reset()
|
||||||
hasher.Write(pubk)
|
hasher.Write(pubk)
|
||||||
addrHash := hasher.Sum(nil)
|
ethAddr := hasher.Sum(nil)[12:]
|
||||||
|
|
||||||
return address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, addrHash[len(addrHash)-20:])
|
return address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, ethAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEip1559Tx(data []byte) (*EthTxArgs, error) {
|
func parseEip1559Tx(data []byte) (*EthTxArgs, error) {
|
||||||
@ -392,7 +400,7 @@ func ParseEthTxArgs(data []byte) (*EthTxArgs, error) {
|
|||||||
} else if data[0] == 1 {
|
} else if data[0] == 1 {
|
||||||
// EIP-2930
|
// EIP-2930
|
||||||
return nil, fmt.Errorf("EIP-2930 transaction is not supported")
|
return nil, fmt.Errorf("EIP-2930 transaction is not supported")
|
||||||
} else if data[0] == 2 {
|
} else if data[0] == Eip1559TxType {
|
||||||
// EIP-1559
|
// EIP-1559
|
||||||
return parseEip1559Tx(data)
|
return parseEip1559Tx(data)
|
||||||
}
|
}
|
||||||
|
@ -775,6 +775,7 @@ var StateGetActorCmd = &cli.Command{
|
|||||||
fmt.Printf("Nonce:\t\t%d\n", a.Nonce)
|
fmt.Printf("Nonce:\t\t%d\n", a.Nonce)
|
||||||
fmt.Printf("Code:\t\t%s (%s)\n", a.Code, strtype)
|
fmt.Printf("Code:\t\t%s (%s)\n", a.Code, strtype)
|
||||||
fmt.Printf("Head:\t\t%s\n", a.Head)
|
fmt.Printf("Head:\t\t%s\n", a.Head)
|
||||||
|
fmt.Printf("Predictable address:\t\t%s\n", a.Address)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -41,11 +41,17 @@ func (delegatedSigner) Verify(sig []byte, a address.Address, msg []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we get an uncompressed public key (that's what we get from the library,
|
||||||
|
// but putting this check here for defensiveness), strip the prefix
|
||||||
|
if pubk[0] == 0x04 {
|
||||||
|
pubk = pubk[1:]
|
||||||
|
}
|
||||||
|
|
||||||
hasher.Reset()
|
hasher.Reset()
|
||||||
hasher.Write(pubk)
|
hasher.Write(pubk)
|
||||||
addrHash := hasher.Sum(nil)
|
addrHash := hasher.Sum(nil)
|
||||||
|
|
||||||
maybeaddr, err := address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, addrHash[len(addrHash)-20:])
|
maybeaddr, err := address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, addrHash[12:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user