Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

BIP44 hd-path mistake #605

Closed
Closed
@xiangjianmeng

Description

@xiangjianmeng

System info: [branch:development, commit:ab951e22d0454ba1a0fccc9362491843bf7d4e06]

Steps to reproduce:

  1. the private key generated through cmd ethermintcli keys add alice --recover is not same to metamask using the same mnemonic.

Expected behavior: can generate same private key on metamask

RootCause:

  1. The String method of BIP44Params in cosmos-sdk v0.39.1 return path without "m".

Here is the code

func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.Reader) error {
	......
	......
	useBIP44 := !viper.IsSet(flagHDPath)
	var hdPath string

	if useBIP44 {
		hdPath = keys.CreateHDPath(account, index).String()
	} else {
		hdPath = viper.GetString(flagHDPath)
	}
	......
	......
}

Here is the code

func (p BIP44Params) String() string {
	var changeStr string
	if p.Change {
		changeStr = "1"
	} else {
		changeStr = "0"
	}
	// m / Purpose' / coin_type' / Account' / Change / address_index
	return fmt.Sprintf("%d'/%d'/%d'/%s/%d",
		p.Purpose,
		p.CoinType,
		p.Account,
		changeStr,
		p.AddressIndex)
}
  1. But the code of parsing hd-path that ethermint use is go-ethereum v1.9.24. Path without "m" will impact the parsed result.

Here is the code

func ParseDerivationPath(path string) (DerivationPath, error) {
	......
        ......
	case strings.TrimSpace(components[0]) == "m":
		components = components[1:]

	default:
		result = append(result, DefaultRootDerivationPath...)
	}
	......
        ......
	return result, nil
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions