-
Notifications
You must be signed in to change notification settings - Fork 137
wallet shows incorrect BIP32 derivation paths #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here is some python code: import hmac
from hashlib import blake2b, sha512
import bip32
from bip32 import BIP32
from bip_utils import Bech32Encoder
from mnemonic import Mnemonic
from nacl import bindings
mnemo = Mnemonic("english")
words = "sign interest obtain raw window monster jump bring nice crunch toward grunt prosper recycle sphere battle mother fold reject velvet emotion similar romance govern"
seed = mnemo.to_seed(mnemonic=words, passphrase="")
# I AM VOLDEMORT
m = hmac.new("IamVoldemort".encode("utf8"), digestmod=sha512)
m.update(mnemo.to_entropy(words))
secret = m.digest()
bip32 = BIP32(chaincode=secret[32:], privkey=secret[:32])
# get the m/0/1/0 key
chain, sk_der = bip32.get_extended_privkey_from_path("m/0/1/0")
# compute the blake2 hash of that key and that is ed25519 private key
sk_der_blake = blake2b(sk_der, digest_size=32).digest()
# get the ed25519 public key from it
pk, sk = bindings.crypto_sign_seed_keypair(sk_der_blake)
# compute the slatepack address
slatepack_address = Bech32Encoder.Encode("grin", pk)
print(f"slatepack at m/0/1/0:\t{slatepack_address}")
assert (
slatepack_address
== "grin14kgku7l5x6te3arast3p59zk4rteznq2ug6kmmypf2d6z8md76eqg3su35"
)
# get the m/0/2/0 key
chain, sk_der = bip32.get_extended_privkey_from_path("m/1/1/0")
# compute the blake2 hash of that key and that is ed25519 private key
sk_der_blake = blake2b(sk_der, digest_size=32).digest()
# get the ed25519 public key from it
pk, sk = bindings.crypto_sign_seed_keypair(sk_der_blake)
# compute the slatepack address
slatepack_address = Bech32Encoder.Encode("grin", pk)
print(f"slatepack at m/1/1/0:\t{slatepack_address}")
assert (
slatepack_address
== "grin1uqan8sf49yf0369ezef9jhl25jll9fc8xc5wjkcg0w6nv6v85v2sp4wgwy"
)
# get the m/0/3/0 key
chain, sk_der = bip32.get_extended_privkey_from_path("m/2/1/0")
# compute the blake2 hash of that key and that is ed25519 private key
sk_der_blake = blake2b(sk_der, digest_size=32).digest()
# get the ed25519 public key from it
pk, sk = bindings.crypto_sign_seed_keypair(sk_der_blake)
# compute the slatepack address
slatepack_address = Bech32Encoder.Encode("grin", pk)
print(f"slatepack at m/2/1/0:\t{slatepack_address}")
assert (
slatepack_address
== "grin1guszgjsjlt9vrppu42l03xx080epzzvse5nev3nvdh632explc0sj8ylja"
) Output:
|
@marekyggdrasil Is this issues still an open issue? |
This part of grins use of BIP32 is indeed confusing, I think more confusing than it needs to be due to lacking explicit documentation on how grin uses BIP32 key derivation. Grin is both smart and tricky in that it uses BIP32 derived receive keys for outputs and derived change keys for SlatepackAddress generation. As can be found in the RFC on SlatepackAddresses, two keys are derived from the account master key, one for the SlatepackAddress, one for blinding factors
Source: https://github.com/j01tz/grin-rfcs/blob/slatepack/text/0015-slatepack.md It would be best for to provide explicit example within this RFC as well as in the grin wiki documentation on key derivation both for output private-keys (blinding factors) and slatepacks. Currently the only explicit example can be found hidden in the the code:
If we would implement account specific SlatepackAddresses, it would make sense to change the output to show something like this ____ Wallet Accounts ____ Name | Output BIP-32 Parent Key | SlatepackAddress key | address |
Describe the bug
The key derivation path shown after running
grin-wallet account
is not correct.To Reproduce
Steps to reproduce the behavior:
grin-wallet account
to list them, note the derivation pathsExpected behavior
When I run
correct paths should be
You can get the test data here
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: