paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

`subkey -e inspect` yields inconsistent public keys with `subkey -e generate` #2760

Closed dryruner closed 5 years ago

dryruner commented 5 years ago

Example:

$ subkey -e generate
Phrase `island morning track vast rhythm rebel vendor hold buffalo place east exhaust` is account:
  Seed: 0x8ba9420c3e1bf0ffd3a141c7f7c6e06b70c2fef141a9dcf53c51b96964b8687e
  Public key (hex): 0x094cd08a28543ea0a4cd9f14dbbd936724e54230b0f8ff7fa0e6eaef36e0da4e
  Address (SS58): 5CGu79d1oTYtfZpoPJQz4tt5dmiYi3S6RY44UGUx6N7kyqTx
$ subkey -e inspect "island morning track vast rhythm rebel vendor hold buffalo place east exhaust"
Secret Key URI `island morning track vast rhythm rebel vendor hold buffalo place east exhaust` is account:
  Seed: 0xe989b242dd358858476667bfc3d1c92a96e00c41d8ea1f46f47c4ee154fe323f
  Public key (hex): 0xe989b242dd358858476667bfc3d1c92a96e00c41d8ea1f46f47c4ee154fe323f
  Address (SS58): 5HLuvEbZs7SzwUMzd6RmdeN76cFYdSRvRVqXurE9z6A1cinV

However, there's no such issue for -s/--sr25519 option.

Version:

$ subkey -V
subkey 2.0.0
bkchr commented 5 years ago

Hey, what is your question?

dryruner commented 5 years ago

@bkchr Hi what I'm asking is: shouldn't the public key yielded by subkey -e generate be the same public key generated by inspecting on the same mnemonic? However, as shown in the example above, they're not the same, why is that?

xlc commented 5 years ago

We noticed same issue.

Seed: 0xe989b242dd358858476667bfc3d1c92a96e00c41d8ea1f46f47c4ee154fe323f
Public key (hex): 0xe989b242dd358858476667bfc3d1c92a96e00c41d8ea1f46f47c4ee154fe323f

Note that the seed part and public key part are same. This is clearly a mistake.

bkchr commented 5 years ago

I looked into this. subkey generte expects the seed. If you give it the seed it always outputs the correct data.

Based on the implementation, there is currently no way to recover from the mnemonic. (But implementing this should not be that complicated).

bkchr commented 5 years ago

Okay, another update. You need to add /// at the end of your mnemonic and then inspect also works correctly.

This clearly needs some better documentation.

dryruner commented 5 years ago

Re @bkchr : generate should not take any seed/mnemonic imo, as it's used to generate one :)

Also:

$ subkey -e inspect "island morning track vast rhythm rebel vendor hold buffalo place east exhaust///"
Secret Key URI `island morning track vast rhythm rebel vendor hold buffalo place east exhaust///` is account:
  Seed: 0xe989b242dd358858476667bfc3d1c92a96e00c41d8ea1f46f47c4ee154fe323f
  Public key (hex): 0xe989b242dd358858476667bfc3d1c92a96e00c41d8ea1f46f47c4ee154fe323f
  Address (SS58): 5HLuvEbZs7SzwUMzd6RmdeN76cFYdSRvRVqXurE9z6A1cinV

Still not working

bkchr commented 5 years ago

Please try with latest Master.